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

mqtt
nodemcu
ledstrip
Tags: #<Tag:0x00007f6cf05f8610> #<Tag:0x00007f6cf05f82a0> #<Tag:0x00007f6cf05efe20>

(B K) #1

Hi all! I’ve created some quick how-to videos (https://www.youtube.com/playlist?list=PLH-d6dcsARGNHlRyqTrwyiWJLNb1YpbPS) to show the build and configuration of my homemade NodeMCU LED Strip controller (https://www.thingiverse.com/thing:2690563), which I use for kitchen under-cabinet lighting and holiday lights. The complete project is written up on the Thingiverse site, but I wanted to post the openHAB specific configuration sample files here for easy linking.

The following items/sitemap and rules entries comprise a single strip and a “group” of strips (if more than one strip is defined and they’re required to be controlled as a group).

ledstrip.items:

    String LEDStrip_FF_Kitchen_Cabinet_1 "Kitchen Cabinet 1 String" {mqtt=">[broker:home/FF_Kitchen_Cabinet_1/set:state:*:default]"}
    Switch LEDStrip_FF_Kitchen_Cabinet_1_Power "Kitchen Cabinet 1 Power" {mqtt=">[broker:home/FF_Kitchen_Cabinet_1/set:command:*:MAP(LEDStripEffectJSON.map)]"}
    Number LEDStrip_FF_Kitchen_Cabinet_1_FX "Kitchen Cabinet 1 Fx" {mqtt=">[broker:home/FF_Kitchen_Cabinet_1/set:command:*:MAP(LEDStripEffectJSON.map)]"}
    Color LEDStrip_FF_Kitchen_Cabinet_1_Color "Kitchen Cabinet 1 Color"	<rgb>	
    Number LEDStrip_FF_Kitchen_Cabinet_1_Speed "Kitchen Cabinet 1 Speed [%.0f]"		
    Number LEDStrip_FF_Kitchen_Cabinet_1_Intensity "Kitchen Cabinet 1 Intensity [%d]" 

    String LEDStrip_Group_1 "Group 1 String" {mqtt=">[broker:home/Group_1/set:state:*:default]"}
    Switch LEDStrip_Group_1_Power "Group 1 Power" {mqtt=">[broker:home/Group_1/set:command:*:MAP(LEDStripEffectJSON.map)]"}
    Number LEDStrip_Group_1_FX "Group 1 Fx" {mqtt=">[broker:home/Group_1/set:command:*:MAP(LEDStripEffectJSON.map)]"}
    Color LEDStrip_Group_1_Color "Group 1 Color"	<rgb>	
    Number LEDStrip_Group_1_Speed "Group 1 Speed [%.0f]"		
    Number LEDStrip_Group_1_Intensity "Group 1 Intensity [%d]"

.sitemap:

				Switch item=LEDStrip_FF_Kitchen_Cabinet_1_Power
				Selection item=LEDStrip_FF_Kitchen_Cabinet_1_FX mappings=[1="BPM",2="Noise",3="Fire",4="Rainbow",5="Twinkle",6="Glitter",7="Solid",8="Sinelon",9="Juggle",10="Confetti",11="Dots",12="Lightning",13="Candy Cane",14="Cyclon Rainbow",15="Ripple",16="Christmas Alternate",17="Police All",18="Police One",19="Random Stars",20="Sine Hue"] 
				Colorpicker item=LEDStrip_FF_Kitchen_Cabinet_1_Color
				Setpoint item=LEDStrip_FF_Kitchen_Cabinet_1_Speed minValue=5 maxValue=240 step=5
				Setpoint item=LEDStrip_FF_Kitchen_Cabinet_1_Intensity minValue=0 maxValue=255 step=16 
                Switch item=LEDStrip_Group_1_Power
				Selection item=LEDStrip_Group_1_FX mappings=[1="BPM",2="Noise",3="Fire",4="Rainbow",5="Twinkle",6="Glitter",7="Solid",8="Sinelon",9="Juggle",10="Confetti",11="Dots",12="Lightning",13="Candy Cane",14="Cyclon Rainbow",15="Ripple",16="Christmas Alternate",17="Police All",18="Police One",19="Random Stars",20="Sine Hue"] 
				Colorpicker item=LEDStrip_Group_1_Color
				Setpoint item=LEDStrip_Group_1_Speed minValue=5 maxValue=240 step=5
				Setpoint item=LEDStrip_Group_1_Intensity minValue=0 maxValue=255 step=16

.rules:

    rule "LED Strip Kitchen Cabinet 1 JSON Color"
    when Item LEDStrip_FF_Kitchen_Cabinet_1_Color received update
    then LEDStrip_FF_Kitchen_Cabinet_1.sendCommand("{\"color\": {" + 
    		"\"r\": " + (LEDStrip_FF_Kitchen_Cabinet_1_Color.state as HSBType).red + "," +
    		"\"g\": " + (LEDStrip_FF_Kitchen_Cabinet_1_Color.state as HSBType).green + "," +
    		"\"b\": " + (LEDStrip_FF_Kitchen_Cabinet_1_Color.state as HSBType).blue + "}}") end

    rule "LED Strip Kitchen Cabinet 1 JSON Speed"
    when Item LEDStrip_FF_Kitchen_Cabinet_1_Speed received update
    then LEDStrip_FF_Kitchen_Cabinet_1.sendCommand("{\"transition\": \"" + LEDStrip_FF_Kitchen_Cabinet_1_Speed.state + "\"}") end

    rule "LED Strip Kitchen Cabinet 1 JSON Intensity"
    when Item LEDStrip_FF_Kitchen_Cabinet_1_Intensity received update
    then LEDStrip_FF_Kitchen_Cabinet_1.sendCommand("{\"brightness\":" + LEDStrip_FF_Kitchen_Cabinet_1_Intensity.state + "}") end

    rule "LED Strip Group 1 JSON Color"
    when Item LEDStrip_Group_1_Color received update
    then LEDStrip_Group_1.sendCommand("{\"color\": {" + 
    		"\"r\": " + (LEDStrip_Group_1_Color.state as HSBType).red + "," +
    		"\"g\": " + (LEDStrip_Group_1_Color.state as HSBType).green + "," +
    		"\"b\": " + (LEDStrip_Group_1_Color.state as HSBType).blue + "}}") end

    rule "LED Strip Group 1 JSON Speed"
    when Item LEDStrip_Group_1_Speed received update
    then LEDStrip_Group_1.sendCommand("{\"transition\": \"" + LEDStrip_Group_1_Speed.state + "\"}") end

    rule "LED Strip Group 1 JSON Intensity"
    when Item LEDStrip_Group_1_Intensity received update
    then LEDStrip_Group_1.sendCommand("{\"brightness\":" + LEDStrip_Group_1_Intensity.state + "}") end

LEDStripEffectJSON.map:

1={"effect":"bpm"}
2={"effect":"noise"}
3={"effect":"fire"}
4={"effect":"rainbow"}
5={"effect":"twinkle"}
6={"effect":"glitter"}
7={"effect":"solid"}
8={"effect":"sinelon"}
9={"effect":"juggle"}
10={"effect":"confetti"}
11={"effect":"dots"}
12={"effect":"lightning"}
13={"effect":"candy cane"}
14={"effect":"cyclon rainbow"}
15={"effect":"ripple"}
16={"effect":"christmas alternate"}
17={"effect":"police all"}
18={"effect":"police one"}
19={"effect":"random stars"}
20={"effect":"sine hue"}
ON={"state":"ON"}
OFF={"state":"OFF"}

-B.K.


How to build a WS2812B LED strip with ESP8266 NodeMCU?
RGB Strip Arduino MQTT control
RGB MQTT Help to create items and sitemap
(Rich Koshak) #2

If you use specific code fences you will get some syntax highlighting which will make the rules a little easier to read. How to use code fences


(B K) #3

Ugh, I know you’re right, but I did the sitemap file using code fences last night, and I just hate how it splits every line into a separate fence if you select them all and click the formatting button (and you have to remove every single one to make it look right). It does look much better, so I went and re-edited just now.

-B.K.


(Rich Koshak) #4
```php
Paste in sitemap code
```

If you put in the code fences first and paste you sitemap between the fences it doesn’t matter how many white spaces there are, it will keep them all together. I never use the buttons.


(B K) #5

Brilliant!! Of course there’s a better way once I finish doing it the hard way :smiley: Thanks for that, I’ll definitely remember it next time!


(Josar) #6

@rlkoshak can this not be fixed somehow? I see a lot of people have bad post formatting as the engine does split up marked code into multiple lines.


(Rich Koshak) #7

I have no idea. I suppose someone could file an issue over on Discourse, the underlying software that drives the forum. We don’t have that much control over those sorts of behaviors ourselves.


(Josar) #8

HMMM @ThomDietrich did you not wrote the plugin for the Buttons? I would Guess.

And a deeper search shows a FIX: Apply surround should not be applied individually to each line. for discourse/discourse-spoiler-alert

Maybe this could also be fixed? As it seems its just a single line!