Script not working as expected. Please help

returns off

1 Like

Ah ha!

Ok, Try this:

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['0x00158d000232c071'].state == 'on') %}
          Both garage doors are open
        {% elif states.binary_sensor['0x00158d000243672e'].state == 'on') %}
          The left garage door is open
        {% elif states.binary_sensor['0x00158d000232c071'].state == 'on') %}
          The right garage door is open
        {% else %}
          both doors are closed
        {% endif %}

Oops just had to edit the first sensor test. Good to go now.

Its erroring regarding the ) right after ‘on’. If I remove all of the ), configuration validation passes.

Sorry, I missed that. Yes get rid of them and give it a go.

Ok thanks for hanging in there with me. I changed the script name. Telling alexa to rediscover the new script as I don’t know how to execute the script manually… I’ll test shortly

You might not need to rename it, but considering the bug report posted above it’s better to be safe than sorry.

I think that got it. Thanks so much for your help. I’ll try all combinations tomorrow, but seems to be working. You’re the man.

No worries. It was a learning experience for me too.

I checked all of the different scenarios. Working perfectly. Wanted to post the final solution here that @tom_l came up with, but after upgrading to 0.80.0, from 0.79.3, it looks a lot different. Still works, but a lot harder to read. Does anyone have any explanation for the formatting changes that occurred after the upgrade?:

garage_door_status:
  alias: Garage Door Status Spoken
  sequence:
    service: media_player.alexa_tts
    entity_id: media_player.jeffs_dot
    data_template:
      message: "{% if states.binary_sensor['0x00158d000243672e'].state == 'on' and\
        \ states.binary_sensor['0x00158d000232c071'].state == 'on' %}\n  Both garage\
        \ doors are open\n{% elif states.binary_sensor['0x00158d000243672e'].state\
        \ == 'on' %}\n  The left garage door is open\n{% elif states.binary_sensor['0x00158d000232c071'].state\
        \ == 'on' %}\n  The right garage door is open\n{% else %}\n  both doors are\
        \ closed\n{% endif %}\n"

Yikes! That’s horrible.

Did you include the “>” after message: ?

Like so:

message: >

If not cut and paste the code again and include it.

Yeah it was in there before. Anyway, pasted it back in and the formatting didn’t change after a restart. Working great. Here’s the final working code. Thanks @tom_l

garage_door_status:
  alias: 'Garage Door Status Spoken'
  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['0x00158d000232c071'].state == 'on' %}
          Both garage doors are open
        {% elif states.binary_sensor['0x00158d000243672e'].state == 'on' %}
          The left garage door is open
        {% elif states.binary_sensor['0x00158d000232c071'].state == 'on' %}
          The right garage door is open
        {% else %}
          both doors are closed
        {% endif %}
1 Like

I’d like to use that last script together with the sensor last_alexa which tells you the last spoken alexa device.

The state of the sensor looks like this:

echo_dot_wz

How can I use this information in the automation above? So the sensor state should be filled in instead of “echo_plus”

EDIT: Answer:

- service: media_player.alexa_tts
  data_template:
    entity_id: '{{ states.sensor.last_alexa.state }}' 
    message: "Some message"