Node Red Save and Restore WLED effect

Hey guys,

Found this function on a YouTube channel. And I’m not sure how to change it to what I need.

Basically because this is a WLED light I want to remove brightness and swap rgb colour for the current effect playing.

Can anyone help change this?

Thanks :slight_smile:

// Enter your Light entity and if used the Effect Name
var light = "light.tv_strip";
var effect = "Fill Noise"; 

const cs = global.get('homeassistant').homeAssistant.states[light].state;
const cc = global.get('homeassistant').homeAssistant.states[light].attributes.rgb_color;
const cb = global.get('homeassistant').homeAssistant.states[light].attributes.brightness;

var s = context.get('s'); // These lines retrieve the lables 's', 'c' & 'b' 
var c = context.get('c'); // from memory and apply thier values to the
var b = context.get('b'); // variables s, c & b used to retun the Light state

if (msg.payload === "trigger_off" && s == "off") {
    msg.payload =  {"service": "turn_on", data:{"entity_id": light, "rgb_color": c,"brightness": b, "effect":"effect"}};
    msg.payload =  {"service": "turn_off", data:{"entity_id": light}};
    }

if (msg.payload === "trigger_off") {
    msg.payload =  {"service": "turn_on", data:{"entity_id": light, "rgb_color": c,"brightness": b, "effect":"effect"}};
    }

if (msg.payload === "trigger_on") {
    context.set('s', cs); // These line save the values of cs, cc & cb
    context.set('c', cc); // and save them in memory with lables:
    context.set('b', cb); // 's', 'c' & 'b' 
    
    // 'Alarm state' will be RED & 100% Brighness - Adjust this line to suit your needs
    msg.payload =  {"service": "turn_on",data:{"entity_id": light, "rgb_color": [251,41,255],"brightness": 255, "effect":effect}};
    }

return msg