Sonoff DW2 door sensor going to state "unavailable"

Hi Guys

I have a Sonoff DW2 433mhz door sensor mounted on a door, it correctly reports if the door opens or closes but seemingly goes into some sort of sleep mode and its state defaults to unavailable after a short period.

The problem is that I want to use this door sensor to check if the door has been left open i.e. if state is on then I know the door is open and I can have an automation check for this state but because its going into unavailable mode it is not reporting that the door is open.

Any ideas on how to somehow retain last state or prevent it from going into unavailable state?

Thanks in advance.

Not without seeing your sensor config.

I’m just running it off a Sonoff RF Bridge so do not have a sensor config for it. Below extract on the Sonoff console when the states changed and screen grab of the sensor, I’m just monitoring for state changes.

11:44:57 MQT: sonoff-rf-bridge/tele/RESULT = {"Time":"2020-03-26T11:44:57","RfReceived":{"Sync":10560,"Low":340,"High":1010,"Data":"22080F","RfKey":"None"}}
11:45:20 MQT: sonoff-rf-bridge/tele/RESULT = {"Time":"2020-03-26T11:45:20","RfReceived":{"Sync":10600,"Low":310,"High":1040,"Data":"220803","RfKey":"None"}}

entities:
  - entity: binary_sensor.garage_door_entrance
    name: Patio Door
type: glance

I didn’t realise the sonoff RF bridge supported discovery.

This is the way I filter out unknown states from my gate sensor that goes to sleep:

automations:

- id: lane_gate_open
  alias: 'Lane Gate Open'
  initial_state: true
  trigger:
    platform: state
    entity_id: binary_sensor.laneway_gate
    to: 'on'
  action:
    service: mqtt.publish
    data_template:
      payload: "ON"
      topic: 'home-assistant/variable/lane_gate'
      retain: true

- id: lane_gate_closed
  alias: 'Lane Gate Closed'
  initial_state: true
  trigger:
    platform: state
    entity_id: binary_sensor.laneway_gate
    to: 'off'
  action:
    service: mqtt.publish
    data_template:
      payload: "OFF"
      topic: 'home-assistant/variable/lane_gate'
      retain: true

binary sensor:

- platform: mqtt
  state_topic: "home-assistant/variable/lane_gate"
  name: "lane_gate_filtered"
  payload_on: 'ON'
  payload_off: 'OFF'
  qos: 0
  device_class: opening

@tom_l thanks for your config, I’m being a dork I did setup this sensor in my binarysensors.yaml file, please see below. I set this up quite a while ago and then never used it so kind of forgot what all I had done…

- platform: mqtt
  name: 'Garage Door Entrance'
  state_topic: 'sonoff-rf-bridge/tele/RESULT'
  value_template: >-
    {% if value_json.RfReceived.Data == '220803' %}
      {{'ON'}}
    {% elif value_json.RfReceived.Data == '22080F' %}
      {{'OFF'}}
    {% else %}
      {{states('binary_sensor.sonoff_rf_bridge_button1') | upper}}
    {% endif %}
  device_class: door

Is this a sensor or a binary sensor?

If it’s a sensor change it to this to ignore anything except on or off.

- platform: mqtt
  name: 'Garage Door Entrance'
  state_topic: 'sonoff-rf-bridge/tele/RESULT'
  value_template: >-
    {% if value_json.RfReceived.Data == '220803' %}
      {{'ON'}}
    {% elif value_json.RfReceived.Data == '22080F' %}
      {{'OFF'}}
    {% else %}
      {{states('sensor.garage_door_entrance') }}
    {% endif %}
  device_class: door

If it’s a binary sensor I’m surprised it works as the value template needs to resolve to true or false. Not ON or OFF.

Home Assistant detects it as a binary sensor (binary_sensor.garage_door_entrance)

Let me try the changes you have suggested and see if it helps, thanks again.

Make sure you use this instead then:

    {% else %}
      {{states('binary.sensor.garage_door_entrance') }}

Thanks @tom_l looks like it retains its state however if I restart HA the state is not retained and it goes back to off (closed)

If you want to retain a state from the rf bridge when restarting HA , read this topic :

Use strategy 2 to set the retain flag.

Thanks francisp, this might be above my pay-grade :slight_smile: but I’m certainly going to give it a try.

EDIT:

Well I’ll be!!! Gave it a go and got it working first time, pretty pleased with myself, retains the state even after HA restart, thanks for the tip.