I’m very new to Home Assistant, only been tinkering a couple of weeks and still learning. The lights in my house are currently run from smart switches. I created a switch group named “All Lights”, so I have an entity switch.all_lights. I built the following based on posts I found on the forum and stuck it into my configuration.yaml, but the sensor always reads as “unavailable”. I’m sure I did something wrong here, but I don’t know what.
sensor:
- platform: template
sensors:
count_lights_on:
friendly_name: "# Lights on"
unit_of_measurement: "on"
value_template: "{{ switch.all_lights | selectattr('state', 'eq', 'on') | list | count }}"