I have been here before but this is a new twist on the message.
This is the code as I have it working.
But it sends RGB messages to RGB-LEDs.
if (msg.delay_time == undefined)
msg.delay_time = 400;
var delay_time = msg.delay_time;
if (msg.sunset == undefined)
msg.sunset = "196,10,0";
var sunset = msg.sunset;
sendLater(0, msg, "rgb,0," + sunset);
sendLater(delay_time * 1, msg, "rgb,1," + sunset);
sendLater(delay_time * 2, msg, "rgb,1," + sunset);
sendLater(delay_time * 3, msg, "rgb,2," + sunset);
if (msg.existing[0] == undefined) {
msg.existing[0] = "0,0,0";
}
sendLater(delay_time * 4, msg, "rgb,0," + msg.existing[0]);
sendLater(delay_time * 5, msg, "rgb,3," + sunset);
if (msg.existing[1] == undefined) {
msg.existing[1] = "0,0,0";
}
sendLater(delay_time * 6, msg, "rgb,1," + msg.existing[1]);
sendLater(delay_time * 7, msg, "rgb,4," + sunset);
if (msg.existing[2] == undefined) {
msg.existing[2] = "0,0,0";
}
sendLater(delay_time * 8, msg, "rgb,2," + msg.existing[2]);
sendLater(delay_time * 9, msg, "rgb,5," + sunset);
if (msg.existing[3] == undefined) {
msg.existing[3] = "0,0,0";
}
sendLater(delay_time * 10, msg, "rgb,3," + msg.existing[3]);
sendLater(delay_time * 11, msg, "rgb,6," + sunset);
if (msg.existing[4] == undefined) {
msg.existing[4] = "0,0,0";
}
sendLater(delay_time * 12, msg, "rgb,4," + msg.existing[4]);
sendLater(delay_time * 13, msg, "rgb,7," + sunset);
if (msg.existing[5] == undefined) {
msg.existing[5] = "0,0,0";
}
sendLater(delay_time * 14, msg, "rgb,5," + msg.existing[5]);
if (msg.existing[6] == undefined) {
msg.existing[6] = "0,0,0";
}
sendLater(delay_time * 15, msg, "rgb,6," + msg.existing[6]);
sendLater(delay_time * 16, msg, "rgb,7," + msg.existing[7]);
if (msg.existing[7] == undefined) {
msg.existing[7] = "0,0,0";
}
/**
* @param {number} delayMS
* @param {NodeMessage} msg
* @param {string} payload
*/
function sendLater(delayMS, msg, payload) {
// node.warn(`In sendLater(${delayMS},${msg},${payload}) - setting up a timer to send payload '${payload}' in ${(delayMS/1000).toFixed(2)} seconds time`)
const callback = function (msg, payload) {
// node.warn("Sending delayed payload " + payload);
msg.payload = payload;
node.send(msg);
}
setTimeout(callback, delayMS, RED.util.cloneMessage(msg), payload)
}
The twist is that I want to control a tasmota bulb
.
When the bulb turns on: it is/defaults to being OFF
.
I define where it goes to with brightness
and colour temperature
and the speed it takes to get there - in seconds.
So it does the maths - kind of as shown in the above code but the opposite way around. (going from low to high)
And sends messages at a fixed time interval with scaled brightness
and colour temperature
values from 0,0
to what is set.
The destination values are stored in flow context
.
I'll put my hand up here/now.
Yes, I need help.
Normally I try to not ask for this kind and want to be poked in the right direction and learn myself.
Alas with things just happened, I fear I am not going to understand it by a long way and will only frustrate myself rather than learn.
Ok, I am kind of open to well structured examples. But please understand I don't think I understand what needs to be done.
Thanks in advance.