Jump to: navigation, search

A MQTT controlled device that reads outdoors and indoors temperature sensors and give the user control over 8 relays, including three that have an RGB LED Stripe under the front window.


  • NodeMCU
  • 5V 8 Channel Relay Board with Optocouplers
  • ~3m RGB LED Strip
  • Two DS18B20 Temperature Sensors. Soldered the cables together plus 4.7kΩ resistor between data and VCC on the cable.
  • Two Power Supplies -- 12V 2A, 5V 1A. Separate for Isolation.
  • Router Case -- From the Junk Bench
  • Wiring -- 10 Pin "Dupont" Male to Male Flat Cable from Relay Board to NodeMCU.



  • Sonoff-Tasmota
  • Mosquito MQTT server -- Default Settings (Allow Anonymous)


Atom with PlatformIO.


Disabled everything that is not used by this installation, preconfigured WiFi and MQTT broker address. leet-tasmota-user_config.h


NodeMCU in Tasmota is the "WeMos D1 mini" module

mosquitto_pub -h -m '18' -t cmnd/example/module and /example/ are fake placeholders replace with real values to actually use any of this.

The relay board expects the optocouplers to be driven low, so we use the inverted relay module. Also the NodeMCU "D" Pins and the ESP GPIO are not matching. I ordered relay modules so that they are aligned with the flat cable.

mosquitto_pub -h -m '25' -t cmnd/example/gpio16
mosquitto_pub -h -m '26' -t cmnd/example/gpio5
mosquitto_pub -h -m '27' -t cmnd/example/gpio4
mosquitto_pub -h -m '28' -t cmnd/example/gpio0
mosquitto_pub -h -m '29' -t cmnd/example/gpio2
mosquitto_pub -h -m '30' -t cmnd/example/gpio14
mosquitto_pub -h -m '31' -t cmnd/example/gpio12
mosquitto_pub -h -m '32' -t cmnd/example/gpio13

For the DS18B20 "bus" I tried gpio15 but NodeMCU wouldn't boot with DS18B20 attached, so I moved it to gpio1 which is normally Serial TX, but seems to work fine, even when upgrading firmware over usb with the sensores attached.

mosquitto_pub -h -m '4' -t cmnd/example/gpio1



One operation is done automatically by a script. When it is dark outside it starts randomly toggle the relays in random intervals.


start=`date +%s`

while true ; do
    if [ `date +%s` -gt  $end ]; then

    mosquitto_pub -h -m 'toggle' -t cmnd/example/POWER$(( ( RANDOM % 3 ) + 1 ))
    sleep $(( ( RANDOM % 100 ) + 1 ))

mosquitto_pub -h -m 'off' -t cmnd/example/POWER1
mosquitto_pub -h -m 'off' -t cmnd/example/POWER2
mosquitto_pub -h -m 'off' -t cmnd/example/POWER3

exit 0

This script is ran by cron at sunset and exits at sunrise (~9.5h hard coded values right now)

38 19 * * * /home/user/ 34260


The user can manually change the state of the relays.

Turn off the light:

mosquitto_pub -h -m 'off' -t cmnd/example/POWER1

Turn on the light:

mosquitto_pub -h -m 'on' -t cmnd/example/POWER1

Toggle the state of the light:

mosquitto_pub -h -m 'toggle' -t cmnd/example/POWER1

POWER1 Coresonds to the first relay, in the current installation the one connected at D0/GPIO16 and it controls the Red LEDs. For Green change to POWER2 and for Blue to POWER3.


The Device periodically sends information about its state including the readings of the temperature sensors.

From the terminal you can subscribe to receive those messages periodically with (and leave it running):

  • For the temperature sensors:
    mosquitto_sub -v -h -t 'tele/example/SENSOR'
  • For the power states:
    mosquitto_sub -v -h -t 'tele/example/STATE'