Automation -> Notification -> YAML for IF statement

In a notification action I want to show a notification message reporting the state of an entity. I’ve got this working using

message: >-
    En-suite window state = {{states('Binary_sensor.contact_sensor_en_suite_window')}}

The reported state shows on & off. However it’s a window sensor so I’d like to covert these results to open & closed. I’ve assumed an if statement would do the trick but I’m not familiar with the language so trying to get the right syntax from piecing together google results. Would anyone be able to point me in the direction of where I’m going wrong here please.

  message: >-
    En-suite window state = 
    {% Set state == states('Binary_sensor.contact_sensor_en_suite_window') %}
    {% if state == 'off' %} "Closed"
    {% elif state == 'on' %} "Open"
    {% else %} state
    {% endif %}]

Assignments must use a single =, dual == are explicitly for comparisons. Also not sure whether HA/Jinja would be case sensitive here but ideally this should all be lowercase.

Here you must use dual curly brackets around state, otherwise you will not actually render the contents of the value.

Edit: Scratch any previous suggestions. There is a state_translated function/filter which can be used directly on a string containing an entity id. Simply use that!

message: >-
  En-suite window = {{ state_translated('binary_sensor.contact_sensor_en_suite_window') }}

Ah fantastic, I did wonder if there was an alternative to me manually converting.

Couple of follow up questions…

How do I see what the translated state values are for an entity state?

What is the language this code is written in? I’m struggling to find good sources of the code library. I’m google YAML code for x. Is the code actually called YAML? Is there a definition library anywhere?

In English, they’re listed here for binary sensors:

The config is YAML, the template is Jinja:

And in addition to Troon’s links, this is the general Jinja documentation:

https://jinja.palletsprojects.com/en/stable/templates/

Perfect thank you.

So as long as I set the entity device class, which I think is in the entity settings and “Show as” as that’s where I have this as a window, then the state_translated will use this list to find that device class Binary sensor - Home Assistant