Door sensor for a usually open door

Hi there,

I have configured a door sensor for a wine cellar… and the door is usually open. Problem is: every time HA reboots or something like that, its state is shown as closed - where it is actually open, as it has not changed its state.

Any suggestion on how to solve this, besides actually closing the cellar door? I only close it when I leave town - that’s why.

I thank you in advance!!

Sincerely,

MO

What door sensor? If it is a mqtt door sensor, make sure it publishes it state with the retain flag set, so the state gets preserved across HA restarts.

Thanks, Francis.

it 's a cheap RF433 sensor, which shows open and closed state. My configuration is:

  • platform: mqtt
    name: “Bodega Vinos”
    state_topic: “sonoff_bridge/tele/RESULT”
    value_template: ‘{{value_json.RfReceived.Data}}’
    payload_on: “D7C80A”
    payload_off: “D7C80E”
    device_class: door
    qos: 0

Anything (obvious) missing???

Cheers!

You’ll want to update on the Tasmota side to send the MQTT message with the retain flag set: https://tasmota.github.io/docs/MQTT/#retained-mqtt-messages

1 Like

I use strategy 2 to set the retain flag.

( I have 433Mhz door sensors too)

1 Like

Couldn’t find how… tried using the “retain: true” line, and did not work.

:frowning:

Thanks Francis. I tried using strategy 1, and it shows no error messages, but the same thing happens: as soon as I reboot HA, it again shows the sensor as closed, whereas it has been left open.

  • platform: mqtt
    name: “Bodega Vinos”
    state_topic: “sonoff_bridge/tele/RESULT”
    value_template: >-
    {% if value_json.RfReceived.Data == ‘D7C80A’ %}
    {{‘ON’}}
    {% elif value_json.RfReceived.Data == ‘D7C80E’ %}
    {{‘OFF’}}
    {% else %}
    {{states(‘binary_sensor.bodega_vinos’) | upper}}
    {% endif %}
    device_class: door

What is the “upper” thing for??

Thanks again!

Cheers.

Strategy 1 does not let you set the retain flag.

See this snippet :

d = { 
      '2291358':['frontdoor','ON','true'],
      '2291351':['frontdoor','OFF','true']
    }


p = data.get('payload')

if p is not None:
  if p in d.keys():
    service_data = {'topic':'sensor/{}'.format(d[p][0]), 'payload':'{}'.format(d[p][1]), 'qos':0, 'retain':'{}'.format(d[p][2])}
  else:
    service_data = {'topic':'sensor/unknown', 'payload':'{}'.format(p), 'qos':0, 'retain':'false'}
  hass.services.call('mqtt', 'publish', service_data, False)

The third parameter of d is true, so the retain flag is set and the state of the door is preserved across HA restarts.