NodeMCU MQTT LED Strip Controller Build & Config How-To Videos

I guess I never noticed how unsaturated the solid colors were :smiley: (I do mostly use these strips for effects, though).

Thanks @Daniel3 for finding the bug, and @Dave_K for fixing it! :+1:

Hello

Is there a way i can change the start up brightness to 100% white ,becurse
im building my kitchen light to led and i wood like it just to turn on when it is powered on so it the mqtt is not working i will get som light ? or will the D1 mini not start up if is not connecet to mqtt ?

Simon

Hi,

You could use a simple switch on your D1, but in this case you have to modify your code, when you turn it on, send full white values into the main loop. IMO it’s a hard way.
Much easier, if you use and trust in MQTT itself, and use a smart button for OH. I use Xiaomi zigbee smart switch taped to the kitchen furniture, when I push, a rule triggers, and OH sends a full white ON command to the ledstrip. It’s simple and works well. This button knows the simple and double click action, so if you want to turn off the ledstrip, you can use the double click action for that. More funny feature, if you use Xiaomi’s magic cube for this :slight_smile:

1 Like

First, thanks BK for all of your videos and tutorials, I think if it weren’t for that I would have abandoned openhab.

Down to business, I copy pasted the postings and loaded an arduino with code. It connects to wifi and MQTT.

However, openhab, when I press the buttons in the UI put a message in the log

2019-05-07 15:58:07.986 [vent.ItemStateChangedEvent] - LEDStrip_FF_Kitchen_Cabinet_1_Speed changed from 25 to 30

2019-05-07 15:58:08.008 [ome.event.ItemCommandEvent] - Item ‘LEDStrip_FF_Kitchen_Cabinet_1’ received command {“transition”: “30”}

2019-05-07 15:58:08.016 [vent.ItemStateChangedEvent] - LEDStrip_FF_Kitchen_Cabinet_1 changed from {“transition”: “25”} to {“transition”: “30”}

2019-05-07 15:58:09.355 [ome.event.ItemCommandEvent] - Item ‘LEDStrip_FF_Kitchen_Cabinet_1_FX’ received command 5

But no mqtt message are actually sent.

I know MQTT is working because in the paper ui i setup broker and created a thing, with topic matching the set command of the arduino and Output set to {“state”:“%s”}
When a switch is linked to that item it works (turning on/off)

But I would prefer to use .items file as I don’t mind doing for one item via ui, but there are quite a few.

1 Like

I solved the issue. Just thought I would post in case this happens to other…Was using MQTT Binding for 2.x Installed 1.x binding in addition, set the mqtt.cfg file and it works :slight_smile:

@DarthMops - just saw your original post, but I see you already solved your own problem, excellent! :slight_smile:

@bartus - Thanks as always for your help!

just as a follow up, for me the following patterns don’t work.
26=USA, 21=Christmas,22=St Patty,23=Valentine,24=Turkey, 28=Halloween, 29=Go Lions

I have tested almost all. Just curious if it is just me or if these work for other people?

@DarthMops - as those are the “newer” effects (as of late 2018), I’d just make sure that you’re using the latest .ino file from my repository, and the latest MAP transformation file (copy mine).

hi, does this work on the latest versions of opennhab and MQTT binding? ive been trying for a few days and cant seem to get my MQTT broker to talk to my NodeMCU. nothing shows in the serial minitor after it says its connected to MQTT

edit, so i got this to work by downgrading the MQTT to the legacy version and playing around with the mqtt.cfg file. however im using a neopixel strip with chipset SK6812RGBW and the colours arnt solid when using the colour picker each led is sperate colour as per photo

@byronendleton - This should work with the MQTT v2 binding in openHAB as well - just need to define the MQTT things/channels (I haven’t done so myself yet, still using MQTT v1 for these).

As for your LED strips, the fact you’re using RGBW is the problem - FastLED (the library that supports all the effects within the program) doesn’t support RGBW, only RGB LED strips. That’s why you’re seeing the weird color issues. My goto LED strips have been WS2812 RGB strips, in case you want to try those.

im only new to this and tried with v2 for a long time and couldnt work it out. seems to be working ok with v1 till someone has a proven method it works.

hmm thought that might be the case. is there a work around for it that you know of? ive already for the RGBW strips installed

Hi guys,

here is my implementation with MQTT v2 binding. This is the 40 animations included version, unfortunately I’ve forgot where I found the code itself. If you use an another version of the code, don’t forget replace the mappings on the sitemap and the transformation map file’s contents. As an extra, I’ve configured direct switches for the four base colors (R,G,B,W), and I’ve made a basic logic for the reatining the previous settings if you choose a solid one. I switch on a solid color red light with an astro binding based rule in the night, and turn it off when the sun rises. In this case, the ledstrip switching back to the previous states via the “prev_” prefixed dummy items. Since the OH2.5 snapshot fixed the early MQTT based issues, it works fine without any issue. I’m a rookie yet, so I’m sure you can simplify my rules, but it do what I’ve planned. If somebody wants migrate this project to MQTT v2, it’s an opportunity.

broker.things:

Bridge mqtt:broker:sentinel "MQTT Broker: Mosquitto server"  [ 
	host="localhost",
	port=1883,
	clientid="sentinel_openhab",
	secure="false",
    username="openhabian",
    password="mqtt"
]

mqtt.things:

Thing mqtt:topic:sentinel:t-hLED  "Hifi LED" (mqtt:broker:sentinel) @ "MQTT2" {
    Channels:
        Type string : hLED              "HiFi LED"              [ stateTopic="hifi_led", commandTopic="hifi_led/set" ]
        Type switch : hLEDPower         "HiFi LED Power"        [ stateTopic="hifi_led", commandTopic="hifi_led/set", transformationPattern="JSONPATH:$.state"] 
        Type string : hLEDFX            "HiFi LED FX"           [ stateTopic="hifi_led", commandTopic="hifi_led/set", transformationPattern="JSONPATH:$.effect"]
        Type string : hLEDIntensity     "HiFi LED Intensity"    [ stateTopic="hifi_led", commandTopic="hifi_led/set", transformationPattern="JSONPATH:$.brightness"]
        Type string : hLEDColorred      "HiFi LED color r"      [ stateTopic="hifi_led", commandTopic="hifi_led/set", transformationPattern="JSONPATH:$.color.r"]
        Type string : hLEDColorgreen    "HiFi LED color g"      [ stateTopic="hifi_led", commandTopic="hifi_led/set", transformationPattern="JSONPATH:$.color.g"]
        Type string : hLEDColorblue     "HiFi LED color b"      [ stateTopic="hifi_led", commandTopic="hifi_led/set", transformationPattern="JSONPATH:$.color.b"]
    }

led items:

Group:Switch    HifiColors         "Solid color buttons"

Switch          HifiRed            "Solid Red"       (HifiColors)    [ "Switchable" ]
Switch          HifiBlue           "Solid Blue"      (HifiColors)    [ "Switchable" ]
Switch          HifiWhite          "Solid White"     (HifiColors)    [ "Switchable" ]
Switch          HifiGreen          "Solid Green"     (HifiColors)    [ "Switchable" ]

Switch          hLED_Power         "Ledstrip Power [%s]"                [ "Switchable" ]        {channel="mqtt:topic:sentinel:t-hLED:hLEDPower"}
String          hLED_FX            "Ledstrip FX [MAP(LEDStripEffectJSON_2.map)%s]" 
String          hLED               "Ledstrip overall state [%s]"                                {channel="mqtt:topic:sentinel:t-hLED:hLED"}
Dimmer          hLED_Speed         "Ledstrip Speed" 
Dimmer          hLED_Intensity     "Ledstrip Intensity"
Color           hLED_Color         "Ledstrip Color"     <rgb>           [ "Switchable" ] 
String          hLED_Color_red     "Ledstrip red color [%s]"                                    {channel="mqtt:topic:sentinel:t-hLED:hLEDColorred"}
String          hLED_Color_green   "Ledstrip green color [%s]"                                  {channel="mqtt:topic:sentinel:t-hLED:hLEDColorgreen"}
String          hLED_Color_blue    "Ledstrip blue color [%s]"                                   {channel="mqtt:topic:sentinel:t-hLED:hLEDColorblue"}

Switch          prev_hLED_Power
String          prev_hLED_FX
Dimmer          prev_hLED_Speed
Dimmer          prev_hLED_Intensity
Color           prev_hLED_Color

led sitemap:

sitemap hifi_led label="Ledstrip Control" icon="colorpicker" {
Frame label="Solid color direct buttons" icon="lightbulb" {
Switch item=HifiWhite
    mappings=[OFF="Turn off"]
	labelcolor=[OFF="red",NULL="red",ON="blue"]
	valuecolor=[OFF="red",NULL="red",ON="blue"]
	visibility=[HifiWhite==ON]
	icon="light"

Switch item=HifiWhite
	mappings=[ON="Turn on"]
	labelcolor=[OFF="red",NULL="red",ON="blue"]
	valuecolor=[OFF="red",NULL="red",ON="blue"]
	visibility=[HifiWhite==OFF,HifiWhite=="NULL"]
	icon="light"

Switch item=HifiRed
	mappings=[OFF="Turn off"]
	labelcolor=[OFF="red",NULL="red",ON="blue"]
	valuecolor=[OFF="red",NULL="red",ON="blue"]
	visibility=[HifiRed==ON]
	icon="light"

Switch item=HifiRed
	mappings=[ON="Turn on"]
	labelcolor=[OFF="red",NULL="red",ON="blue"]
	valuecolor=[OFF="red",NULL="red",ON="blue"]
	visibility=[HifiRed==OFF,HifiRed=="NULL"]
	icon="light"

Switch item=HifiBlue
	mappings=[OFF="Turn off"]
	labelcolor=[OFF="red",NULL="red",ON="blue"]
	valuecolor=[OFF="red",NULL="red",ON="blue"]
	visibility=[HifiBlue==ON]
	icon="light"

Switch item=HifiBlue
	mappings=[ON="Turn on"]
	labelcolor=[OFF="red",NULL="red",ON="blue"]
	valuecolor=[OFF="red",NULL="red",ON="blue"]
	visibility=[HifiBlue==OFF,HifiBlue=="NULL"]
	icon="light"

Switch item=HifiGreen
	mappings=[OFF="Turn off"]
	labelcolor=[OFF="red",NULL="red",ON="blue"]
	valuecolor=[OFF="red",NULL="red",ON="blue"]
	visibility=[HifiGreen==ON]
	icon="light"

Switch item=HifiGreen
	mappings=[ON="Turn on"]
	labelcolor=[OFF="red",NULL="red",ON="blue"]
	valuecolor=[OFF="red",NULL="red",ON="blue"]
	visibility=[HifiGreen==OFF,HifiGreen=="NULL"]
	icon="light"
}
Frame label="Animation, color, speed, intensity" icon="smiley" {
Slider item=hLED_Intensity label="Ledstrip intensity [%d %%]" icon="chart"
Switch item=hLED_Power label="Ledstrip Power [%s]"
Selection item=hLED_FX mappings=[1="BPM",2="candy cane",3="animations",4="template",5="blendwave",6="beatwave",7="blur",8="confetti",9="confetti 2",10="confetti pal",11="dotbeat",12="easing",13="every n example",14="fill grad",15="inoise8 mover",16="inoise8 pal",17="noise 16 1",18="noise 16 2",19="noise 16 3",20="one sine pal",21="palette cross fade",22="rainbow march",23="rainbow beat",24="ripple pal",25="sinelon",26="cyclon rainbow",27="dots",28="fire",29="glitter",30="juggle",31="lightning",32="noise",33="police all",34="police one",35="rainbow",36="rainbow with glitter",37="ripple",38="sinelon",39="solid",40="twinkle"] icon="smiley"
Slider item=hLED_Speed label="Ledstrip speed [%d %%]" icon="motion"
Colorpicker item=hLED_Color icon="colorwheel"
Text item=hLED_Color_red icon="colorpicker"
Text item=hLED_Color_green icon="colorpicker"
Text item=hLED_Color_blue icon="colorpicker"
//Text item=hLED label="HLED"
}
}

led rules:

rule "Hifi color  switch"
    when Member of HifiColors received command
        then
        if(receivedCommand == ON){
            prev_hLED_Intensity.postUpdate(hLED_Intensity.state)
            prev_hLED_Speed.postUpdate(hLED_Speed.state)
            prev_hLED_Color.postUpdate(hLED_Color.state)
            prev_hLED_Power.postUpdate(hLED_Power.state)
            prev_hLED_FX.postUpdate(hLED_FX.state)
            
            if (triggeringItem == HifiWhite) {
                    hLED_FX.sendCommand(39)
                    hLED_Speed.sendCommand(60)
                    hLED_Intensity.sendCommand(60)
                    val actions = getActions("mqtt", "mqtt:broker:sentinel")
                    actions.publishMQTT("hifi_led/set", "{\"state\":\"ON\",\"transition\":170,\"color\":{\"r\":255,\"g\":255,\"b\":255}}")
                    hLED_Power.postUpdate(ON)
                    HifiRed.postUpdate(OFF)
                    HifiGreen.postUpdate(OFF)
                    HifiBlue.postUpdate(OFF)
                    logInfo("Test", "Ledstrip White command executed")
                }
            else if(triggeringItem == HifiRed) {
                    hLED_FX.sendCommand(39)
                    hLED_Speed.sendCommand(60)
                    hLED_Intensity.sendCommand(60)
                    val actions = getActions("mqtt", "mqtt:broker:sentinel")
                    actions.publishMQTT("hifi_led/set", "{\"state\":\"ON\",\"transition\":170,\"color\":{\"r\":255,\"g\":0,\"b\":0}}")
                    hLED_Power.postUpdate(ON)
                    HifiWhite.postUpdate(OFF)
                    HifiGreen.postUpdate(OFF)
                    HifiBlue.postUpdate(OFF)
                    logInfo("Test", "Ledstrip Red command executed")
                }
            else if (triggeringItem == HifiBlue) {
                    hLED_FX.sendCommand(39)
                    hLED_Speed.sendCommand(60)
                    hLED_Intensity.sendCommand(60)
                    val actions = getActions("mqtt", "mqtt:broker:sentinel")
                    actions.publishMQTT("hifi_led/set", "{\"state\":\"ON\",\"transition\":170,\"color\":{\"r\":0,\"g\":0,\"b\":255}}")
                    hLED_Power.postUpdate(ON)
                    HifiRed.postUpdate(OFF)
                    HifiGreen.postUpdate(OFF)
                    HifiWhite.postUpdate(OFF)
                    logInfo("Test", "Ledstrip Blue command executed")
                }
            else if (triggeringItem == HifiGreen) {
                    hLED_FX.sendCommand(39)
                    hLED_Speed.sendCommand(60)
                    hLED_Intensity.sendCommand(60)
                    val actions = getActions("mqtt", "mqtt:broker:sentinel")
                    actions.publishMQTT("hifi_led/set", "{\"state\":\"ON\",\"transition\":170,\"color\":{\"r\":0,\"g\":255,\"b\":0}}")
                    hLED_Power.postUpdate(ON)
                    HifiRed.postUpdate(OFF)
                    HifiWhite.postUpdate(OFF)
                    HifiBlue.postUpdate(OFF)
                    logInfo("Test", "Ledstrip Green command executed")
                }
            }
        else {
            val actions = getActions("mqtt", "mqtt:broker:sentinel")
            actions.publishMQTT("hifi_led/set", '{"state" : "OFF"}')
            postUpdate(HifiRed, OFF)
            postUpdate(HifiWhite, OFF)
            postUpdate(HifiBlue, OFF)
            postUpdate(HifiGreen, OFF)
            sendCommand(hLED_Power, prev_hLED_Power.state.toString)
            Thread::sleep(100)
            hLED_Color.sendCommand(prev_hLED_Color.state.toString)
            Thread::sleep(100)
            hLED_FX.sendCommand(prev_hLED_FX.state.toString)
            Thread::sleep(100)
            hLED_Intensity.sendCommand(prev_hLED_Intensity.state as Number)
            Thread::sleep(100)
            hLED_Speed.sendCommand(prev_hLED_Speed.state as Number)
            }
end

rule "LED Strip Hifi JSON Intensity"
    when Item hLED_Intensity received command
    then 
         var intensity = Math::round(((receivedCommand as Number) * 255 / 100.0).intValue)
         val actions = getActions("mqtt", "mqtt:broker:sentinel")
         actions.publishMQTT("hifi_led/set", "{\"brightness\":" + intensity + "}")
         logInfo("Test", "Ledstrip intensity command executed, new value : " + hLED_Intensity.state + "%")

end

rule "hLED Strip JSON Speed"
    when Item hLED_Speed received command
    then 
         var speed = Math::round(((receivedCommand as Number) * 255 / 100.0).intValue)
         val actions = getActions("mqtt", "mqtt:broker:sentinel")
         actions.publishMQTT("hifi_led/set", "{\"transition\":" + speed + "}")
         logInfo("Test", "Ledstrip Speed command executed, new value : " + hLED_Speed.state + "%")
end

rule "hLED MQTT JSON effect rule"
    when Item hLED_FX received command
    then 
        val hledFX=transform("MAP","LEDStripEffectJSON_2.map", receivedCommand.toString)
        val actions = getActions("mqtt", "mqtt:broker:sentinel")
        actions.publishMQTT("hifi_led/set", hledFX)
        logInfo("Test", "Led FX command executed: " + hledFX)
end

rule "hLED MQTT JSON power on off"
    when Item hLED_Power received command
    then 
        if(receivedCommand == ON){
        val actions = getActions("mqtt", "mqtt:broker:sentinel")
        actions.publishMQTT("hifi_led/set", '{"state" : "ON"}')
        }
    else {
        val actions = getActions("mqtt", "mqtt:broker:sentinel")
        actions.publishMQTT("hifi_led/set", '{"state" : "OFF"}')
    } 
end

rule "hLED MQTT JSON Strip Color"
    when 
        Item 
            hLED_Color received command
    then
            val actions = getActions("mqtt", "mqtt:broker:sentinel")
            actions.publishMQTT("hifi_led/set", "{\"color\": {" +
    		"\"r\": " + ((hLED_Color.state as HSBType).red * 2.55).intValue + "," +
    		"\"g\": " + ((hLED_Color.state as HSBType).green * 2.55).intValue + "," +
    		"\"b\": " + ((hLED_Color.state as HSBType).blue * 2.55).intValue + "}}")
            Thread::sleep(100)
            logInfo("Test", "Ledstrip color command executed: Red :" + ((hLED_Color.state as HSBType).red * 2.55).intValue + 
                                                    ", Green: " + ((hLED_Color.state as HSBType).green * 2.55).intValue + 
                                                    ", Blue: " + ((hLED_Color.state as HSBType).blue * 2.55).intValue )
end

LEDStripEffectJSON_2.map:

1={"effect":"bpm"}
2={"effect":"candy cane"}
3={"effect":"animations"}
4={"effect":"template"}
5={"effect":"blendwave"}
6={"effect":"beatwave"}
7={"effect":"blur"}
8={"effect":"confetti"}
9={"effect":"confetti 2"}
10={"effect":"confetti pal"}
11={"effect":"dotbeat"}
12={"effect":"easing"}
13={"effect":"every n example"}
14={"effect":"fill grad"}
15={"effect":"inoise8 mover"}
16={"effect":"inoise8 pal"}
17={"effect":"noise 16 1"}
18={"effect":"noise 16 2"}
19={"effect":"noise 16 3"}
20={"effect":"one sine pal"}
21={"effect":"palette cross fade"}
22={"effect":"rainbow march"}
23={"effect":"rainbow beat"}
24={"effect":"ripple pal"}
25={"effect":"sinelon"}
26={"effect":"cyclon rainbow"}
27={"effect":"dots"}
28={"effect":"fire"}
29={"effect":"glitter"}
30={"effect":"juggle"}
31={"effect":"lightning"}
32={"effect":"noise"}
33={"effect":"police all"}
34={"effect":"police one"}
35={"effect":"rainbow"}
36={"effect":"rainbow with glitter"}
37={"effect":"ripple"}
38={"effect":"sinelon"}
39={"effect":"solid"}
40={"effect":"twinkle"}
ON={"state":"ON"}
OFF={"state":"OFF"}

hifi_led.ino.txt (59.2 KB)

1 Like

what about the ino file and the wire connections to the esp ? There must be one more wire and some changes in the ino file .

Here is my .ino, I use just one pin, as the original project does.
Just fill the wifi and mqtt params, digital pin of your board, and the color order and type of your ledstrip.

hifi_led.ino.txt (59.2 KB)

(I had to rename to .txt because .ino upload isn’t permitted).

1 Like

I’m not an electrician, but I’m afraid it’s not a good idea to send 27 amps over such a thin cable. The better idea is surely to use 3 power supplies and to provide each LED Stripe with individual power. The data line can be permanently connected to the NodeMCU. In addition, a fuse should be installed! The power supplies do not switch off in the event of a short circuit … the stripes then quickly get 250 degrees hot.

Actually, if you notice in my video, I’m sending power in both directions (e.g. a “ring bus” configuration, where the end of the wire comes back around to the power supply), and the LED strip PCB is still carrying some amount of the power through. Also, the 27A is an absolute max (full RGB, bright white), staying way below that for the majority of the time. But, I agree a fuse would be good to have, and ultimately, you’d want to use a thicker wire to leave some “headroom” for temperature derating, lower voltage drop, etc…). Better yet, the best way to run such a large # of LEDs is to use a 12V strip, which will draw fewer amps.

While it would be nice to have a separate power supply for each strip, that wouldn’t be feasible in this setup (strips wrapped around the room’s ceiling) with power supplies hanging off at random intervals on the wall. Besides, you’d need feedback protection diodes if you wanted to power both the start/end of each strip (voltage drop along the run is one of the problems this power injection scheme is supposed to solve).

In the end, even with the 450 LEDs, I never felt the wiring get even warm to the touch, and they’ve been in use for the better part of this year so far.

I tried compiling and uploading for this board. but it seems to fail.

NODEMCU V3 LUA ESP-12E WIFI DEVELOPMENT BOARD

In file included from C:\Users\Bist\Documents\Arduino\libraries\FastLED/FastLED.h:48:0,

             from C:\Users\Bist\Documents\Arduino\nodemcumqtt\nodemcumqtt.ino:8:

C:\Users\Bist\Documents\Arduino\libraries\FastLED/fastpin.h: In instantiation of ‘class FastPin<14u>’:

C:\Users\Bist\Documents\Arduino\libraries\FastLED/platforms/esp/8266/clockless_esp8266.h:21:49: required from ‘class ClocklessController<14, 40, 100, 60, (EOrder)66u, 0, false, 50>’

C:\Users\Bist\Documents\Arduino\libraries\FastLED/chipsets.h:582:7: required from ‘class WS2812Controller800Khz<14u, (EOrder)66u>’

C:\Users\Bist\Documents\Arduino\libraries\FastLED/FastLED.h:105:52: required from ‘class WS2812B<14u, (EOrder)66u>’

C:\Users\Bist\Documents\Arduino\libraries\FastLED/FastLED.h:302:39: required from ‘static CLEDController& CFastLED::addLeds(CRGB*, int, int) [with CHIPSET = WS2812B; unsigned char DATA_PIN = 14u; EOrder RGB_ORDER = (EOrder)66u]’

C:\Users\Bist\Documents\Arduino\nodemcumqtt\nodemcumqtt.ino:203:65: required from here

C:\Users\Bist\Documents\Arduino\libraries\FastLED/fastpin.h:207:2: error: static assertion failed: Invalid pin specified

static_assert(validpin(), “Invalid pin specified”);

^

exit status 1
Error compiling for board NodeMCU 1.0 (ESP-12E Module).

Yepp, I’ve tried and experienced the same. Unfortunately I’ve found only pin D4 for succesfully compiling, but it isn’t recommended. IMHO you should try Wemos D1 mini, it’s far enough for this code and works fine with this pin. With regards of NodeMCU, I could compile it with D4 pin, but I had to downgrade the latest Fastled library to the latest v5 version from v6. I use Arduino IDE 1.8.10.
Here is a link for the ESP8266 pinouts: https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/

you meand arduinojson v6 to v5. Fastled is version 3.3.2

I’m sorry, I missed, yes!

1 Like