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

mqtt
nodemcu
ledstrip
Tags: #<Tag:0x00007f87709f31f8> #<Tag:0x00007f87709f30b8> #<Tag:0x00007f87709f2f50>

(B K) #61

Updated first post with some modifications I’ve made to my configuration. I’ve simplified the rules to be more generic (instead of requiring a set of Color/Intensity/Speed rules for each strip, the three rules act on every strip by using the new “Member of” trigger clause. Also, changed Setpoint to Slider for Speed and Intensity (and updated the rules to suit).


(John Chiasson) #62

@bartus, I’ve successfully used your code with RGBW SK6812 strips, when pulling in the https://github.com/coryking/FastLED fork of FastLED. PlatformIO makes including a github library easy and it helps with OTA as well. I did have a little trouble with mqtt (I tried the new embedded broker), but eventually using mosquitto did the trick. Thanks for a great library.

I did notice there are about 50 effects in the code, but only 20 in your LEDStripEffectJSON.map. Do you have an updated map and items file to share?


(B K) #63

@JohnChiasson - thanks for the heads up - I’ve updated the sitemap and map definition in the original post to show the additional effects (Dr Zzz’s as well as some of my own new ones).


(Zskadar) #64

Hi, it’s a really impressive led project, I’ve made it successfully as a real beginner. A few days ago openhab released version 2.4 with a totally new MQTT binding. It seems it’s totally changed, the v1.x syntax is abolutely unusable. I’ve found a good starting point for the migration:[Using Sonoff Power Switches with Tasmota firmware and openHAB2 MQTT2 binding](http://Sonoff with MQTT v2) , but I stucked on the basic items. A simple switch or state item seems easy, but the items what use map transformations, and json based output commands, seems harder… Is somebody tried already to migrate this briliant project to the new MQTT version? As I’ve read, the transormation parameter works only on inbound mqtt messages, but I have to send commands as json. On a simple led_power item I could use the (on={state: “ON”}, off={state: “OFF”}) syntax, but what do I have to use for mapped items, led effect for example?


(David Graeff) #65

Actually everybody would benefit if the author could change his MQTT topics to follow the Homie convention. Auto discovery would be possible then.

This is coming the next days for OH 2.5 snapshots.


(Zskadar) #66

Thanks David, I’ll polling the release notes. May it could be a solution if I move the transformations to the rules instead of the items. It’s a custom project with a custom arduino code, I’m not a programmer, unfortunately I definitely won’t upgrade the code to follow the homie convention :slight_smile:


(B K) #67

@David_Graeff - definitely thought about converting to the Homie convention - I’ll work on it

@zskadar - The lack of outbound MQTT transforms is what kept me from updating my personal setup to MQTTv2 for now - at least until the first milestone build for OH 2.5 where @David_Graeff implements them. That said - you should be able to install MQTTv1 and have them running side-by-side still (and keep the original sitemap/item configuration).


(Zskadar) #68

Thanks @bartus, I’m using both MQTTs side-by-side right now, I’m just trying to catch up this new solution as an enthusiastic rookie :slight_smile: .


(Zskadar) #69

It seems it works, not the final and full solution, but I succesfully moved the necessary transformations into the rules.
thing configuration:

{
    Thing mqtt:topic:t-hLED "Hifi LED" @ "MQTT-2" {
    Channels:
        Type string : hLED "Hifi24 LED" [ stateTopic="hifi_led", commandTopic="hifi_led/set"]
        Type switch : hLED_Power "Hifi24 LED Power" [ stateTopic="hifi_led", commandTopic="hifi_led/set", transformationPattern="JSONPATH:$.state", on="{state: 'ON'}", off="{state: 'OFF'}"]
        Type string : hLED_FX "Hifi24 LED FX" [ stateTopic="hifi_led", commandTopic="hifi_led/set", transformationPattern="JSONPATH:$.effect"]
    }

Item configuration:

Switch hLED_Power "Hifi24_LED Power" {channel="mqtt:topic:t-hLED:hLED_Power"}
String hLED_FX "Hifi24_LED FX" {channel="mqtt:topic:t-hLED:hLED_FX"}
String hLED "Hifi24_LED [%s]" {channel="mqtt:topic:t-hLED:hLED"}

Rule:

rule "hLED MQTT json effect rule"
    when Item hLED_FX received command
    then 
    val hledFX=transform("MAP","LEDStripEffectJSON_2.map", hLED_FX.state.toString)
    hLED.sendCommand(hledFX)
    logInfo("Test", "Led FX command executed: " + hledFX)
end

The sitemap uses the original “selection” type as before for the FX item. I know it’s just a hack, I hope I will understand the new model


(Simon Thorsted) #70

How to send a mqtt message to the mcu whit this build on to follow another switch in openhab2 2.4
, I have another device whit tasmota " Generic Module " whit a motion sensor i wood like to sent to the led
board to turn on ,it runs rules whit timer on the tasmota device ,so it can publish an mqtt messange but
i cant figuor out the syntax to follow it ? thanks

PS : I WOOD LIKE IT TO TURN ON WHITE PLEASE

publish cmnd/home/FASTLED/ POWER %value%


(Zskadar) #71

You could use the mqtt action in your rule file:

rule "Publish all"
when 
      Member of myGroupOfItems changed
then
   val actions = getActions("mqtt","mqtt:broker:myUnsecureBroker")
   actions.publishMQTT("allItems/"+triggeringItem.name,triggeringItem.state)
end```

(Simon Thorsted) #72

Do you know how to send the all white “sollid” to LED via mqtt


(Zskadar) #73

If you use this code, the all white solid command is the following:

sendCommand(YOUR_LED_STRIP_ITEM, "{\"state\": \"ON\",\"color\":{\"r\":255,\"g\":255,\"b\":255},\"brightness\":255,\"effect\":\"solid\"}")

Or, with mqtt2.x you could use the previously mentioned mqtt action from the rule directly:

    val actions = getActions("mqtt","mqtt:broker:YOUR_BROKER_NAME")
   `actions.publishMQTT("YOUR_LED_SET_TOPIC", "{\"state\": \"ON\",\"color\":{\"r\":255,\"g\":255,\"b\":255},\"brightness\":255,\"effect\":\"solid\"}")`

(Daniel) #74

Hi. This is e very nice project.

I used the code from the OP and it works for my first strip.

But one problem: the brightness for each color only set to 100.

Is there a chance tu set it to the full range of 255 to each color?


(B K) #75

@Daniel3 - are you sure you used the latest version from the Github and the rules I posted in post #1? I have updated these a few times since the original post, including some fixes to the rules, to use Sliders instead of Setpoints for the Speed/Intensity items (but there may have been some changes to the Color items too over time).


(Daniel) #76

Yes. It´s the code from today.


(B K) #77

Can you post what the rule is actually sending to the Logs? It’s strange that I don’t have the same problem with my LED strips…


(Dave Kneisz) #78

The value of HSBType.red (also green and blue) contain the percentage of the color. If you want the value you have to multiply it by 2.55. So you have to change the rule to:

var ColorHSB = LEDStrip_Test_Color.state as HSBType
val red = (ColorHSB.red * 2.55).intValue
val green = (ColorHSB.green * 2.55).intValue
val blue = (ColorHSB.blue * 2.55).intValue
LEDStrip_Test.sendCommand("{\"color\": {" + 
	"\"r\": " + red + "," +
	"\"g\": " + green + "," +
	"\"b\": " + blue + "}}")

See: Example: Convert Color Item Values To RGB (With Explanation)


(Simon Thorsted) #79

can anyone implement the ” * 255 ” in the bk hobby rule please


(Dave Kneisz) #80

Just copy the code from my example and replace it in the rule. This is what you get:

rule "LED Strip Group 1 (Kitchen) JSON Color Single Strip"
when Member of gLEDStrip_Kitchen_Color received update
then 
 	val source = triggeringItem.name.split("_Color").get(0)
	val item = gLEDStrip_Kitchen.members.findFirst[ l | l.name == source ] as StringItem
	var ColorHSB = triggeringItem.state as HSBType
	val red = (ColorHSB.red * 2.55).intValue
	val green = (ColorHSB.green * 2.55).intValue
	val blue = (ColorHSB.blue * 2.55).intValue
	item.sendCommand("{\"color\": {" + 
		"\"r\": " + red + "," +
		"\"g\": " + green + "," +
		"\"b\": " + blue + "}}")
end