NOTE: This blog post is incomplete because we knocked the house down and rebuilt. I plan to replace this switch with an improved version, so will not be updating this post. The project however is complete and works. The incomplete portion is the circuit diagram. I have opted to publish this post anyway as much of the info is still useful.
Traditionally, to activate a device – like the mosquito zapper I have in the backyard, or the fairy lights on the tree in the yard – I need to physically flick a switch.
I’d like to be able to flick the same switches automatically based on events and/or a schedule. Therefore, I need to build a device which can do this for me.
The number of switches (eg. controlling two different circuits at the same time), what they do (eg. one switches on when the other is off), and the number/type of events (eg. based on time of day and if someone is home at the time) depends on the application.
A RISC (Remote IoT Switch Controller):
- Provides basic switch, push-button, and combination controls for home automation
- Is a simple and cheap piece of hardware based on thr ESP8266 (on a NodeMCU board)
- Includes multiple relays to allow for flexibility
- WiFi connected to centralised controller (Smart Home server)
- Aims to have most of the logic and configuration implemented in the centralised controller
- Standardised initial configuration and ability to reuse configuration for quick deployment of additional RISC devices
The first application for RISC was the fairy lights on the tree in my front yard. The lights not only need to have their power switched, they also have a mode button to change the pattern of the flashing lights.
This means we need to control two relays:
- An on/off switch – To control the power to the lights.
- A momentary push-button – To select the mode of the lights.
Although we will only be using 2 relays for this project, the RISC is a very versatile device and can handle multiple other configurations. So long as your particular project needs up to 4 switches and/or momentary push-buttons then this project will work out for you – with minimal modification.
Step 1 – Source the parts
The two main components needed are the ESP8266 (on a NodeMCU) and the 4 relay module.
Other parts incude wires, barrel connector plug and other miscellaneous parts which you can find pretty much anywhere.
Step 2 – Circuit Board / Wiring
Step 3 – Coding
NodeMCU uses standard Arduino (C++) code out of the box. You can use the Arduino IDE to program and upload to the board.
There are plenty of tutorials online showing you how to do this, so I won’t replicate those efforts here.
Grab the code from here: https://github.com/Aristocles/RISC-Remote-IoT-Switch-Controller-/
Step 2 – Build circuit board
(This portion incomplete. See note at beginning of post)
Step 3 – Add the code to Arduino
Grab the Arduino code from here.
- You would need to enter your WiFi SSID and password along with the MQTT username and password.
- You then need to modify the MQTT Topic names. The code supports two (inTopic & outTopic. inPushTopic & outPushTopic).