The map should work both ways, but the status string doesn’t contain the effect (it’s only sent out), You can pull out brightness/speed from the MQTT message, but need to update the item MQTT path, to access just that value. Try:
Number tvledright_brightness "TV LEDs Right Brightness" {mqtt="<[broker:home/leds/tvright:state:JSONPATH($.brightness)]" }
Since the MQTT status topic is a multi-line set of status items, and we need to pull out only the current brightness, the JSONPATH will pull that out.
That said, I never did this for my items - they seem to update whenever I make a change in my GUI/app. Are you making changes to the items via rules or something? Sending a “postUpdate” at the end of the rule should modify the status item…
Thanks for the reply, having a play around in the items/sitemap files and can get the number to appear as you described, but that also doesn’t update in the GUI, tried 3 separate devices and does the same on each of them - No changes to items or rules except from what is in your examples!
Ah, just the text shows? I think I know what the problem is there, you just need to format it into the item. So, for example:
Number tvledright_brightness "TV LEDs Right Brightness [%d]" {mqtt="<[broker:home/leds/tvright:state:JSONPATH($.brightness)]" }
That should format it as a number, and adjust the item state with it.
If that doesn’t work, I’d say the next thing to do would be to write a handler rule, based on the MQTT input string updating, and explicitly set the state for each item as you parse it out of the JSON string…
No, I didn’t. Easiest way was to just use an ESP8266 instead. There probably is a way to make it work with an ESP32, but I don’t really see the point for me. The 8266 is cheaper, and I don’t need the extra “horse power” and bluetooth for my LED controller.
Wondering if anyone would be able to point me in the right direction please? I have made the WS2812 LED strip with a NodeMCU. Everything loaded on fine. Connects to WIFi and MQTT server correctly. I added the items, sitemap, rules and transform additions to my openhab (latest version). The issue is that when trying to control the LED strip via openhab, all functions do not work. Observations are as follows.
-MQTT fx shows that the messages are being received.
-When connected to the Arduino Serial Monitor error reports “parseObject() failed” when power of fx is chosen.
-When manually publishing {“state”:“ON”,“color”:{“r”:255,“g”:255,“b”:255},“brightness”:150,“effect”:“solid”,“transistion”:0} I can use the colour picker to choose a colour and turn on/off.
-Latest libraries and boards loaded into Arduino IDE
-I feel that I have something missing as I am so close, it appears that openhab is not acting on the messages. I just am unsure what that is.
The questions I think I need help on are…
Is there any prerequisites I need installed in Openhab in relation to The JSON side of things?
Has anyone else had this issue?
Can you post your rule code? I’m thinking you’re just creating a faulty Json object…you can also subscribe with MQTT.fx to the led strip’s set topic, so you can see exactly what openHAB is outputting to the Nodemcu.
Ok, so, rereading your original post - you’re actually able to use the openHAB color picker to change colors/power status, correct? And, you’re seeing the MQTT messages that openHAB sends to the strip (whether it’s the power strip or color picker) in the “set” topic, right?
Can you post a couple of those messages? I’d like to see the difference between the mapped (Power/FX) and rule-built (Color/Speed/Intensity) JSON packets.
Finally, can you post the LED.map file, as well? The two controls you’re having problems with (Power/FX) have their JSOn strings built from the MAP file directly, so any formatting issues must be isolated to that file.
Correct. After manually sending this string
{“state”:“ON”,“color”:{“r”:255,“g”:255,“b”:255},“brightness”:150,“effect”:“solid”,“transistion”:0} through the MQTT fx, I can use the colour picker to choose a colour and turn on/off.
Again the LED.map file is a copy from above only with the name change.
Ok, I will check when I get home. I may have changed that last night trying to diagnose the workings and non workings to see if could see any trends as to why. As I copied the code from Openhab this morning before I left for work. I may not have changed it back to the LED.map entry. If that is the case, it still won’t work. Fingers crossed Thanks for your perseverance.
If that’s the case, then the next step in troubleshooting would be to take the exact JSON string from the MAP file and post it to your MQTT.fx (publish to the set topic)…if it doesn’t work there, we may need to start looking at your arduino code next.
Have access to the MQTT and system now.
I have updated the {mqtt=">[mqtt:main/bedstrip/set:command:*:MAP(LED.map)]"} path to be correct. I did fail to change it back last night.
The following is the message is published on the MQTT topic main/bedstrip/set when I switch the power switch to ON. MAP(LED.map)
When I tap the up arrow on Bedstrip color the MQTT topic main/bedstrip/set publishes
{“color”: {“r”: 21.202913280000000000,“g”: 100,“b”: 10.45785600}}
I think the next course of action is to reflash the NodeMCU and coy verbatim your Openhab files to see if that works, then I will try to modify to suit.
Update. I deleted my previous entries and reflashed the NodeMCU and copied item,sitemap,rules and map files in their entirety into my openhab.
Below is what was returned when I switched on the led strip power and selected JSON in MQTTfx.
*** PAYLOAD IS NOT VALID JSON DATA ***
Unexpected character ('M' (code 77)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: java.io.StringReader@1511ecc0; line: 1, column: 2]
The frustrating part is that I am new to the Arduino world. But I’m learning fast.
Update. Finally stopped doing back flips and cart wheels.
Found the issue that dopey me didn’t have the map transformation installed. rebooted my openhab and what do you know… it works. thank you immensely @bartus for your perseverance. It is amazing what happens what the right words a poke in the right direction can do.