this is hardly a workable solution, if you have but a few more lights, or entities in other domains. Hard coding these entities is very sub-optimal.
You’d better try this:
- alias: 'State changed Light'
trigger:
platform: event
event_type: state_changed
condition:
condition: template
value_template: >
{{ trigger.event.data.entity_id in state_attr('group.all_lights_only','entity_id') }}
action:
- service: homeassistant.update_entity
entity_id: sensor.lights_on
and create use the sensor update utility. use which ever group you like. Or use it with the expand function:
- alias: 'State changed expand'
trigger:
platform: event
event_type: state_changed
condition:
condition: template
value_template: >
{{ trigger.event.data.entity_id in (expand('group.iungo_switches_state') | map(attribute='entity_id')) }}
action:
etc etc
use a notification if you will:
- service: notify.notify
data_template:
message: >
{{trigger.to_state.attributes.friendly_name}} changed from {{trigger.from_state.state}} to {{trigger.to_state.state}}
and some useful conditions:
condition: template
value_template: >
{% set skip_list = ['automation_ran','last_automation','script_ran','last_script',
'count_warnings','count_errors','activate_map_sensors_actueel',
'timed_python_scripts','update_last_motion','call_service_event_script'] %}
{{ trigger.event.data.entity_id.startswith('automation.') and
trigger.event.data.entity_id.split('.')[1] not in skip_list and
'old_state' in trigger.event.data and 'new_state' in trigger.event.data }}
skiplisted are several automations I don’t want to trigger my automation tracker ( substitute with Hue groups you don’t want to track @DBuit Custom Lovelace Card - Homekit style card ).
startswith is useful for limiting to a domain (which could also be done by using states.[domain] of course, but options are always nice. The final old and new data condition prevents extra firing when attributes change but state is still the same.
Use to your specific needs.