Remove Unavailable reporting from door sensor in UI using binary sensor template

My door sensor is a samotech door sensor and works very well, except lovelace card entries report “Unavailable” a short time after a state transition. This is annoying but understood as the device is not retransmitting regulary in order to conserve battery power, so HA reports the sensor “Unavailable”

I wanted to do this without using Node Red so viewed various posted solutions, some similar to my final one. Here is my solution: Under Settings, Helpers, select Create Helper then Template and Binary Sensor. The name of the binary sensor is sliding_door. The icon I used is the mdi:door_closed because this icon changes when the door opens. Most important was the entry for the Template Options, here is the code used to make it work:
{% if is_state(‘binary_sensor.tz3000_bnai1qnw_ts0203_opening’, ‘on’) %}
{{states(‘binary_sensor.tz3000_bnai1qnw_ts0203_opening’) }}
{% elif is_state(‘binary_sensor.tz3000_bnai1qnw_ts0203_opening’, ‘off’) %}
{{states(‘binary_sensor.tz3000_bnai1qnw_ts0203_opening’) }}
{% else %}
{{states(‘binary_sensor.sliding_door’) }}
{% endif %}
where “binary_sensor.tz3000_bnai1qnw_ts0203_opening” is the default entityID of the samotech door sensor.

No more “Unavailable” reporting now just Open or Closed, providing you use the new binary sensor in the UI card.
Happy Days

1 Like

This is a bit redundant.

You just checked for the state of the sensor, there’s no need to get it again, just do:

{% if is_state('binary_sensor.tz3000_bnai1qnw_ts0203_opening', 'on') %}
{% elif is_state('binary_sensor.tz3000_bnai1qnw_ts0203_opening', 'off') %}
{% else %}
  {{states('binary_sensor.sliding_door') }}
{% endif %}

Or even simpler:

{% if states('binary_sensor.tz3000_bnai1qnw_ts0203_opening') in ['off','on'] %}
  {{ states('binary_sensor.tz3000_bnai1qnw_ts0203_opening') }}
{% else %}
  {{states('binary_sensor.sliding_door') }}
{% endif %}

Also please use backticks to format your pasted code, not quotes. I had to replace all your and with '.

1 Like

Thanks. My coding was basic, but most importantly, it worked. I will change it to your abreviated code without the redundant checks. It’s still a tidy solution to the “unavailable” reporting issue for battery powered binary sensors using radio communication.

I gues it will work for any sensor so long as the on and off states are changed to the context of the sensor variable.

Shorter still:

{{ states('binary_sensor.tz3000_bnai1qnw_ts0203_opening')
   |bool(states('binary_sensor.sliding_door')) }}

The bool filter converts the input to true or false, with the single argument being the default value to use if the input can’t be converted.

So on/off from the tz3000 sensor gets turned into true/false.

If the tz3000 has any other state (unavailable, unknown), the template will output the raw state of the sliding door sensor.

If that sensor has failed too, you’ll get its failed state.

1 Like


Not only shorter but generic in that no states are listed, just clasified as boolean.

This lets users eliminate unwanted sensor states from their UI cards and make the wanted states available to automations through the new binary sensor entity.

After a reboot Open and Closed were transposed. Testing to find out why.

For a door sensor, on is conventionally Open and off is Closed.

The historical data was lost due to onboarding and restoring due to issues not relevant to this post.

After HAOS fresh start with no history record, the status does not update on the UI till either the door is Opened or Closed or the sensor transmits the status, which can take a while.