Dynamic Notification

I’m not sure how to go about this but I believe it’s possible using the template system. The goal is the following:

Anytime a switch which is a member of group.all_switches changes state either on or off. I want to capture what that device name is, and then compose a notification which contains the device_id and the state it changed to.

For example group.all_switches contains the following entity_id:
“switch.downstairs_main_ceiling_lights_switch”, “switch.downstairs_seating_accent_lights_switch”,

Lets say “switch.downstairs_seating_accent_lights_switch” is turned off. I want the automation to fire capture the entity_id of “switch.downstairs_seating_accent_lights_switch” and then send a message of “switch.downstairs_seating_accent_lights_switch”, has turned off. Eventually I’d clean this up with friendly names etc. but for now I just wonder how I can iterate over a group and only alert when a sate change happens for a member within the group. Otherwise I’d imagine I’d have to write an automation rule per switch which sounds unplesant.


i think you need to list all the switches in the automation trigger and use trigger entity.

This should help: Trigger.entity_id sample

That was the tipping point I needed. I realized I’ll never be able to trigger just on the group because as long as one switch is one the status will never change. So it’s a long list of entity IDs for the trigger but a short template for the message.


Final Code:

# Tweet when Light Switch is Touched
- id: Tweet_Light_Switch
  alias: 'Tweet when Switch is toggled'
platform: state
entity_id: switch.downstairs_accent_lights_switch, switch.downstairs_main_ceiling_lights_switch, switch.downstairs_seating_accent_lights_switch, switch.downstairs_seating_lights_switch, switch.downstairs_stair_light_switch, switch.downstairs_step_lights_switch, switch.garage_exterior_lights_switch, switch.loft_ceiling_lights_switch, switch.loft_step_lights_switch
- service: notify.twitter_borkshiremanor
      message: "Yelp! It appears someone is playing with my switches {{ trigger.to_state.attributes.friendly_name }} was turned {{ trigger.to_state.state }}. - {{ now().strftime('%I:%M:%S %p') }}"