If it’s possible, how can I add attributes to this template sensor to tell me which lights are on (Matches condition for sensor)? When I configure the sensor, at the bottom the Preview says “This template listens for the following state changed events:” And then lists the entities it’s counting. My goal is for the sensor to tell me how many lights are on, which is does, but then show me which lights are on when I open the sensor to see more information.
{%- set search_state = 'on' %}
{%- set search_areas = ['Living Room', 'Bedroom', 'Front Door', 'Bathroom','Garage','Office','Kitchen'] %}
{%- set ns = namespace(lights=[]) %}
{%- for light in states.light | selectattr('state','eq', search_state) %}
{%- for area in search_areas %}
{% if area_name(light.entity_id) == area not in state_attr(light.entity_id, "friendly_name") %}
{%- set ns.lights = ns.lights + [ light.entity_id ] %}
{% endif%}
{%- endfor %}
{%- endfor %}
{{ ns.lights| list | length }}
The Template Helper does not currently support advanced features like availability, templated attributes, or triggers. If you want to use those features you need to configure your sensor in YAML.
Thank you! This is exactly what I was looking for, I additionally used Browser Mod to make the tap action for the number entity display the list entity.