I have a very simple automation that I have created based on the following Home Assistant guide page:
Insert entity friendly name into notification
Here is the automation source:
alias: Garage low temp warning
description: ""
trigger:
- platform: numeric_state
entity_id:
- sensor.hue_outdoor_motion_sensor_1_temperature
- sensor.hue_outdoor_motion_sensor_2_temperature
below: 15
condition: []
action:
- service: notify.mobile_app_mark_cell_by_ip
data:
message: Low temperature detected on "{{ state_attr(trigger.event.data.entity_id, 'friendly_name') }}"!
mode: single
When I run the automation, I get the following error in the trace output:
Executed: May 6, 2024 at 9:26:27 PM
Error: Error rendering data template: UndefinedError: 'dict object' has no attribute 'event'
If I remove the entity reference from the message, the automation runs fine and the static text message is reported.
This seems like an incredibly simple example, I am not sure why it does not work for me.
Did you see the solution in the post you shared?
message: "{{ state_attr(trigger.entity_id, 'friendly_name') }}"
tom_l
May 7, 2024, 4:34am
3
Or even simpler:
data:
message: Low temperature detected on {{ trigger.to_state.name }} !
This will return the friendly name if one exists, otherwise it falls back to the entity_id.
1 Like
Thanks, I get a similar error with this approach:
Executed: May 7, 2024 at 1:33:29 PM
Error: Error rendering data template: UndefinedError: 'dict object' has no attribute 'to_state'
Thanks, but this also results in an error:
Executed: May 7, 2024 at 1:37:50 PM
Error: Error rendering data template: UndefinedError: 'dict object' has no attribute 'entity_id'
tom_l
May 7, 2024, 9:43pm
7
Manually running the automation skips the triggers and conditions and just performs the actions. Hence no trigger variables.
You need to change one of the sensor values in Developer Tools → States to simulate a trigger. It is only a temporary change and will be overwritten next time the sensor updates.
Arghh! That was exactly the problem, thank you very much! I had assumed that running it manually would pick up the current entity state (and variables).