Pass trigger entity to action

Sorry, I’m not familiar with home-assistant entities yet, so my question could be stupid, but…
I wish to get Telegram notification if any of lights turned on (for debugging).
I don’t want to write automation for each light, I want something like if %any_light% turned on – notify 'Light %light_name% turned on.
I wrote an automation:

alias: Notify
  trigger:
    platform: state
    entity_id: group.all_lights
    to: 'on'
  action:
    service: notify.notify
    data_template:
      message: "Light {{ trigger.to_state.attributes.friendly_name }} turned on"
      title: " "

But it gives me message like Light None turned on. Seems like it’s group.all_lights friendly_name, but I need name of exact light that triggered automation.

1 Like

Not a stupid question at all. I’d like to get an answer to this as well as I have a use case for this.

In this case, you don’t really want to look at the group. Groups will be “on” if any single item in the group is on (and “off” only when all items are off), so you won’t catch changes if a second or third member of the group changes status. You’d want to look at a list of entity_ids. You can supply a list to your trigger like

entity_id: light.first_light, light.second_light

or


entity_id:
  - light.first_light
  - light.second_light
1 Like

Wow, I din’t know you could do that. Now I feel kind of stupid!

Thanks a lot for your solution. But what if I have 200 bulbs or often add/delete items? It will be not very comfortable to write long config or often edit it. Hope there is another solution…

If you truly had 200 bulbs, adding them to the trigger list would be the least of your problems.

2 Likes

Lol, you right. Anyway, thanks a lot for your reply. Rewritten my automation, now it works properly.