How to get value from status message to use in sending new message

Hi all,

I have an Ikea on/off switch that I use to control a RGBW LED strip connected to a Shelly RGBW2. I have the on/off working but now I want to use the long press on/off to dim the white of the LED strip.

I figured I would need to know the current white setting and then send a new message to the RGBW2 with the current white setting + 5. But how do I get the current white setting from the status message?

This is the status message, the white is set to 125 here.

{
    "lights":
    [{
        "ison":false,
        "source":"http",
        "has_timer":false,
        "timer_started":0,
        "timer_duration":0,
        "timer_remaining":0,
        "mode":"color",
        "red":0,
        "green":0,
        "blue":0,
        "white":125,
        "gain":28,
        "effect":0,
        "transition":0,
        "power":10.48,
        "overpower":false
    }],
    "meters":
    [{
        "power":10.48,
        "is_valid":true,
        "overpower":false,
        "timestamp":1663629453,
        "counters":
        [
            8.309,
            1.018,
            0
        ],
        "total":2170
    }],
    "inputs":
    [{
        "input":0,
        "event":"",
        "event_cnt":0
    }]
}
  1. How do I get this value for white (125 here) from this message?
  2. And how do I increase that value by 5? (I’m guessing a change node?)
  3. And finally, how do I use the new value (130) in the new message to send to the RGBW2?

The new message would have to look like this:

{
    red : 0,
    green : 0,
    blue : 0,
    white : 130,
    on : true
}

I figured out how to do this using a function. I send a message with an empty payload to the Shelly RGBW2 to get the state and I use that as the entry for the function. The function then extracts the white and gain (I also added a little orange from the RGB LED’s as the white LED’s are a little too white, gain is basically the brightness of the color LED’s) values and increase them. Finally I use those values to create the message for the RGBW2:

var white = msg.payload.lights[0].white;
var gain = msg.payload.lights[0].gain;

white = white + 5;
gain = gain + 2;

if (white > 255) { white = 255; }
if (gain > 100) { gain = 100; }

msg.payload = {
    "white": white,
    "gain": gain
};

return msg;

I also make sure neither value ever exceeds it’s max.

And of course I have a similar function to decrease the values to dim the LED strip.