How to make Google Home say door status translating the status message?

First of all, thanks to all of you who help people here. I learned a lot by reading the other posts.

But I guess dealing with scripts and variables are way out of my league and reading the docs got me nowhere.

I’m trying to make Google Home say my door status (open/closed) when calling a script, but it returns as ON or OFF. Of course, it would be better if it returns OPEN or CLOSED (in my case, ABERTA ou FECHADA, same thing but in portuguese).

The base for the script I got from another topic here and I can’t remember who wrote it. And I tried to use the same I did when translating YR weather states (which I also got from here). But obviously everything went wrong because I had no clue what I was doing. Here’s what I did.

    alias: 'Status da Porta da Cozinha'
    sequence:
    - delay:
        seconds: 2
    - service: tts.google_translate_say
      entity_id:
        -  media_player.googlehome0916
      data_template:
        message: >-
          A porta da cozinha está {{states('binary_sensor.door_window_sensor_158d000232ddf0')}} 
          {% if binary_sensor.door_window_sensor_158d000232ddf0 | state==off}Fechada
          {% elif binary_sensor.door_window_sensor_158d000232ddf0 | state==on}Aberta


Can someone help me understand how to make this work? Thanks!

Take a look at the dev-template in Developer tools. I modified the example, try this

{% if is_state("binary_sensor.door_window_sensor_158d000232ddf0", "on") -%}
  Aberta
{%- else -%}
  Fechada
{%- endif %}

based on this

{% if is_state("device_tracker.paulus", "home") and
      is_state("device_tracker.anne_therese", "home") -%}
  You are both home, you silly
{%- else -%}
  Anne Therese is at {{ states("device_tracker.anne_therese") }}
  Paulus is at {{ states("device_tracker.paulus") }}
{%- endif %}
1 Like

It worked! Thank you so much!

And I guess I understood the code so I can modify to other devices. I’ll check the templates out as well, thanks for pointing me the right direction.