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.

1 Like

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.

1 Like

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.

I can’t for the life of me register the DW2 as closed no matter what I do…

Press ADD alarm in Ewelink app and open. No problem, alarm added.
Press ADD and shut but it doesn’t register.
Could I have a faulty product or am I being a donut and missing something?

cuz DW2-RF only sends rf signal when it is being seperated, a really silly design.

Just discovered after buying a few of these that this is only for open status! So I’ll never know when that door closes. I ask why! Can anyone tell me the use case here?

I have 2 door sensor in my drawer that do the same. They are only usable for intrusion detection, not for home automation.

1 Like

I had 4 … sold them on. Useless for automation and battery life is dire. Busy with Sonoff SV flashed with ESPHome and reed switches to do door open/close sensing.

1 Like