SONOFF RF Bridge

Once the framework is there you start thinking about usecases. Usecases immediatly call for sensors. In my case, I’m still looking for a nice set of window sensors. I’d be interessted in:

  • Message ‘Window Open’
  • Message ‘Window Closed’
  • Message ‘Window vibration’ (e.g. somebody trying to get in)’
  • Avoid 230V power requirement
  • WAF (Woman Acceptance Factor) - means the packaging / case must be ‘ok-ish looking’

Secondly I really had a hard time when trying to get PIR motion sensors running along with ESP8266. It kind of worked once in a while, but there where tons of alarms. A colleague told his where stable for weeks, but then he got similar effects. Maybe its interferrence problems, maybe its me - somewhen I decided I had wasted enought time.

4 weeks ago I ordered SONOFF stuff at AliExpress similar to the following set. A battery powered 433 MHz PIR sensor, a battery powered Window Reed contact and an Espurna / Tasmota compatible 433MHz to Wifi / Mqtt / .. / bridge.

https://www.itead.cc/sonoff-rf-bridge-433.html

Hacking the RF Bridge

The friendship kicked off with a hard start. After a night with to less sleep I had tried Espurna and Tasmota, fighted with the Atom IDE under Windows & almost trashed the device with physical force.

Right now I’m pretty amazed by the bridge, as:

  • Espurna firmware flashing is easy - if you do it right :-)
  • MQTT messages arrive on Window Open (SONOFF DW1, 4,49$ at Aliexpress)
  • MQTT messages arrive on Motion (SONOFF PIR2, 8,79$ at Aliexpress)
  • MQTT messages can trigger Brennstuhl PowerSwitch On/Off with a bit of hacking
  • The 433 sender range is much superior to the one I had on my Raspberry
  • Downside: The DW1 doesn’t notify on Window close, so you cannot implement a ‘window still open function’
  • Downside: DW1 No vibration sensor (.. would have been nice to detect somebody tempering with the window ..)

So - pretty good deal for the money. If i saw it right Espurna would even allow Amazon Alexa integration. But - Alexa is not in the house, so nothing i really examinated.

Flashed ESPURNA to RF Bridge

- Download the esptool.py program from https://github.com/espressif/esptool

- Put device in firmware upload mode (hold button while connecting to power) and clear flash with command esptool.py --port <COMX> erase_flash

- Get the firmware file sonoff.ino.bin from https://github.com/xoseperez/espurna/releases/ (e.g. https://github.com/xoseperez/espurna/releases/download/1.12.3/espurna-1.12.3-itead-sonoff-rfbridge.bin )

- Flash a Sonoff Touch or Sonoff 4CH with command esptool.py --port COM5 write_flash -fm dout -fs 1MB 0x0 sonoff.ino.bin

- esptool.py --port /dev/ttyS15 write_flash -fm dout -fs 1MB 0x0  espurna-1.12.3-itead-sonoff-rfbridge.bin

- Connect to the WiFi operated by the Espurna Bridge - configure WiFi & MQTT settings, restart

MQTT message formats

ESPURNA MQTT messages

sonoff/ESPURNA_9EEF32/data : {"rfin":"2FF8019004A60DFEE1","time":"2018-02-04 17:36:58","mac":"60:01:94:9E:EF:32","host":"ESPURNA_9EEF32","ip":"192.168.178.222","id":4958}

sonoff/ESPURNA_9EEF32/data : {"rfin":"30E801A404C4D263CE","time":"2018-02-04 17:37:01","mac":"60:01:94:9E:EF:32","host":"ESPURNA_9EEF32","ip":"192.168.178.222","id":4959}

My desired MQTT messages

I use a custom python ‘mqttRewrite’ script to subscribe to above messages & transform them to a format I defined.

sensor/motion/ct60-1 : {"TS":"2018-02-04 11:18:00", "SENSOR_TYPE":"ALARM", "OBJECT":"CT60-1", "SENSOR":"ESPURNA_D263CE","KEY":"Motion","VALUE":"1","UNIT":"MOTION"}

sensor/reed/dw1-1: {"TS":"2018-02-04 17:36:58", "SENSOR_TYPE":"ALARM", "OBJECT":"WIN-1", "SENSOR":"ESPURNA_0DFEE1","KEY":"Window","VALUE":"1","UNIT":"OPEN"}

more ESPURNA messages - not in use

sonoff/ESPURNA_9EEF32/data : {"relay/1":"0","relay/2":"0","relay/3":"0","relay/4":"0","relay/5":"0","relay/6":"0","relay/7":"0","vcc":"3264","time":"2018-02-04 17:10:02","mac":"60:01:94:9E:EF:32","host":"ESPURNA_9EEF32","ip":"192.168.178.222","id":4929}
sonoff/ESPURNA_9EEF32/data : {"app":"ESPURNA","version":"1.12.3","host":"ESPURNA_9EEF32","ip":"192.168.178.222","mac":"60:01:94:9E:EF:32","rssi":"-61","uptime":"198908","datetime":"2018-02-04 17:15:02","freeheap":"20576","relay/0":"0","time":"2018-02-04 17:15:02","id":4930}
sonoff/ESPURNA_9EEF32/status : 1

Brennenstuhl

As mentioned - the ability to drive the Brennenstuhl PowerSwitches via 433 is a nice ‘addon’.

The ‘learn’ mode didn’t work for me. I understand there are two chips on the Bridge, one is flashed with ESPURNA and operates Wifi, Mqtt messages etc.. The other one stays with ithead code and does the decoding / learning part. That one doesn’t seem to fullfill all requirements.

A guy called ‘Felix’ did a nice job of getting the codes required for me. You can find details here or in his comments in this post. The article itself seems to be authored by the ESPURNA author.

1  1  1  1  1    1  0  0  0  0    01 00			# This depends on how you put the mini jumpers on your device
00 00 00 00 00   00 01 01 01 01   01 00			# Invert

000000000000010101010100 (bin) -> hex 551 / 554		# bin -> hex e.g. via http://www.arndt-bruenner.de/mathe/scripts/Zahlensysteme.htm

2650013203BD000551              ->  11111 10000 on 
2650013203BD000554              ->  11111 10000 off

Simply copy & paste that codes into the GUI - and be able to power your power switches

Image