I have received finally DIGOO door sensor which is capable of sending separate 433MHz codes for closing and opening state. I tried to get some use-case for it. I will use it to monitor fridge door in case if somebody does not close them enough. In this tutorial I use also previous setup of Sonoff RF Bridge. This time we will received codes and using MQTT control OpenHAB items. If door will be open longer than 2 minutes then Alexa remind me about it.
Digoo Door Window Sensor
Digoo Window Sensor is very small. Dimensions as on the picture below. It is funny part because on the website they put pictures as this sensor looks like at least 20 cm high :). In real is very tiny and looks elegant.
It is powered up button battery CR2032, which according to website shoud stand for 2 years. There is also led indicator chaning status. It sends separate codes for Open and Close state. A little bit specification below
Brand | DIGOO |
Type | 433MHz Door Window Alarm Sensor |
Voltage | 3V Button Battery (Included in package) CR2032 |
Under Voltage Monitoring | 7.5 V+/-0.5V |
Static Current | <=10uA |
Triggering Distance | >20mm |
Emission Current | <=15mA |
Emission Distance | >=120 m (Open area) |
Emission Frequency | 433MHz |
Working Temperature | -10℃ ~50 ℃ |
I have also to other similar sensors but it looks like they send only one code once sensor is OPEN. They are cheaper but not every use case will be covered. Anyhow please find they pictures to avoid/order them:
Receiving codes
At this stage I assume that you have OpenHAB instance and also Sonoff RF Bridge 433MHz flashed with Tasmota. If not, please follow my previous posts. Let’s try to capture codes. In console window for Sonoff we should see codes similar to these ones, whenever you move sensors close together and far away:
1 2 |
tele/sonoff-bridge/RESULT {"RfReceived":{"Sync":12900,"Low":450,"High":1250,"Data":"082439","RfKey":"None"}} tele/sonoff-bridge/RESULT {"RfReceived":{"Sync":12890,"Low":440,"High":1250,"Data":"082433","RfKey":"None"}} |
The same should be visible in your MQTT broker. It is important as we will use it further in OpenHAB instance. Steps how to configure and part of configuration that will be used you find in this post. You may notice “Data” field. They are differ each other and this is what we use in our configuration. First define new thing called door1 in .things file. They are also debug things for observing what code Sonoff RF Bridge received last time.
.things
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Bridge mqtt:broker:localbroker [ host="10.0.1.10", secure=false, clientID="OpenHABv2" ] { Thing mqtt:topic:sonoffbridge { Channels: Type string : reachable "Reachable" [ stateTopic="tele/sonoff-bridge/LWT" ] Type string : receiveddata "Received Data" [ stateTopic="tele/sonoff-bridge/RESULT", transformationPattern="JSONPATH:$.RfReceived.Data"] Type string : receivedsync "Received Sync" [ stateTopic="tele/sonoff-bridge/RESULT", transformationPattern="JSONPATH:$.RfReceived.Sync"] Type string : receivedlow "Received Low" [ stateTopic="tele/sonoff-bridge/RESULT", transformationPattern="JSONPATH:$.RfReceived.Low"] Type string : receivedhigh "Received High" [ stateTopic="tele/sonoff-bridge/RESULT", transformationPattern="JSONPATH:$.RfReceived.High"] Type string : receivedrfkey "Received RfKey" [ stateTopic="tele/sonoff-bridge/RESULT", transformationPattern="JSONPATH:$.RfReceived.RfKey"] Type number : rssi "WiFi Signal Strength" [ stateTopic="tele/sonoff-bridge/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"] Type contact : door1 "Door 1" [ stateTopic="tele/sonoff-bridge/RESULT", transformationPattern="JSONPATH:$.RfReceived.Data" ,allowedStates="082439,082433", off="082439", on="082433"] } } |
I have defined contact type of thing, then which states are allowed in case we have more sensors and also which code means open/close (on/off) state. In this approach you do not need to use rules to recognize it. MQTT + OpenHAB contact item logic does it for you.
.items
1 |
Contact GF_Sonoff_RF_Door_1 "Door 1:" (GF_Sonoff_RF) { channel="mqtt:topic:sonoffbridge:door1" } |
.sitemaps
1 2 3 4 5 6 7 8 9 10 |
Group item=GF_Sonoff_RF { Text item=GF_Sonoff_RF_Reachable label="Status [%s]" Text item=GF_Sonoff_RF_Received_Data label="Data [%s]" Text item=GF_Sonoff_RF_Received_Sync label="Sync [%s]" Text item=GF_Sonoff_RF_Received_Low label="Low [%s]" Text item=GF_Sonoff_RF_Received_High label="High [%s]" Text item=GF_Sonoff_RF_Received_RfKey label="RfKey [%s]" Text item=GF_Sonoff_RF_RSSI label="WiFi Signal Strength [%d %%]" Text item=GF_Sonoff_RF_Door_1 label="Door [%s]" } |
Once you receive signals from sensor parameters should change and status as well CLOSE or OPEN (last line):
Good now time to force you door to speak.
Amazon Echo Dot + Alexa voice
I do not have any Alarm Siren yet. Maybe I will add this one working also over 433 Mhz. For now I wondered how I can use my Amazon Echo Dot and Alexa voice to remind me about issue.
There is nice OpenHAB binding available, which utilizes all Alexa features. For more information go to documentation. For simplicity for you I just use text to speech functionality.
Installing amazonechocontrol binding
First you add binding to you conf/services.cfg file, or by using PaperUI. I’m old school and everything want to keep in files. Edit:
1 2 3 |
# A comma-separated st of bindings to install (e.g. "binding = sonos,knx,zwave") binding = http1,ntp,samsungtv,network,mqtt,exec,openweathermap,weather1,amazonechocontrol |
Give it few seconds to be installed. In meantime create amazonechocontrol.things file with the content:
amazoncontrol.things
1 2 3 4 |
Bridge amazonechocontrol:account:account1 "Amazon Account" @ "Accounts" { Thing echo echo1 "Alexa" @ "Living Room" [serialNumber="SERIAL_NUMBER"] } |
For now Serial number is whatever. We get it in next steps.
Login to amazon devices over OpenHAB
You have to put to your browser url http://address-to-your-oh:8080/amazonechocontrol/
You should get website with link and asked for providing Amazon credentials.
after login you will get list of registered devices. Seek for Echo Dot. You should see also Serial number that you copy and paste to your configuration.
After updating configuration refresh website and under Thing column you should see Alexa in Online state as below:
Well done! Now OpenHAB last configuration part.
amazonechocontrol.items
1 2 3 |
Group Alexa_Living_Room String Echo_Living_Room_TTS "Text to Speech" (Alexa_Living_Room) {channel="amazonechocontrol:echo:account1:echo1:textToSpeech"} Dimmer Echo_Living_Room_TTS_Volume "Text to Speech Volume" (Alexa_Living_Room) {channel="amazonechocontrol:echo:account1:echo1:textToSpeechVolume"} |
Basically for my usage just Echo_Living_Room_TTS item is the most relevant. For other interesting examples please check binding documentation.
amazonechocontrol.rules
This is almost done. Please create amazonechocontrol.rules file in rules conf/rules folder. I put two rules. First is just for testing purposed. Immediatly after opening sensor Alexa should speak.
1 2 3 4 5 6 |
rule "Say welcome if the door opens" when Item GF_Sonoff_RF_Door_1 changed to OPEN then Echo_Living_Room_TTS.sendCommand('Your fridge is open') end |
This one is the final one. We trigger timer for 15s after opening. After that time if sensor is still in OPEN state Alexa will remind. Otherwise nothing happened.
1 2 3 4 5 6 7 8 9 10 11 12 |
var Timer stopAlarmTimer = null rule "Warn if the door opens" when Item GF_Sonoff_RF_Door_1 changed to OPEN then if (stopAlarmTimer === null) { stopAlarmTimer = createTimer(now.plusSeconds(15)) | stopAlarmTimer.cancel() stopAlarmTimer = null if ( GF_Sonoff_RF_Door_1.state == OPEN ) { Echo_Living_Room_TTS.sendCommand('Your fridge is still open') } } else { return; } |
1 |
Hi is this using mqtt 2.5 if so what bindinds should I have
These are my bindings from addons.cfg file:
#A comma-separated st of bindings to install (e.g. "binding = sonos,knx,zwave")
binding = http1,ntp,samsungtv,network,mqtt,exec,openweathermap,weather1,amazonechocontrol
mqtt it’s in version 2.x
mqtt1 would be in version 1.x and config files would be also different.
Hi
Thanks for your complet tutorial. Nice work !
One question.
I want to assign the Thing “Door1″ in your exemple to the location”Cellar” for exemple.
(Exemple for another Thing in MQTT :
Thing mqtt:topic:Door1 “My Door in basement” @ “Cellar”
…)
Norm is :
Thing :: “Label” @ “Location” [ ]
Means in this case it’s always linked to SonoffRF Bridge location:
If your Sonoff Bridge is in Floor1 all components are in Floor1 :o( because they depends from the bridge…
Thing mqtt:topic:sonoffbridge “Bridge” @ “Floor1” {
How can we manage the location where we want please ?
(I don’t want to look for Bridge RF to see if my door is opened or closed in a location (like Cellar, Garage…)
Thanks for your help
Location here what I spotted is used only for tabs in PaperUI. For general usage I would rather follow in .items files using Groups.
It is easier later control set of devices in certain groups later in context to Amazon Alexa, Persistence etc.
More regarding Groups https://www.openhab.org/docs/configuration/items.html#groups