Integrating the 4 channel Sonoff R3 Pro into Home-Assistant and Node-red

Integrating the 4 channel Sonoff R3 Pro into Home-Assistant and Node-red

One of the things I’ve been meaning to get for a while now was a Sonoff R3 Pro. Now for those of you not familiar with this device, it’s essentially a 4 channel smart switch. There’s a non-pro version and the pro version. I opted for the Pro version mainly due to the fact that it comes with inbuilt 433Mhz RF control, as well as the ability to handle higher loads. I thought I would write a quick post describing how I integrated it into my current setup.

Sonoff R3 Pro
Sonoff R3 Pro

First thing’s first, there’s no way am leaving this running Sonoff firmware. So Tasmota was the first port of call. Thankfully the pin out holes on the motherboard are just the right size for some dupont jumper cables. I know some like to solder on headers, but personally, I don’t like to solder anything if I can get away with it. I connected the jumpers to my USB FTDI programmer except the ground. You need to hold down the relay 1 button as you power it up so that the sonoff can go into flash mode (remember RX=>TX and vice versa). You’ll know if you’ve done it right because as you power it up, the Wifi led (blue) won’t flash on. I downloaded the latest version of Tasmotizer and fired it up.

Tazmotizer Main Screen
Tazmotizer Main Screen

Within seconds it had found the correct port and we were good to go. I elected to backup the original firmware first (note this .bin file will download automatically into the folder the tazmotizer.exe is located). I set the option to “release” (at the time of writing that’s Tasmota 9.2) and set it to go. A few moments later we were done. I must admit, i didn’t pay too much attention to tasmotizer, i’d used it a few times before, but the latest variants had the ability to send a config to the device (MQTT details, wifi SSID/Password etc). I hadn’t used that before, but I decided to give it a go.

Tazmotizer Send Config Screen
Tazmotizer Send Config Screen

On the module option at the bottom,  I selected 4 channel sent the config across, waited a few moments and then hit the get-ip button. For some reason or another it didn’t work. It returned me the following XX.XX.XX.XX. It wasn’t an issue though, I checked my router’s IOT network and sure it enough, there was my r3 pro. I went to the website and tested the buttons, relays 1-4 were working as needed.

Next thng was to get it into Home-Assistant. Configuration->integration ->MQTT I clicked on the newly found r3 pro and added it to lovelace.

Sonoff R3 Pro Home-Assistant
Sonoff R3 Pro Home-Assistant

So far so good. The sonoff software supposedly allows for things such as Inching (closing the relay for X amount of time) and Interlocking where pressing 1 relay automatically turns off the rest. Am not quite sure exactly where the interlocking feature would come in to play, but I wanted to make sure I had the same capabilities. Enter Node-red. For those of you not familiar with using MQTT and node-red, might I suggest you take a look at the first post of my three part Node-red tutorial which can be found here.

First thing’s first, simple on/off of each relay via MQTT:

Full MQTT control
Full MQTT control

Next we send a command to output a full status report by sending a message of cmnd/r3pro/POWER0.

Then I wanted to look at Inching (timed closure), this was a simple case of using the trigger node. Change the time as per your requirements.i.e. send “true” to the relay and then after x amount of time send a new payload of “false” to switch the relay off.

mqtt inching example
mqtt inching example
Trigger node
Trigger node

Finally the missing part of the puzzle was interlocking. This could have been accompanied by sending several commands. i.e. turn relay 1 on, turn relay 2-4 off. Then rinse and repeat for the other relays. Whilst this would work perfectly well, I wsa searching only and found a simpler way of doing it, via the function node. I want to give credit for this piece of code to Matt from Notenoughtech. He has a cool youtube channel and a blog. See below for an example of one of the nodes.

interlocking function node
interlocking function node

Once I tested the first one, it was a simple case of rinse and repeat for the other relays, only varying which relay was going to become true.

Interlocking flow
Interlocking flow

So there we have it. One locally controlled 4 channel smart switch. I’m still trying to decide where to deploy this. At present, I’m thinking of the following potential usage cases:

  1. Outside garden lights – with four channels this could allow for certain zones and mood lighting to be deployed around the property.
  2. Garage controller – 1 channel for garage door control, 1 channel for main lighting, 1 channel for desk / focused lighting, leaving the last channel available for maybe a second garage door or additional outside lighting zone.
  3. Kitchen lighting – with 4 channels, you could have above and under cabinet lighting, as well as dual-main zone lighting.
  4. Aquarium or swimming pool control – lighting, pump, filter, heating
  5. Home-cinema control – Shades, projector screen, subwoofer control, zone lighting etc.

I’m a big fan of this small unit. for less than £30 you can potentially create a complete system. Let me know if you can think of any other cool ideas for this unit. The links below maybe affiliate, which mean they don’t cost you any extra, but help to support the blog if you’re interested in purchasing one of these units for yourself:

Sonoff R3 Pro on Amazon

Sonoff R3 Pro on Aliexpress

As a side point, if you enjoyed this type of content and would be interested in sharing your own solutions, tips and tricks with like minded people perhaps you’d consider joining our facebook group. The aim of this group will hopefully be more show and tell rather than support, but that’s not to say we can’t lend a helping hand 🙂

https://www.facebook.com/groups/386238285944105

Cheers

 

The Smarthome Book
The Smarthome Book

 

Comments

  1. Interlocking is supposed to be atomic operation, fail free. Usage for the interlocking is duct fan with three speeds: low, mid, high. The duct fan has 3 different wires for those 3 speeds and you need to power only a single wire for the respective speed. It should be atomic, i.e. if turning off one of the channels fails, then the entire operation fails. I hope the original firmware makes sure that first all channels are off and after few ms turns the desired channel on (you need small delay according to relay datasheet, for the amount of time needed to turn off completely). It seems your emulation might fail and you might end up with 2 or more channels turned on.

    1. I know it’s two years later but this is exactly what I’m looking to use a Sonoff switch for. Only issue I see is my motor is designed to start on high with an auxiliary start winding. Not sure what the outcome will be if the low speed wire is energized first.

    1. Really? I’ve never used the RF with it. I’ll need to go and check that when I have time. The RF for me was always an additional feature I wasn’t using.

Leave a Reply