added this
{
“message”: " {{ trigger.entity_id.attributes.friendly_name }} Open"
}
nop
log saying
File “/usr/lib/python3.6/site-packages/jinja2/sandbox.py”, line 385, in getattr
value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: ‘trigger’ is undefined
I under Stand What you have Written
one of my problems when I read automation which is build from the Front end
it look like its in the wrong Order think that a python thing LOL
Hay what about when we build a automation form the front could the engine put some
Hash -----------------------------------
at the Begining before script/ automation
and
Hash ----------------------------------- at the End
so just us new bee and see what happen and so we can break Break it
Trying to get it to send a message when the Side Door is Open
- action:
- data:
message: A Open was Open
service: notify.stephan_phone
- data:
data:
displaytime: 20000
icon: warning
message: A Door Opened!
title: Home Assistant
service: notify.main_kodi_message
alias: To Stephan Phone
condition: []
id: '1513489971216'
trigger:
- entity_id: sensor.garage_side_door
from: Closed
platform: state
to: Open
- entity_id: sensor.garage_door
from: Closed
platform: state
to: Open
This isn’t actually a thing, right? I’ve been trying to figure out how to get the friendly names of things for automating messaging like:
“Front door sensor was closed and now is open!”
“Floor of water heater sensor was dry and now is wet!”
“Garage motion sensor was clear and is now detected!”
Seems like a good data template for this would be: {{ trigger.entity_id.attributes.friendly_name }} was {{ trigger.from_state.attributes.friendly_name }} and now is {{ trigger.to_state.attributes_friendly_name }}!
Lots of people have recommended using {{ trigger.entity_id.attributes.friendly_name }} but on my setup that appears to result in error messages like this:
Error rendering data template: UndefinedError: 'str object' has no attribute 'attributes'
This tells me that entity_id is a string and to my surprise trigger.from_state.attributes.friendly_name is actually the entity_id’s friendly_name and has nothing to do with the state at all.
In my case trigger.from_state.state (or to_state) is either ‘off’ or ‘on’. Is there any way to have it process the type of Binary Sensor so that the state is actually meaningful to humans? Especially for things like a lock – ‘on’ means unlocked and ‘off’ means locked.
This tells me that entity_id is a string and to my surprise trigger.from_state.attributes.friendly_name is actually the entity_id’s friendly_name and has nothing to do with the state at all.
It has nothing to do with current state. It has to do with state changes. “TO” a new state “FROM” and old state.
With a binary sensor I’d just set up an if else and be done with it.
ie (pseudo code)
if state = on then
door is open
else
door is closed
end if
With a binary sensor there’s no real need for to and from… you just need an automation that fires on a change…
Thanks for the response @forsquirel. I understand how the automation triggering works but I’m trying to figure out how to make the automation send a message using a data_template with the result being the custom state value based on the type of binary sensor. I currently have this:
- id: make_sonos_talk
alias: Make Sonos Talk
trigger:
- platform: state
entity_id: binary_sensor.front_door
to: 'on'
- platform: state
entity_id: binary_sensor.basement_family_room_door
to: 'on'
- platform: state
entity_id: binary_sensor.drum_room_exterior_door
to: 'on'
- platform: state
entity_id: binary_sensor.garage_front_man_door
to: 'on'
- platform: state
entity_id: binary_sensor.floor_near_gas_water_heater
to: 'on'
- platform: state
entity_id: binary_sensor.floor_near_electric_water_heater
to: 'on'
- platform: state
entity_id: binary_sensor.motion_in_garage
to: 'on'
- platform: state
entity_id: binary_sensor.motion_in_drum_room
to: 'on'
action:
- service: script.sonos_say
data_template:
sonos_entity: media_player.office_sonos
volume: 0.5
message: >
{{ trigger.to_state.attributes.friendly_name }} is now {{ trigger.to_state.state }}!
delay: '00:00:05'
… and it results in:
“Front door is now on!”
“Floor near gas water heater is now on!”
“Motion in garage is now on!”
etc…
what I want is:
“Front door is now open!”
“Floor near gas water heater is now wet!”
“Motion in garage is now detected!”
etc…
Yeah, I’m using the device class with the sensors so the “friendly name” is applied to the lovelace card:
But, the automation messaging state tokens still don’t seem to have a way to get to the “friendly name” of the state, it’s still reported as ‘on’ or ‘off’.