Extract value (number) from node red payload?

I have problems with my Shelly dimmer 2. I have set it up over mqtt. Everything works great except dimming slider value. Dimming slider works great when I am using it, but I wan't that slider pick up the value from shelly dimmer when it is dimmed somewhere else.
I have subscribed to MQTT topic "shellies/shellydimmer2-D8BFC01A040E/light/0/status" and when I dimm it somewhere else I get this on debug node

shellies/shellydimmer2-D8BFC01A040E/light/0/status : msg : Object


topic: "shellies/shellydimmer2-D8BFC01A040E/light/0/status"

payload: "{"ison":true,"has_timer":false,"timer_started":0,"timer_duration":0,"timer_remaining":0,"mode":"white","brightness":16}"

qos: 0

retain: false

_msgid: "14b5cdb.c291e32"

I would like to get only the value "brightness":16 or any other value of brightness to output as number so I can send that number to slider node.

Can someone help me?

Thank you!

Hello & welcome to the fourm.

So a small lesson on JS objects and their equivalent string representation (AKA JSON)...

Your payload is a string/JSON (due to the Output setting on the MQTT node). You could attempt some complex splits and loops etc - but - as it is JSON (JavaScript Object Notation) - just let JS do its thing - turn that JSON back into a JS Object! (if you dont know what I mean, it'd be worth reading up - will help you greatly in node-red knowing the difference)

So first off, change your MQTT IN to...
... then you will be able to simply "copy path" to any item

There’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.


This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.