I’m trying to refactor and simplify some of my YAML. Templates have always been my nemesis so I’m forcing myself to use them more and more so I can better understand it.
Simple automation, let me know if doors are opening inside of the house while no one is here. Easy with separate automation or even the new Trigger conditions and trigger IDs but I think it would be neatest to use templates so I have dynamic response notifications based on what door opens. I just can’t figure out how to set up the template to get the friendly name of the door sensor.
- id: Notifyifanypedestriandoorsareopenwhennooneishome
alias: Notify if any pedestrian doors are opened when noone is home
initial_state: true
trigger:
platform: state
entity_id:
- binary_sensor.door_window_sensor_158d0006d30679
- binary_sensor.door_window_sensor_158d0006d30781
- binary_sensor.door_window_sensor_158d0006d3079c
from: "off"
to: "on"
condition:
condition: state
entity_id: input_select.occupancy
state: "False"
action:
service: notify.pushbullet
data_template:
message: "The {{ trigger.attributes.friendly_name }} opened while noone was home" ### WTF happens here?
target:
- email/***@***.***
Probably not worth opening another thread but the same templating issue, now just trying to pull the state name out of the condition responsible.
- id: Notifyifanypedestriandoorsareleftopenwhennooneishome
alias: Notify if any pedestrian doors are left open when noone is home
initial_state: true
trigger:
platform: state
entity_id: input_select.occupancy
from: "True"
to: "False"
condition:
condition: or
conditions:
- condition: state
entity_id: "binary_sensor.door_window_sensor_158d0006d30679"
state: "on"
- condition: state
entity_id: "binary_sensor.door_window_sensor_158d0006d30781"
state: "on"
- condition: state
entity_id: "binary_sensor.door_window_sensor_158d0006d3079c"
state: "on"
action:
service: notify.pushbullet
data_template:
message: "The {{ condition.state.name }} was left open" #Templates are hard.
target:
- ***@***
These do not exist. There is some background assumptions you need to interpret that page. And the page has zero actual yaml examples
And I cannot contribute any examples because I do not understand how to interpret the page content. It would help many if an expert user would PR some actual real examples of the use
That line causes all the members of the group to be listed in the message if any one of them are in an open state as the house becomes unoccupied. I need it to state only the doors which are open or “on”.
Indeed it does. Much better than the official documentation. The official doc talks about something named “state” and if you try to use that in a template you get an error. There is nothing a user can use that starts with “state”. There is however “states” but not the way it is described in the documentation. In my view this State page is a developer document. It confuses more than it helps. All my template based sensors I have ever made are based on forum posts, not the official documentation.