How would I create an automation that would trigger on all state changes of an entity? For example, I’d like to announce on a Google Home every change in state of Sun.
Can this be done generically? Ie without knowing the actual state name?
Can this be done on a list of known states? Ie without having to duplicate triggers or conditions?
And for a bonus question:
Can you send a single message to multiple devices? Ie can I announce a TTS message on all my Google Homes?
Yes. Just don’t specify a state. It will trigger on all changes. But beware - it will also trigger on attribute changes. e.g.
trigger:
- platform: state
entity_id: switch.my_switch
Yes you can list the states you want if you don’t want them all (e.g. if an entity could go to the ‘unknown’ state, or you dont want to trigger on attribute changes).
trigger:
- platform: state
entity_id: switch.my_switch
to:
- 'on'
- 'off'
Yes, create a group of your Google homes. TTS to that.
I presume then the way to extract the state further on (eg to announce “it is sunset” is directly via the device, ie there’s no “trigger result” I can use instead?
That’s the best way as it prevents unneeded triggering but if you have a lot of states sometimes it’s easier just to add this condition to prevent the actions running: