You’ve got a sweet automation but you need to grab some data from whatever triggered it. Luckily Home Assistant has the ability to use Jinja in automation via templates so you can get your information to another service. In my example, I’m using an automation where someone has arrived home so I use the TTS engine to welcome them home based on the name of the person who came home.
automation: - id: welcome_home alias: Welcome Home initial_state: True trigger: - platform: state entity_id: device_tracker.brian from: 'not_home' to: 'home' for: minutes: 2 - platform: state entity_id: device_tracker.christina from: 'not_home' to: 'home' for: minutes: 2 action: service: script.welcome_home data_template: user: '{{trigger.to_state.attributes.friendly_name}}' |
You can also use templates to control which entities are passed to the service call; this example is an Alexa intent. You can see both the player and source keys are used to determine the entity and which source to use.
MediaPlayerSourceIntent: action: service: media_player.select_source data_template: entity_id: 'media_player.{{player|replace(" ", "_")|lower}}' source: '{{source}}' speech: text: 'OK. Changing {{player}} to {{source}}' |