I tried to use the friendly name of trigger.entity_id under data_template in my automation. Example…
- alias: 'Alarm tripped'
trigger:
- platform: state
entity_id: sensor.frontdoor
state: 'Open'
- platform: state
entity_id: sensor.entrance_motion
state: 'Active'
condition:
- condition: state
entity_id: alarm_control_panel.zone_a
state: armed_away
action:
service: notify.notify
data_template:
message: "Alarm tripped at {{ trigger.entity_id }}"
title: ""
But it is not working because attributes seem to not passing over to data_template.
I hope this can be supported in future. Thanks.
2 Likes
Consider {{ trigger.to_state.attributes.friendly_name }}
1 Like
Thank you that worked for me.
- alias: 'Announcement Movie playing'
trigger:
platform: state
entity_id: media_player.kodi
from: 'paused'
to: 'playing'
action:
service: notify.notify
data_template:
message: >
{{ trigger.to_state.attributes.media_title }} is now {{ states.media_player.kodi.state }} in the {{ trigger.to_state.attributes.friendly_name }}.
title: ""
- alias: 'Announcement Movie paused'
trigger:
platform: state
entity_id: media_player.kodi
from: 'playing'
to: 'paused'
action:
service: notify.notify
data_template:
message: >
{{ trigger.to_state.attributes.media_title }} is now {{ states.media_player.kodi.state }} in the {{ trigger.to_state.attributes.friendly_name }}.
title: ""
resulted in below for me
16-06-07 22:01:37 homeassistant.core: Bus:Handling <Event logbook_entry[L]: domain=automation, message=has been triggered, name=Announcement Movie playing>
16-06-07 22:01:37 homeassistant.core: Bus:Handling <Event call_service[L]: service_call_id=1979396784-11, domain=notify, service_data=title=, message=Pacific Rim is now playing in the Media Room., service=notify>
16-06-07 22:01:49 homeassistant.core: Bus:Handling <Event call_service[L]: service_call_id=1979396784-12, domain=media_player, service_data=entity_id=media_player.kodi, service=media_play_pause>
16-06-07 22:01:49 homeassistant.components.automation: Executing Announcement Movie paused
16-06-07 22:01:49 homeassistant.core: Bus:Handling <Event logbook_entry[L]: domain=automation, message=has been triggered, name=Announcement Movie paused>
16-06-07 22:01:49 homeassistant.core: Bus:Handling <Event call_service[L]: service_call_id=1979396784-13, domain=notify, service_data=title=, message=Pacific Rim is now paused in the Media Room., service=notify>
TTS speaks movie (announcing movie played/paused) to me now. YEAH!
1 Like
Thank you very much! It works!!!