TechSomething

Zigbee Sonoff Door (contact) to Leak Sensor

UPDATE: #

The sensor has been very unreliable and detected phantom contacts, especially at 3 in the morning, even after applying heat shrink tubing on the contacts.
I’ve ended up taking an Aqara Leak sensor, un screwing the contacts (they are done like this on purpose) and attaching the isolated wire to those. It’s working well.

Scope: #

Conversion of a Sonoff SNZB-04 contact (door/window) sensor to leak (or contact) sensor and code for Homebridge,
possibly retaining the reed switch (magnet) functionality.

Preferably modular so I can attach different "probes" for different use cases.

Why: #

I have a spare contact sensor and need a leak sensor,
I have decided to convert this one instead of buying a new one.

Physical: #

I've soldered 2 wires to the reed swith that would normally close the circuit when a magentic field is applied.
In this way we can close the circuit physically.

description

description

I've also modified the case a bit to allow the wires to come out and be soldered to the screw clamps:

description

description

this way I can "mount" it in it's final location:

description

yep, not my proudest soldering work.

Software: #

Using Homebdridge i wanted to define my sensor as a leak sensor insted of a contact sensor.

My config for the contact sensor:

        {
"accessory": "mqttthing",
"type": "contactSensor",
"name": "Sonoff_Door01",
"url": "mqtt://192.168.0.10:1883",
"username": "homebridge",
"password": "password",
"topics": {
"getContactSensorState": {
"topic": "tele/tasmota_ABCDEF/Sonoff_Door01/SENSOR",
"apply": "return JSON.parse(message).ZbReceived['0xABCD'].Contact;"
},
"getStatusLowBattery": {
"topic": "tele/tasmota_ABCDEF/Sonoff_Door01/SENSOR",
"apply": "return JSON.parse(message).ZbReceived['0xABCD'].BatteryPercentage;"
}
},
"integerValue": "true"
}

My configuration for the leak sensor:

        {
"accessory": "mqttthing",
"type": "leakSensor",
"name": "Sonoff_Door01_LEAK",
"url": "mqtt://192.168.0.10:1883",
"username": "homebridge",
"password": "password",
"topics": {
"getLeakDetected": {
"topic": "tele/tasmota_ABCDEF/Sonoff_Door01/SENSOR",
"apply": "return !(JSON.parse(message).ZbReceived['0xABCD'].Contact);"
},
"getStatusLowBattery": {
"topic": "tele/tasmota_ABCDEF/Sonoff_Door01/SENSOR",
"apply": "return JSON.parse(message).ZbReceived['0xABCD'].BatteryPercentage;"
}
},
"integerValue": "true"
}

notice the negation "!" in the "getLeakDetected" "apply" section,
this is used because the normal state of the contact sensor is:

"Contact":1 if it's open

"Contact":0 if it's closed

I needed to invert the status otherwise the leak sensor would be always in "leak detection" when there was no contact, thus the use of "!".
This has been done since I haven't found another way to define this in other ways.

The alert arrives promptly and is considered an high-priority alert:
description