Smart plugs are the easiest way to automate your home, but at around $40 for a Wi-Fi or ZWave based plug, you’re unlikely to buy more than a few.
You may already have some cheap RF jacks that come with their own remote and have some channel and ID selectors on the back. Unfortunately, there are no smart home hubs on the market. smart home centers who work with those. Wouldn’t it be great if you could somehow link them to your home smart home system? Well, you can — quite easily actually — with about $10 in installments.
With a little more work, you can also integrate other specialized RF-based remote hardware, such as this budget movie screen.
What you need:
- ESP8266 NodeMCU v12E dev board (exact model doesn’t matter, v1 or v3 will work too). The reason we are using the NodeMCU board is because we want to have a simple Wi-Fi connection later on. Link for a pack of 2 that costs $7 each.
- Package 433 MHz transmitter and receiver (about $3).
- The RCSwitch and MQTT libraries and our code can all be downloaded from Github.
- MQTT server, local or remote.
- Some RF connectors work in the 433 MHz band (this should be indicated on the remote control). I bought mine from Maplin as a pack of 3 for about £20 ($25.89).
If you are programming a NodeMCU board for the first time, you will need to download the Arduino plugins for it: follow the first part of our introductory guide about the NodeMCU / ESP8266 chip. You will also need CH430 drivers . You can find signed macOS CH430 drivers here or Windows drivers here.
I used v1.6.5 Arduino because anything above creates more problems than it solves. Downgrade if you haven’t already.
Before proceeding, I am going to take a basic level of programming knowledge. and that you have your NodeMCU setup in the conference manager and you can properly download some demo code. You should also have added the libraries included in our download to the folder Arduino / Libraries .
if you have PubSubClient or MQTT library , create backup it and delete it — the only one I included in the download is the only one where I can reliably receive messages on the NodeMCU and I a lot of tried!
RF sniffing (optional)
This step is unnecessary if you only want to control the DIP switch or selector jacks — they are supported out of the box and require minimal code changes (although it’s still fun to do in the first place, so you’ll understand what’s going on behind the scenes). ).
If you have other RF remotes that you would like to try adding, you first need to «smell» the RF codes that are being transmitted. To do this, upload a sketch ReceiveDemo_Advanced from folders » Menu -> Examples -> RCSwitch » and change the next line from 0
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
up to 2.
mySwitch.enableReceive(2); // Receiver on GPIO 2 / D4.
Connect the receiver module as follows. Looking at the front of the receiver board (it’s longer than two, the transmitter is square) — the side with the components:
- Far to the right is land. Connect to GND on the NodeMCU board.
- Far left VCC. Connect to the VIN on the NodeMCU board.
- The middle two pins are the signal. Connect any of them to D4 on the NodeMCU (they are connected together, so it doesn’t matter which one).

Now upload modified ReceiveDemo_Advanced and when it’s done, open the serial monitor and start pressing the buttons on the remote. Copy the decimal (including bit length), pulse width and protocol at the push of a button.

After that, I found that my projector screen
- SCREEN UP: Received 8694273/24 bits; Pulse length: 355 or 356; Protocol: 1
- SCREEN DOWN: received 8694276 / 24bit; Pulse length: 355 or 356; Protocol: 1
Continue with as many buttons as you need.
Transmitter testing
Next, we will try to send codes using the transmitter. Connect the transmitter module (square) as follows. Be careful: the markings on these pins are terrible .
The VCC pin is actually in the middle, not on the left side. I destroyed one module in the process of figuring this out. What «ATAD» says is actually «DATA» written backwards. Again, data goes to D4, VCC to VIN and GND to GND (remove the receiver module, you don’t need it anymore).

Download Examples -> RCSwitch -> TypeB_WithRotaryOrSlidingSwitches and change the data output again:
mySwitch.enableTransmit(10);
in
mySwitch.enableTransmit(2);
Note that there are various examples included in the library, and which one is right for you will depend on which type of switch you have. Type A (DIP switches) and B (dials or sliders) are the most common — see pictures on the RCSwitch page. For type B, enabling and disabling a socket is as simple as:
mySwitch.switchOn(1, 4); mySwitch.switchOff(1, 4);
where 1 is the channel ID (top disk) and 4 is the socket ID (bottom disk). They were written in Roman numerals on my rosettes. Therefore, a maximum of 16 individual sockets can be addressed, although multiple sockets can share the same address if you have multiple devices to turn on at the same time.
However, my projector screen was slightly different — a different pulse length was used. So, to operate on that, the following worked. Note that you can also define a different protocol if your remote needs one, BUT make sure you define the protocol BEFORE the pulse width. The pulse length is overwritten when the protocol is changed.
// Note that my screen actually requires TWO button presses (not a long press, but two physical presses), so I'm delaying a bit then sending the same signal again void screenUp(){ mySwitch.setPulseLength(358); mySwitch.send(8694273,24); // (decimal code, number of bits) delay(2000); mySwitch.send(8694273,24); } void screenDown(){ mySwitch.setPulseLength(358); mySwitch.send(8694276,24); delay(2000); mySwitch.send(8694276,24); }
Before proceeding to the next step, check all your codes.
Management via MQTT
Open the thumbnail you downloaded from Github named mqtt_rcswitch.ino and start by changing the network SSID and password for your home. Then change the channel name if you like and install the MQTT server. If you don’t already have an MQTT server running on your OpenHAB installation, read Part 2 of our OpenHAB Beginners Guide Guide Please note that my code is for Type B sockets (rotary switch), although you can easily modify it for DIP switches as well.
The most important part of the code is messageReceived() function A that responds to incoming MQTT commands. In this function, we first check the main keyword — I chose «switch» and «screen». In the «switch» case, we then parse the channel and socket ID; then check the payload body for the command.
void messageReceived(String topic, String payload, char * bytes, unsigned int length) { if (topic.indexOf("switch") >=0){ //switch control, parse out the channel and plug id int channel = getValue(topic,'/',3).toInt(); int plug = getValue(topic,'/',4).toInt(); if(payload == "on"){ mySwitch.switchOn(channel, plug); } else{ mySwitch.switchOff(channel, plug); } } else if (topic.indexOf("screen") >=0){ //screen control if(payload == "up"){ screenUp(); } else if(payload == "down"){ screenDown(); } } /* add another else if here to listen for more commands (or just modify the one above if you dont want screen) */ }
Then the following MQTT commands work by default: