Converting binary sensor from on/off to open/closed

I have a pair of Ecolink TILTZWAVE1 tilt sensors. The sensor reports On or Off. It only shows On/Off on the dashboard. I can never remember which of On or Off means open or closed, so I would like to display the actual state. I have tried to do it by creating a template sensor, but all my attempts have failed, only resulting in a sensor that displayed Off 100% of the time, but never Open or Closed. I’m not posting the code for my actual attempts, as they were derived from suggestions but various AIs, and that is not allowed here.

This is what the device looks like in the Settings / Devices screens :

And in Developer / Tools :

I would like to create the template sensors through the GUI, not configuration.xml . Is it possible ?

Using Manual Customization, you can add a device_class: garage_door property to your existing binary sensor. Even easier, you can specify the preferred device_class of your binary_sensor via the UI. No additional Template Binary Sensor is needed.

Customizing an entity

Here’s the example from the documentation. In the field named “Show as” select “Garage”.

If it’s not an actual garage door then you can choose Door or Window. Here’s the list of device classes for a binary_sensor.


NOTE

Be advised that the actual nominal state values of a binary_sensor are always on/off. However, by setting its device_class (“Show as”) to a desired value, then the values will be displayed differently in the Dashboard (example:Open/Closed).

If you absolutely, positively want the entity’s state values to be Open/Closed then, yes, you’re obligated to create a Template Sensor using a simple template like this:

{{ iif(is_state('garage_door_sensor_left_sensor_state_any', 'on'), 'Open', 'Closed') }}
1 Like

Previous reply is best, but if you do want to create template sensors via UI then:

Goto Settings → Devices & Services → Helpers, Create Helper, choose Template then Template a Sensor

with a template something like

{% if states('binary_sensor.garage_door_sensor_left_sensor_state_only') == 'off' %}
Closed
{% else %}
Open
{% endif %}

Thank you ! It worked great through the GUI. I just didn’t think of looking there.

Thanks ! This worked great also, once I typed the correct entity name.

What was confusing to me is that I needed to use “Template sensor” per your instructions. What I had tried was “Template a binary sensor”. And I couldn’t find a way to do it using that later option.

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which indicates to others that the topic has been solved. This helps other users find answers to similar questions.

A binary sensor has two nominal state values: on and off. In contrast, the nominal state values of a sensor can be whatever you want.