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

If you do end up taking it on/getting it to work, I will certainly appreciate a PR on Github

Most definitely!!

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).

1 Like

@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?

@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).

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?

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.

1 Like

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:

@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).

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: .

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

1 Like

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%

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```

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

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\"}")`
1 Like

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?

@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).

Yes. It´s the code from today.

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…

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)