Control multiple relays with Nodemcu and TASMOTA

Hello friends,

I was able to flash TASMOTA on my NodeMCU and got it to switch on / off, 1 relay using both the TASMOTA UI and HA. Now, my Nodemcu is connected to a 4 channel relay. I assigned separate pins and could get those worked using the TASMOTA UI.

For the single relay, I wrote the following in configuration.yaml:

# switch
switch:
  - platform: mqtt
    name: "Sonoff power"
    state_topic: "stat/sonoff/POWER"
    command_topic: "cmnd/sonoff/POWER"
    availability_topic: "tele/sonoff/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

This worked well and comes up in my Home assistant as the screenshot below:

Now, I want 3 more switches to control 3 more relays. What should I be writing in the configuration.yaml?

See https://www.home-assistant.io/docs/configuration/devices/

Checked it. Not sure how to refer the relays in HA, as. Must say, I am quite the noob.

You need to figure out what the MQTT message that Tasmota requires to control each relay. I assume since (I assume…) your first relay is being successfully controlled by HA that the topics in your code are correct.

I believe there should be 3 other topics to publish to and subscribe to in order to control the 3 other relays and then retrieve their states.

So basically you will create 3 more switches just as you have above with those different command and state topics.

2 Likes

Yes, I figured where I was going wrong. Following is how my mqtt is now setup

switch:
  - platform: mqtt
    name: "Den LED"
    state_topic: "stat/sonoff/POWER1"
    command_topic: "cmnd/sonoff/POWER1"
    availability_topic: "tele/sonoff/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

  - platform: mqtt
    name: "Den Fan"
    state_topic: "stat/sonoff/POWER2"
    command_topic: "cmnd/sonoff/POWER2"
    availability_topic: "tele/sonoff/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

Hello, a question: when I sept in tasmota: Generic module to create node mcu with 4 relays they work according to each other. When I turn on one of them, the other goes off. For example: if I turn on the relay 1 while the number 3 is on, the latter goes out as soon as the relay 1 goes ON.
Is there any command to give in the console? Thank you

SetOption14 1

Hi, I installed tasmota generic module with 4 relays and 7 buttons. I set the switchtopic and the various switchmodes. When the mqtt server is turned on it works fine. When mqtt server is turned off, tasmota generic module behaves in another way it changes all my switches.

Thanks for posting your solution.
I copied and paste’ed your configuration above and the altered to suit my setup.
I was having a similar problem and found this and with a little tweeking I have mine working perfect!
Thanks