I’m guessing I’m missing something elementary with my script. Right now most of my script works. When I ask Alexa, “Are the garage doors open?”, She replies either Left Garage Door is open or Right Garage Door is open correctly. The problem is, I want her to reply “both doors are closed” if both doors are closed, but she does not. Below is the script. Any help or thoughts are much appreciated…
Please know that I know the alexa tts isn’t really supported, but I have tried other things like turn on light instead of the alexa tts if both doors are closed and that isn’t working either. That part of the code if both doors are closed (off) isn’t executing.
'1539301820073':
alias: Check Garage Door
sequence:
- condition: state
entity_id: binary_sensor.0x00158d000243672e
state: 'on'
- alias: ''
data:
entity_id: media_player.echo_plus
message: left garage door is open
service: media_player.alexa_tts
- condition: state
entity_id: binary_sensor.0x00158d000232c071
state: 'on'
- data:
entity_id: media_player.echo_plus
message: right garage door is open
service: media_player.alexa_tts
- condition: state
entity_id: binary_sensor.0x00158d000243672e
state: 'off'
- condition: state
entity_id: binary_sensor.0x00158d000232c071
state: 'off'
- data:
entity_id: media_player.echo_plus
message: both doors are closed
service: media_player.alexa_tts
Have a separate script for each door. Put the sensors for both doors into a group. Check the entities with another and/or type script:
{% if is_state("binary_sensor.door1", "on") and
is_state("binary_sensor.door2", "on") -%}
Both doors are closed
{%- else -%}
Door 1 is {{ states("binary_sensor.door1") }}
Door 2 is {{ states("binary_sensor.door2") }}
{%- endif %}
I tried the following, but I have the syntax wrong somehow.
check_garage_door:
alias: 'Check Garage Door'
sequence:
- data_template:
entity_id: media_player.echo_plus
message: >
{% if states.binary_sensor.0x00158d000243672e.state == 'on' %}
The left garage door is open
{% elif states.sensor.0x00158d000232c071.state == 'on' %}
The right garage door is open
{% else %}
both doors are closed
{% endif %}
service: media_player.alexa_tts
check_garage_door:
alias: 'Check Garage Door'
sequence:
service: media_player.alexa_tts
entity_id: media_player.echo_plus
data_template:
message: >
{% if states.binary_sensor.0x00158d000243672e.state == 'on' and states.binary_sensor.0x00158d000243672e.state == 'on' %}
Both garage doors are open
{% elif states.binary_sensor.0x00158d000243672e.state == 'on' %}
The left garage door is open
{% elif states.sensor.0x00158d000232c071.state == 'on' %}
The right garage door is open
{% else %}
both doors are closed
{% endif %}
Thanks. I tried, but I get the following error when I attempt configuration validation:
Invalid config for [script]: invalid template (TemplateSyntaxError: expected token 'end of statement block', got 'x00158d000243672e') for dictionary value @ data['script']['check_garage_door']['sequence'][0]['data_template']['message']. Got None. (See /config/configuration.yaml, line 311). Please check the docs at https://home-assistant.io/components/script/
check_garage_door:
alias: 'Check Garage Door'
sequence:
service: media_player.alexa_tts
entity_id: media_player.echo_plus
data_template:
message: >
{% if states('binary_sensor['0x00158d000243672e']', 'on') and states('binary_sensor['0x00158d000243672e']', 'on') %}
Both garage doors are open
{% elif states('binary_sensor['0x00158d000243672e']', 'on') %}
The left garage door is open
{% elif states('binary_sensor['0x00158d000232c071']', 'on') %}
The right garage door is open
{% else %}
both doors are closed
{% endif %}
EDIT: I stuffed up the formatting. Have fixed it above now.
Thanks Tom, That got rid of the configuration validation errors. Unfortunately no combination of garage doors open and/or closed yield a message via alexa_tts. Every time I try to execute the script (even after a reboot), I get this in the log:
Didn’t see your edit. Retried the code and I’m getting a syntax error on config validation:
Invalid config for [script]: invalid template (TemplateSyntaxError: expected token ',', got 'integer') for dictionary value @ data['script']['check_garage_door']['sequence'][0]['data_template']['message']. Got None. (See /config/configuration.yaml, line 311). Please check the docs at https://home-assistant.io/components/script/