4 m

Lovelace dashboard on a MacBook screenI am using android phones for almost two years now. It felt like a big step forward after using iPhones for more than eight years. Since I started using Android, I couldn’t care less about the iPhone, but nothing can replace the Home app from Apple. Especially the status panel, which shows which and how many lights, switches and thermostats are turned on. So I decided to create my own status panel within the Home Assistant dashboard.

A screenshot of the status panel in Lovelace UITo the left you can see what the status panel looks like. It shows in which room the lights and switches are on. When the lights are turned on in more than one room, it shows how many lights are switched on in total and the same thing for the switches. To create this panel, I first had to group my devices and create sensors to count the lights and switches that has been turned on. In this article I will show you:

  • how to create groups and how to use them.
  • how to create a sensor that counts the devices with a specific state.
  • how to create the actual status panel in the Home Assistant Lovelace Dashboard.

For this article, I am using the lights as an example, but you can create groups and count devices for many different domains, like doors, switches, device trackers, ext.

Grouping lights

First, I grouped my devices. I created a group for every domain in every room. Two groups for my bedroom for example, one for lights and one for switches. You can learn how to format your own groups at the groups documentation on the Home Assistant website. For your convenience, my example code for the living room lights is below:

# Example light group
group:
  lv_lights:
    name: Living room lights
    icon: mdi:light
    entities:
      - light.living_room_ceiling_1
      - light.living_room_ceiling_2
      - light.couch_light
      - light.window_light

Counting lights

For this part, I have to thank Almelo Rico, one of the members of the Dutch Home Assistant Facebook group, for sharing his code with the community. This template sensor counts the specified entities with a specific state and is a key part of the status panel I created. Below you can see an example for the template sensor he created. Please read the template documentation on the Home Assistant website to see how and where to place this code.

# Example light counter
sensor:
  - platform: template
    sensors:
      lights_on_count:
        unit_of_measurement: 'on'
        value_template: >
          {% set total = 0 %}
          {% if is_state('light.couch_light', 'on') %}
            {% set total = total + 1 %}
          {% endif %}
          {% if is_state('light.living_room_ceiling_1', 'on') %}
            {% set total = total + 1 %}
          {% endif %}
          {% if is_state('light.living_room_ceiling_2', 'on') %}
            {% set total = total + 1 %}
          {% endif %}
          {% if is_state('light.table_lamp', 'on') %}
            {% set total = total + 1 %}
          {% endif %}
          {% if is_state('light.window_light', 'on') %}
            {% set total = total + 1 %}
          {% endif %}
          {{total}}

Of course you will need to change the entity id’s to your own. Please make sure that you enter all the lights you want to see in the status panel. It’s easy to forget one.

Templating the status panel

Now it is time to create the actual panel itself. I used the default Markdown card in Lovelace UI. This card supports simple text, but also supports templates. I wrote my own template, which does the following:

  • It checks in which group or groups the lights are on.
  • If the lights in one group are on, it just shows the name of the room in which the lights are on.
  • If the lights are on in multiple groups, than the output will be the result of the sensor which counts the lights that are on.
  • If all the lights are off, it says ‘All lights are off.’

The template code for the lights is shown below. You can paste it in the content of the markdown card and change it to your needs. As you may notice, I didn’t bother to create a group for every room. I did this because there is only one light in the hallway and in the bathroom.

{% if is_state("group.br_lights", "off")
  and is_state("group.kitchen_lights", "off")
  and is_state("group.lv_lights", "off")
  and is_state("light.bathroom_light", "off")
  and is_state("light.hallway_light", "off") -%}
  ✔️ All lights are off
{% elif is_state("group.br_lights", "on")
  and is_state("group.kitchen_lights", "off")
  and is_state("group.lv_lights", "off")
  and is_state("light.bathroom_light", "off")
  and is_state("light.hallway_light", "off") -%}
  💡 Bedroom lights are on
{% elif is_state("group.br_lights", "off")
  and is_state("group.kitchen_lights", "on")
  and is_state("group.lv_lights", "off")
  and is_state("light.bathroom_light", "off")
  and is_state("light.hallway_light", "off") -%}
  💡 Kitchen lights are on
{% elif is_state("group.br_lights", "off")
  and is_state("group.kitchen_lights", "off")
  and is_state("group.lv_lights", "on")
  and is_state("light.bathroom_light", "off")
  and is_state("light.hallway_light", "off") -%}
  💡 Living room lights are on
{% elif is_state("group.br_lights", "off")
  and is_state("group.kitchen_lights", "off")
  and is_state("group.lv_lights", "off")
  and is_state("light.bathroom_light", "on")
  and is_state("light.hallway_light", "off") -%}
  💡 Bathroom light is on
{% elif is_state("group.br_lights", "off")
  and is_state("group.kitchen_lights", "off")
  and is_state("group.lv_lights", "off")
  and is_state("light.bathroom_light", "off")
  and is_state("light.hallway_light", "on") -%}
  💡 Hallway light is on
{%- else -%}
  💡 {{ states('sensor.lights_on_count') }} lights are on
{%- endif %}

Other ideas

You can also add switches with the same method as for the lights. I also added a template for my thermostats and for some problems which might happen from time to time, like automatic snapshots which are not created or smart plugs which loose their connection from time to time. Lastly, I created a template for my balcony doors with the same groups and count method as for the lights.

There you have it. Your own status panel in your Home Assistant dashboard. What did you add to your status panel?