I'm not sure if this is possible, but i'm using the function below I grabbed from someone that turns off/on a lamp through Alexa commands on/off. There is a option to dim/brighten in the Alexa command. I put a debug node and it changes in the percentage field (screenshot below) when looking at the payload. The function i'm using looks like it stores it in var b and I want to compare the percentage coming in from the payload has changed, if it has I want to change the percentage of the light.
Is this possible?
// Enter your Light entity and if used the Effect Name
var light = "light.printer_lamp";
var effect = "Cool white";
const cs = global.get('homeassistant').homeAssistant.states[light].state; //current state
const cc = global.get('homeassistant').homeAssistant.states[light].attributes.rgb_color; //current color
const cb = global.get('homeassistant').homeAssistant.states[light].attributes.brightness; //current 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 === "off" && s == "off") {
msg.payload = {"service": "turn_on", data:{"entity_id": light, "rgb_color": c,"brightness": b, "effect":"none"}};
msg.payload = {"service": "turn_off", data:{"entity_id": light}};
}
if (msg.payload === "off") {
msg.payload = {"service": "turn_off", data:{"entity_id": light}}; //"rgb_color": c,
}
if (msg.payload === "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, "effect":effect}};
}
return msg
return msg;