@arun2118, Looking at your code the trigger will never fire, you have an entity_id, but something has to happen with that entity_id in order to fire. You have commented out the firing mechanism ( # to: ‘off’ ). I think what you want to do here is create 2 triggers like this:
- alias: 'Garage door Test'
trigger:
- platform: state
entity_id: binary_sensor.garage_entry
to: 'off'
trigger:
- platform: state
entity_id: binary_sensor.garage_entry
to: 'on'
action:
- service: media_player.alexa_tts
entity_id: media_player.dot_2
data_template:
message: >
{% if is_state('binary_sensor.garage_entry', 'on') %}
Garage door Closed
{% elif is_state('binary_sensor.garage_entry', 'off') %}
Garage door Open
{% endif %}
With this setup the trigger will fire when the Garage Door is open or closed and with the data template it will determine which action happened and announce it on your media player. As for the your second question about ( message: > ), that is just part of the format for the message template, I hope this helps.
This doesn’t work because you don’t have an entity_id specified in is_state() method, these methods and their inputs are covered here:
the > just means “This is a multi line template”. Without that symbol, you need to have quotes that wrap around your entire template ({%%} and {{ }}), which looks ugly.
This automation should work for you.
- alias: 'Garage door Test'
trigger:
- platform: state
entity_id: binary_sensor.garage_entry
action:
- service: media_player.alexa_tts
entity_id: media_player.dot_2
data_template:
message: >
{% if trigger.to_state.state == 'on' %}
Garage door Closed
{% else %}
Garage door Open
{% endif %}
This uses the trigger.to_state state object. You don’t need to specify a entity_id, it just grabs the current state and checks against it. This is covered here.
The format in your post won’t work. You cannot have 2 trigger sections. You can have 2 triggers, not 2 sections. That would look like this:
- alias: 'Garage door Test'
trigger:
- platform: state
entity_id: binary_sensor.garage_entry
to: 'off'
- platform: state
entity_id: binary_sensor.garage_entry
to: 'on'
It should be noted that > works for all templates and is just not for message templates. The symbol specifically means ‘multi-line template’. If you add a - after, it means ‘mutli-line template with no whitespace’.
Also, for your own info, the to: or from: attributes are optional. When omitted, the automation will fire on every state change regardless of the state itself.
Thanks guys, shortly after posting the forum went down. I’m struggling with a new issue now but:
The code we talked about was for a message to play when the garage door is open, if i just wanted one switch on the frontend to control all switches how can i include more entities? i thought adding a comma would but does not work
- alias: 'Garage door Test'
trigger:
- platform: state
**entity_id: binary_sensor.garage_entry, binary_sensor.front_door**
# to: 'off'
action:
- service: media_player.alexa_tts
entity_id: media_player.dot_2
data_template:
message: >
{% if is_state('binary_sensor.garage_entry', 'on') %}
Garage door Closed
{% elif is_state('binary_sensor.garage_entry', 'off') %}
Garage door open
{% elif is_state('binary_sensor.front_door', 'on') %}
front door door Closed
{% elif is_state('binary_sensor.front_door', 'off') %}
front door door Open
{% endif %}
I have seen this post and thought I would try out some automations.
I have 3 sensors that are linked to my alarm system. If any of the sensors are ‘on’ (open) then the alarm will not activate.
I want to create an automation that will tell me which are open. I have been testing out the below code but even though the binary_sensor.kitchen_window_l is open it doesn’t get past the front door
service: tts.cloud_say
data:
entity_id: media_player.google_nest_mini
message: >-
{% if is_state('binary_sensor.front_door', 'on') %}
The front door is open
{% elif is_state('binary_sensor.kitchen_window_l', 'on') %}
the left kitchen window is open
{% elif is_state('binary_sensor.kitchen_window_r', 'on') %}
the right kitchen window is open
{% endif %}
What am I doing wrong? Probably something very simple… I’m a total noob at this
Just realised it needs to be seperate if statements… doh!
{% if is_state('binary_sensor.front_door', 'on') %} The front door is open
{% endif %}
{% if is_state('binary_sensor.kitchen_window_l', 'on') %} the left
kitchen window is open {% endif %}
{% if is_state('binary_sensor.kitchen_window_r',
'on') %} the right kitchen window is open
{% endif %}