Introduction: Tasmotized NodeMCU 8CH Sonoff Relay
This is a NodeMCU Tasmota-Sonoff Firmware Flashed 8CH Relay Control Project
Sonoff-Tasmota is an alternative firmware for ESP8266 based devices like NodeMCU allowing control over WiFi of Smart Home (ioT) Systems.
My idea was to have a 8CH Relays controlled over WiFi with a Tasmota Firmware Flashed (Tasmotized) NodeMCU board.
I was inspired by:
Fastest way to Flash and Configure ESP8266 Based Sonoff Devices with Tasmota or other firmware - by Vicious Computer on Youtube https://youtu.be/UDnNI5wkNNY
How To Change Firmware on Sonoff Devices for use in Home Automation Projects - by DrZzs on Youtube https://youtu.be/KMiP9Ku71To
Flashing SONOFF Tasmota Firmware on NodeMCU By Sarath341 on Instructables
Step 1: Components and Software Needed
NodeMCU Development Board http://www.nodemcu.com/index_en.html#fr_54745c8bd7...
Sonoff Tasmota Firmware https://github.com/arendst/Sonoff-Tasmota
Termite Software (PC) https://www.compuphase.com/software_termite.htm
Advanced IP Scanner (PC) https://www.advanced-ip-scanner.com/it/
or Finger (Android / IOS APP) https://www.fing.io/
Arduino IDE https://www.arduino.cc/en/Main/Software
8CH Relays Board http://wiki.sunfounder.cc/index.php?title=8_Channe...
Dupont female to female wire https://www.amazon.it/Female-Dupont-Jumper-2-54mm-...
Breadboard https://it.wikipedia.org/wiki/Breadboard
MicroUSB Cable https://www.amazon.com/Anker-PowerLine-Micro-USB-3...
Step 2: Prerequisites
Download the Sonoff Tasmota Firmware from Github https://github.com/arendst/Sonoff-Tasmota
Make sure you have the ESP8266 Library installed on your Arduino IDE.
If you want to know how to install ESP8266 library properly visit this complete blog of Flashing SONOFF Tasmota Firmware on NodeMCU https://www.factoryforward.com/flashing-sonoff-fi...
Step 3: Integration
Tasmotized NodeMCU 8CH Relay can be integrated with various IoT platform:
HomeAssistant https://www.home-assistant.io
Yeti (Domotic App for Android and IOS) https://getyeti.co
MQTT Broker https://www.hivemq.com/blog/mqtt-essentials-part-3...
(Configuration example: https://www.tanzolab.it/openhab_sonoff)
(Example of free available MQTT Cloud Broker: https://customer.cloudmqtt.com/login)
It's also possible to direct access the Tasmotized NodeMCU 8CH Relay via its embedded WEB server (either as AP or with DHCP or static IP address) using a Web Browser.
To access the Tasmotized NodeMCU 8CH Relay from the Internet you need to port forward your router to redirect to the Tasmotized NodeMCU 8CH Relay Web Server (see below the Web page accessible via the Web browser)
Step 4: Web Server of the Tasmotized NodeMCU 8CH Relay
This is the Web server page accessible via your preferred Web browser to direct access to the Tasmotized NodeMCU 8CH Relay and command the 8 relay independently.
From this page it's also possible to configure the Tasmotized device, perform a firmware upgrade and send commands via console to the device.
See also:
Initial Configuration Tasmota Firmware: https://github.com/arendst/Sonoff-Tasmota/wiki/Ini...
Configure Sonoff Tasmota Firmware: https://hobbytronics.pk/config-sonoff-tasmota/
Integrazione SONOFF con MQTT: esempi di programmazione: https://www.tanzolab.it/CM3-HOME_sonoff
Step 5: Configuration of the Tasmota Firmware Flashed Device
By default, Tasmota Firmware fashed device will be in Sonoff Basic.
So you need to change it to ‘Generic’ in ‘Configuration’ menu.
Click ‘Configuration’ and inside that choose ‘Configure Module’.
Step 6: Configuration for ESP8266 NodeMCU to Control 8CH Relay Board
Select the board as Generic and Save.
The device will restart.
This option is for all ESP8266 boards.
Now if you click the configuration, then you can able to see more GPIO options.
Using that you can select the GPIO Functions.
Depending on the GPIO setting the option will appear on the Homepage like DHT, Relay, Switch and Many more.
In this project I used:
GIO0 as Relay8 (pin D3 of the NodeMCU) - Connected to the relay pin 8 of the 8CH Relay Board
GPIO2 as Relay7 (pin D4 of the NodeMCU) - Connected to the relay pin 7 of the 8CH Relay Board
GPIO4 as Relay6 (pin D2 of the NodeMCU) - Connected to the relay pin 6 of the 8CH Relay Board
GPIO5 as Realy5 (pin D1 of the NodeMCU) - Connected to the relay pin 5 of the 8CH Relay Board
GPIO12 as Relay2 (pin D6 of the NodeMCU) - Connected to the relay pin 2 of the 8CH Relay Board
GPIO13 as Relay4 (pin D7 of the NodeMCU) - Connected to the relay pin 4 of the 8CH Relay Board
GPIO14 as Relay3 (pin D5 of the NodeMCU) - Connected to the relay pin 3 of the 8CH Relay Board
GPIO15 as Relay2 (pin D8 of the NodeMCU) - Connected to the relay pin 2 of the 8CH Relay Board
GPIO16 as Relay16 (pin D0 of the NodeMCU) - Connected to the relay pin 1 of the 8CH Relay Board
Step 7: Fritzing Scheme
Fritzing Scheme for the connection between the NodeMCU and the 8CH Relay Board.
Note: VCC is 5V DC
Step 8: How to Flash Tasmota Firmware on Your ESP8266 Based Device
If you want to flash your ESP8266 device with the Arduino IDE use the sonoff firmware source code from GitHub: https://github.com/arendst/Sonoff-Tasmota
Other way to flash your ESP8266 device is by using the sonoff.bin with ESPTool (https://github.com/arendst/Sonoff-Tasmota/wiki/Esptool) by using Python command line or Platformio IDE.
Here you can download both sonoff.bin or sonoff source code firmware https://github.com/arendst/Sonoff-Tasmota/releases
Step 9: Home Assistant Integration
How to integrate your Tasmotized NodeMCU 8CH Relay with Home Assistant
Prerequisites:
1. Setup the embedded Home Assistant MQTT broker (or an alternative MQTT broker)
2. Configure the Tasmotized NodeMCU with MQTT parameters of your broker such as Host (IP address), Port (1883 usually), Client, User and Password of your MQTT broker.
This is my configuration.yaml section to integrate the Tasmotized NodeMCU 8CH Relays (as Lights) in my Home assistant Panel:
#Tasmota_Sonoff_8CH_Relay
light:
- alias: Tasmota_Sonoff_NodeMCU_8CH
platform: mqtt
name: "CH1"
state_topic: "stat/Sonoff_NodeMCU_GS/POWER1"
command_topic: "cmnd/Sonoff_NodeMCU_GS/POWER1"
qos: 0
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
retain: false
- alias: Tasmota_Sonoff_NodeMCU_8CH
platform: mqtt
name: "CH2"
state_topic: "stat/Sonoff_NodeMCU_GS/POWER2"
command_topic: "cmnd/Sonoff_NodeMCU_GS/POWER2"
qos: 0
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
retain: false
- alias: Tasmota_Sonoff_NodeMCU_8CH
platform: mqtt
name: "CH3"
state_topic: "stat/Sonoff_NodeMCU_GS/POWER3"
command_topic: "cmnd/Sonoff_NodeMCU_GS/POWER3"
qos: 0
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
retain: false
- alias: Tasmota_Sonoff_NodeMCU_8CH
platform: mqtt
name: "CH4"
state_topic: "stat/Sonoff_NodeMCU_GS/POWER4"
command_topic: "cmnd/Sonoff_NodeMCU_GS/POWER4"
qos: 0
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
retain: false
- alias: Tasmota_Sonoff_NodeMCU_8CH
platform: mqtt
name: "CH5"
state_topic: "stat/Sonoff_NodeMCU_GS/POWER5"
command_topic: "cmnd/Sonoff_NodeMCU_GS/POWER5"
qos: 0
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
retain: false
- alias: Tasmota_Sonoff_NodeMCU_8CH
platform: mqtt
name: "CH6"
state_topic: "stat/Sonoff_NodeMCU_GS/POWER6"
command_topic: "cmnd/Sonoff_NodeMCU_GS/POWER6"
qos: 0
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
retain: false
- alias: Tasmota_Sonoff_NodeMCU_8CH
platform: mqtt
name: "CH7"
state_topic: "stat/Sonoff_NodeMCU_GS/POWER7"
command_topic: "cmnd/Sonoff_NodeMCU_GS/POWER7"
qos: 0
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
retain: false
- alias: Tasmota_Sonoff_NodeMCU_8CH
platform: mqtt
name: "CH8"
state_topic: "stat/Sonoff_NodeMCU_GS/POWER8"
command_topic: "cmnd/Sonoff_NodeMCU_GS/POWER8"
qos: 0
payload_on: "ON"
payload_off: "OFF"
payload_available: "Online"
payload_not_available: "Offline"
retain: false
Step 10: References
Sonoff-Tasmota Firmware Wiki: https://github.com/arendst/Sonoff-Tasmota/wiki
Sonoff-Tasmota Firmware: https://github.com/arendst/Sonoff-Tasmota
Flashing SONOFF Firmware on NodeMCU: https://www.factoryforward.com/flashing-sonoff-fi...
Step 11: Visit My Blog and Youtube Channel

Participated in the
First Time Author
20 Comments
Question 2 years ago
a nice project!
it can run with ewelink?
thank you
2 years ago
I am sorry, but this isn't going to work as described.. Don't use GPIO15 / D8 to drive something with a pull up resistor like those relay boards. This pulls up D8 high during startup and the ESP won't boot.
Question 2 years ago
Hi, thanks for the great tutorial! 2 questions:
1) Why do you use Relay 2 twice (GPIO 12 / D6 and GPIO 15/ D8)?
2) My Generic (18) also has the A0 ADC0 pin. Can I just ignore it and set it to 'none'?
Thanks!
Answer 2 years ago
Hi, the sceenshot I posted is wrong, you are right, it shows 2 GPIOs assigment for Relay 2. If you look at the wiring diagram D7 is not connected because Realy 2 is assigned to GPIO 15 / D8 and Relay 4 is assigned to GPIO 12/ D6 (not to D7). I will fix the images. "2) My Generic (18) also has the A0 ADC0 pin. Can I just ignore it and set it to 'none'?" I think yes
3 years ago
Thanks for the great work, but i think that relay module works opposite right, if ON its led is OFF, but can change from the the yaml file right.
Reply 3 years ago
Yes, you can fit your need from YAML or from the Tasmota Configuration
4 years ago
My NodeMCU is not booting with a pin connected to D7. It would boot fine with it disconnected and after bootup I can connect it in to have all 8 relays switch on and off without any problems. For now I am running without Relay 2.
Any advice?
Reply 3 years ago
I can get all working
Reply 3 years ago
I use a delayed relay to power on the relay board AFTER 2 sec that the NodeMCU bootup
Reply 3 years ago
I solved this issue by power on the tasmota and THEN after 2 second connect the 5V to the relay board (you can use a delay cicuit to connect the 5V to the relay board)
Reply 3 years ago
same thing happend with me , but i was using a 4ch relay , i had D5,D6,D7,D8 as relay outputs while using D0 and D1 for temperature sensors
Question 4 years ago on Step 11
Hello,
I followed what described above, using a D1 mini and two relays attached on D2 and D4; when I try to switch them on, nothing happen. I tried to use " i " , in tasmota web interface option, for the relays but its the same. The relays I used are the same in photo above and they are working when I try to give them a signal manually.
Any suggestion?
Thanks to everybody
Answer 3 years ago
Have you properly "tasmotized" the NideMCU? Have you configured from the web tasmota interface the GPIO -> NodeMCU pins?
3 years ago
Interesting that the 5V relay board can cope with the 3.3V output from the node MCU.
3 years ago
Easiest way to do is use software rasmotized 5 mins and it's all done automatically. I don't know how to configure same with Google home.
3 years ago
You have relay 2 wired twice in your description, but otherwise awesome.
I plan to use ESPHome for easier HA integration, though.
Question 3 years ago
Great Project Idea!
I'm looking to do a similar thing, but with an option to manually control each relay (like a toggle button for every relay, that the NodeMCU can monitor also).
That way - it can be a great base for a smart home - upgrading all the lights and switches to be smart and connected.
The problem is that the NodeMCU doesn't have enough GPIOs for inputs AND outputs.
So it will have to use a kind of input/output board to 'multiplex' 8 inputs and outputs into NodeMCU AND still being compatible with Tasmota logic.
Any help will be appreciated.
Answer 3 years ago
Hi,
Yes, multiplexing is the solution.
Now I want to address the known issue of "gost switch" of the tasmotized NodeMCU.
Despite I followed various solution described in several post, "gost switch" remain
Reply 3 years ago
Thanks for your reply.
Just to make sure I understand - Ghost Switching is an issue only with touch buttons. Right.
And back to the multiplexing idea:
Found this little GPIO extender, based on PCF8574 chip:
https://www.aliexpress.com/item/32224660654.html
Without Tasmota, it seems to me simple just to wire it to 8 toggle switches around the house, read their status in the main loop (or use an Interrupt for it), and control the realys according to it.
But with Tasmota - How can you tell it to use the extended GPIOs as additional inputs?
Many thanks for that!
Question 4 years ago on Step 9
Hello,
I followed what described above, using a D1 mini and two relays attached on D2 and D4; when I try to switch them on, nothing happen. I tried to use " i " , in tasmota web interface option, for the relays but its the same. The relays I used are the same in photo above and they are working when I try to give them a signal manually.
Any suggestion?
Thanks to everybody