Tasmotized NodeMCU 8CH Sonoff Relay

30,938

29

18

Introduction: Tasmotized NodeMCU 8CH Sonoff Relay

About: Electronic, Arduino, Raspberry, Photography, Model Train Entusiat

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

https://www.instructables.com/id/Flashing-SONOFF-T...

Step 1: Components and Software Needed

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

Step 11: Visit My Blog and Youtube Channel

First Time Author

Participated in the
First Time Author

Be the First to Share

    Recommendations

    • The 1000th Contest

      The 1000th Contest
    • Battery Powered Contest

      Battery Powered Contest
    • Hand Tools Only Challenge

      Hand Tools Only Challenge

    18 Discussions

    0
    fsoave
    fsoave

    Question 4 months 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!

    0
    radiowinr
    radiowinr

    Answer 4 months 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

    0
    hnaeem07
    hnaeem07

    4 months 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.

    0
    radiowinr
    radiowinr

    Reply 4 months ago

    Yes, you can fit your need from YAML or from the Tasmota Configuration

    1
    Skillet_ZA
    Skillet_ZA

    1 year 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?

    0
    hnaeem07
    hnaeem07

    Reply 4 months ago

    I can get all working

    0
    radiowinr
    radiowinr

    Reply 4 months ago

    I use a delayed relay to power on the relay board AFTER 2 sec that the NodeMCU bootup

    0
    radiowinr
    radiowinr

    Reply 1 year 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)

    0
    Faizi
    Faizi

    Reply 1 year 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

    0
    Leonida61
    Leonida61

    Question 1 year 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

    0
    radiowinr
    radiowinr

    Answer 4 months ago

    Have you properly "tasmotized" the NideMCU? Have you configured from the web tasmota interface the GPIO -> NodeMCU pins?

    0
    thamesmud
    thamesmud

    5 months ago

    Interesting that the 5V relay board can cope with the 3.3V output from the node MCU.

    0
    ajaygupta1974
    ajaygupta1974

    6 months 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.

    0
    kosh42efg
    kosh42efg

    10 months ago

    You have relay 2 wired twice in your description, but otherwise awesome.

    I plan to use ESPHome for easier HA integration, though.

    0
    OfferLa
    OfferLa

    Question 12 months 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.

    0
    radiowinr
    radiowinr

    Answer 12 months 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

    0
    OfferLa
    OfferLa

    Reply 11 months 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!

    0
    Leonida61
    Leonida61

    Question 1 year 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