I am creating a notification automation for when a garage door is open or closed using trigger template to make it more dynamic and not have a notification per door. I got it to work in a basic form, but when is basic ever enough?
This works and notifies me of which door’s binary sensor is ‘on’ or ‘off’:
{{ trigger.to_state.attributes.friendly_name }} is {{ trigger.to_state.state }}
The problem is that the binary sensor states are ‘on’ or ‘off’ although it is a garage_door class. In the entity’s history I can see it was opened or closed, but I am unable to extract those states for the message body.
Instead I am trying to do something like this, but it is not working:
{{ trigger.to_state.attributes.friendly_name }} is {% if is_states('trigger.to_state.state','on') %) open {% else %} closed {% endif %}
I have gone through various syntax iterations and should have noted them to share here as some could save, but would not evaluate the state and only give the message that the door is closed.
I am not sure if this is possible or if I should do something more elaborate with a proper value template
The automation thus far:
alias: Notify Garage Door
description: ''
trigger:
- platform: state
entity_id: >-
binary_sensor.main_garage_door,binary_sensor.small_garage_door,binary_sensor.back_garage_door
condition: []
action:
- service: notify.mobile_app_xxxxxx
data:
message: >-
{{ trigger.to_state.attributes.friendly_name }} is {% if is_states('trigger.to_state.state','on') %) open {% else %} closed {% endif %}
mode: single
I am testing this by opening and closing the door as I understand you cannot test this using the template test.
In short, the automation can trigger on any of the 3 separate entities. I want the notification to indicate which entity triggered the automation and what the state of that trigger was, be it opening or closing. The binary sensor only has ‘on’ or ‘off’ states and I want to translate this into ‘open’ or ‘closed’
I am open to suggestions on how to do this and avoid having 3 or 6 notification automations to do this.
Great to hear. And yes you were testing it the correct way. The trigger.to_ objects will not have values unless you actually trigger the automation with one of the trigger entities.
Dear
I am looking for prayer time automation in single automation .
I need to play if Fajr prayer (Prayer_Fajr.mp3) if other any prayers need to play (Prayer_Azan.mp3)
Here my code