Sonoff RF Bridge 433 Mhz & Tasmota custom firmware

Introduction

This project is about controlling power plugs connected to standing lights in my living room. I’ve a set of 3 plugs with one remote controller. The remote controller uses radio-frequencies (RF) to sent commands to the plugs. The RF are of the common 433 Mhz.

My current home automation is hosted in-house and built around Home Assistant. My core devices communicate together through a MQTT broker.

My goal is to use a Sonoff RF Bridge to link the dumb RF433 devices (power plugs = receive only, remote controller = send only) to Home Assistant using the MQTT broker. The base Sonoff RF Bridge uses a custom cloud app from Sonoff called eWeLink. I’ll replace that with a custom open source firmware : Tasmota.

Let’s summarize what we need :

  1. Replace the Sonoff firmware by Tasmota to access its full potential and integrate it into local only Home Assistant;
  2. Setup Tasmota for my WiFi network;
  3. Define the remote control keys within Tasmota;
  4. Integrate Tasmota into Home Assistant.

Spoiler : That failed because my remote controller uses rolling codes while the bridge only support fixed codes. Something I wasn’t aware of when purchasing the bridge. I’m still posting this as I’d like to use it later on anyway.

Well, not exactly, each button uses one of 4 codes. Always the same 4 in a loop. I haven’t yet checked how to hack that.

Flashing Tasmota

About Tasmota

It’s way easier to just quote the Tasmota page :

Tasmota is an open source firmware for ESP8266 based devices created and maintained by Theo Arendst.

Everything began as Sonoff-MQTT-OTA-Arduino with a commit on 10. March 2016. by Theo Arendst. Its goal was to provide ESP8266 based ITEAD Sonoff devices with MQTT and ‘Over the Air’ or OTA firmware using Arduino IDE.

What started as a simple way to hack a cloud bound Sonoff Basic (one of the first cheap and accessible smart home devices in the market) into a locally controlled device has grown into a fully fledged ecosystem for virtually any ESP8266 based device.

Everything documented here started from the … Getting Started page at Tasmota again. Tasmota has a quite extensive list of commands, look at their Commands page.

Preparing the flash

To flash a custom firmware, one needs access to the serial interface of the chip, usually this involves a USB to Serial adapter and a few wires to be driven to the PCB.

First, remove the rubber feet and unscrew the box, this gives full access to all pins of the PCB. For the sake of documentation I’ve temporarily un-soldered the big green LED used as background for the Sonoff logo.

The PCB exposes a few headers :

  • J4 (near buzzer and clock) : 3V3, C2CK, C2D, GND
  • J3 (between RF chip and big sliding switch) : GND, TX, RX, 3V3
  • J5 (below J3, left of ESP8285) : 3V3, GPIO5, GPIO4, GND
  • J2 (right of big sliding switch) : SDA, GND, TX, RX, 3V3

What is of interest to us is the J2 because we need the TX and RX lines. The squared hole being the 3V3.

USB-to-Serial adapter (FTDI)

I had already a FTDI USB adapter laying around for my ESP8266 based Wemos D1 Mini. This is a simple USB to FTDI board along with 4 Dupont wires glued together.

Caution : My adapter has a jumper to select between 5V and 3.3V (3V3). Make sure to set this to 3V3.

USB FTDI adapter

For flashing, you must connect the FTDI adapter so that you switch the RX/TX lines between the adapter and the board.

Here are the connections from FTDI to board:

  • (brown) GND <> GND (brown)
  • (red) RX <> TX (orange)
  • (orange) TX <> RX (red)
  • (yellow) 3V3 <> 3V3 (yellow)
Connecting the FTDI adapter to the board

Flashing process using Tasmotizer (Windows)

Once everything is wired properly, this gets really easy. The smart people from Tasmota provides Tasmotizer, a full fledged tool.

Easiest is to select the image you want to flash under “Select image > Release 8.2.0” and the default tasmota.bin build.

Hit Tasmotize! and you’re done.

The device will reboot and starts a new WiFi hot spot called tasmota_xxxxx.

At that moment, remove the FTDI cable and you can put back everything into the box and power it using a USB cable. You’re done for the hardware and flashing part.

Tasmota setup

Initial setup of WiFi

Using your smartphone or a computer, connect to the tasmota_xxxxx network and setup the actual WiFi to be used (AP1). You can even define a secondary WiFi network (AP2).

After setup of the actual WiFi, the device will connect to the proper network and get an IP address from it.

Tasmota configuration

First connection to Tasmota

Since the device does not have a screen, you’ll have to get its IP address from your home router or access point admin. In my case, this is from the connected computers of the ISP home router (which is garbage, I’m considering buying a UniFi Security Gateway).

VOO Home router, connected computers

Connect to that IP using your browser, for instance at http://192.168.0.3/

This opens the built-in web server for Tasmota configuration.

MQTT configuration

From the home page, go to Configuration > MQTT.

After a new reboot, you’ll start seeing messages from your device on the MQTT server. Getting pretty close! You can also get a view from Tasmota Console view. This is very useful to get the RF codes sent by the remote controller.

Connect to Home Assistant

Configuring the devices

Manual setup

Since I like doing things myself, I’ve initially done this using a manual setup. The usual way when Home Assistant is up and running is to declare new MQTT entities. Below is an example for one of the power plug (called “Eclairage – Meuble TV”).

switch:
  - platform: mqtt
    name: "Eclairage - Meuble TV"
    command_topic: cmnd/tasmota_B2E86C/rfcode
    availability_topic: "tele/tasmota_B2E86C/LWT"
    payload_available: "Online"
    payload_not_available: "Offline"
    payload_on: "#C80E70"
    payload_off: "#CCCC10"
    optimistic: true

There are 3 important things to be noted :

  • My Sonoff RF Bridge is known as tasmota_B2E86C;
  • The RF code for plug ON is C80E70
  • The RF code for plug OFF is CCCC10

NB : Well, the RF codes are what I thought they were. As my Profile stuff is using kind of rolling codes, again, this won’t actually work but the setup is properly done as far as I can tell.

You must repeat the same entity block for each power plug you’d like to declare. So for a remote controller with 4 On / Off set of buttons (A, B, C & D) but only 3 power plugs you’d end up with 3 blocks for MQTT. Eache block having 2 RF codes (On & Off).

Auto discovery

Tasmota and Home Assistant are also able to use auto discovery. For that, you need to enable specific option set. I haven’t yet had the chance to try this out. Here is some reading:

  • https://community.home-assistant.io/t/sonoff-rf-bridge-strategies-for-receiving-data/108181
  • https://community.home-assistant.io/t/help-with-sonoff-tasmota-rf-bridge-switch-config/85949
  • https://tasmota.github.io/docs/Home-Assistant/
  • https://community.home-assistant.io/t/tasmota-sonoff-automated-discovery-in-hass/126131

Conclusion

I actually enjoyed this (failed) project as I’ve learnt a few new things, which is why I actually like hacking stuff.

  1. I’ve been able to discover the Tasmota firmware, this look amazing and is a premium choice for my other WiFi plugs (post to follow);
  2. The Sonoff hardware is a joy to hack into, they are hacking friendly and receive a lot of support from the community;
  3. Home Assistant is not always easy to setup but this is getting interesting now that I have more than heating devices.

References

And some more documentation.

  • https://1technophile.blogspot.com/2018/02/adding-infrared-emitter-to-sonoff-rf.html
  • https://github.com/arendst/Tasmota/wiki/Sonoff-RF-Bridge-433 (cache)

Sending RF Signals with Sonoff RF Bridge

Post Author: Shut

Leave a Reply

Your email address will not be published. Required fields are marked *