Performing action on trigger device or entity

I want to use toggle helpers as buttons because I want them to appear on the Google Home dashboard, which switches do but buttons do not. Therefore I want to make an automation with a number of these helpers changing state to “on” as the triggers and the action would be to turn whatever triggered the automation to “off” - ie like a button. Other separate automations would respond to each helper turning on, the real purpose of these helpers.

So, rather than give each trigger an id and deal with it individually, is there a way just to make one action, which says something like “and now turn off the toggle helper, whatever it happened to be” ? Using Trigger.device_id? I’ve found threads talking about that but it seems in nearly every case the enquirer is encouraged to find a different solution so I’ve not seen a working example to copy.

Yes, you can use the trigger variable:

trigger:
  - platform: state
    to: 'on'
    from: 'off'
    entity_id:
      - switch.switch1
      - switch.switch2
      - switch.switch3
action:
  - delay: 1
  - action: switch.turn_off
    target:
      entity_id: "{{ trigger.entity_id }}"
mode: queued

I don’t use Google Home, so I’m not well versed in what your other options are, but if the majority of related threads favor other solutions, there’s probably a good reason…

1 Like

Thanks for the code example, I’ll try that. Yeah in my case though I have a different purpose from the others and I don’t think their alternative suggestions would suit anyway.

Later: Works perfectly, thank you!

1 Like