Back to sending message sequences from a `function` node

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;
    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.

What precise Tasmota bulb do you have?
Do you want to fade from the current setting to a new target or from fully off to a new target?

I am not sure how to answer the first part.
(Looking at the config in the bulb it is built on Generic 18)
It only supports brightness and colour temperature. NOT RGB.

I want to fade from OFF to a set/given value I define with two sliders.

So when the bulb is powered on it starts at/in the OFF mode and goes to the brightness/temperature I defined in a given number of seconds.


Oh, the brightness is done in 10 steps and temperature in 20. Scaled up to the bulbs range via maths.

Putting aside any code etc - Can you just explain what the purpose of this is please ?

It may be that Tasmota can do at least some of this natively.
Look at the Wakeup and WakeUpDuration commands in the wiki

Wakeup Start wake up sequence from OFF to stored Dimmer value

WakeUpDuration 1..3000 = set wake up duration in seconds

1 Like

Today this is where I am at. But it has quickly gone way beyond my abilities.

With the original code.....

That may help.

I won't post any more as it may not be useful to anyone anyway.

(Double hugs to you.)

That has reduced a lot of work needed.

I am a bit stuck on how to make it start from "OFF" (completely power dead) to on/dull/warm then going to on/bright/cold.

I have the fade working. (Not sure if it is the fade, speed2 or wakeup command.
But it isn't changing both CT and BRIGHTNESS values.

wakeup starts from 0 (OFF) to the value you provide (this is for the dimmer value only)
WakeUpDuration sets the time in seconds to go from 0 to the value provided to the wakeup command.

So that should cover your brightness requirement.

Get the brightness working as you want it first then try CT with fade and speed settings to match.

Fade also provides a transition from current value to new value, the time taken to do the transition is set by the speed command. Fade works with brightness CT and RGB values.

So it should work with CT going from one value to another over N seconds.

I'm not sure if wakeup may override it though. Just try it and see how you get on.

1 Like

Just to declare:

The bulb is DEAD most of the time. NO POWER AT ALL.

So it is a cold power up from OFF (obviously) to max brightness and CT from WARM to COLD.
Turing off is power removed.
(Old circuits.)
And I don't need the bulb using power all the time. (Power bills here are skyrocketing.)
It is mostly my morning alarm clock light.
Turing on slowly MAY be nicer than a bright light suddenly turning on.

If has no power how are you going to turn it on ?

At time x the relay operates. Power behind the relay.
This is for an old school bulb.
Rather than the sudden super bright list coming on, the relay turns on and the bulb fades up slowly.

I am working on ANOTHER one similar, but the brightness and speed are determined by the time of day. And there is the problem that the bulb will be DEAD while turned off.
So I may have to send a command to it (alas slight delay, but....) setting the max brightness and CT.

But that is a fair way down the track, and may not be viable given this new stuff I have been told.

It must be a smart bulb if you tasmota on it ?
So just leave the power on all the time and switch off the LEDs via software.

I am not trying to be difficult, but it isn't that simple.

The bulb is now in my bedside lamp thingy. Used to control the bedside lamp and a couple of other things. Arduino (uno) based. Alas it is an early one the program only just fits.

The devices are powered via push buttons, relays, as they need to be turned on/off at different time for short periods. Not a good idea to have a relay on 24/7. Heat, etc.
There is also a 20 x 4 LCD to show the time/status of things.
But again: It is self contained and only just works - memory wise.

So at the given time (in the morning) the LIGHT relay is turned on to wake me up.
It is winter just now here and I thought rather than the sudden brightness, a slowly warming/brightening light may be better.

This light is also used of an evening when I am going to bed. (And maybe during the day if it is dark and I am in the room.
The slow brightening bulb isn't too much of a problem.

All that is controlled with REAL HARDWARE and all self contained.
No WiFi, no WAP, no RasPi.

Now and then - alas - the arduino hangs and it needs resetting/rebooting. (I think it is the I2C bus)

Controlling the bulb with software from NR means the WAP must be working.
I live where I am surrounded by a LOT of WAPs and it is not reliable for my alarm clock to maybe not turn on the bulb because the WAP is down.

Now, before you shoot me down with the obvious hole in this reply so far:
Yes, I did ask about controlling it with NR at the start and now - suddenly I don't want to.
Not quite.

It has become a bit more complicated than I would have liked, but: That's life.

Quick story to get you on the same page as me:
(more details here)
As was this (now) was my alarm clock/bedside lamp controller that SIMPLY turns the bulb on/off at different times (alarm and when I am going to bed)
This also controls another device. Simple ON/OFF.
The code ONLY JUST fits on the arduino, and it needs work to fix a slight bug if/when it is reset.

Say I go with the "Node Red control" of the lamp.
I will have to add WiFi to the Arduino.
I will have to write code to send the commands to turn the bulb on/off (not too difficult but it needs memory.)
It can't happen. The code as is ONLY JUST FITS!
The arduino doesn't have WiFi built in.
(Oh, and there is a serious lack of GPIO pings.
I have added some more via the I2C bus expander, but that gives problems now and then. I don't want to use it if at all possible.)

All this would mean a SERIOUS rebuild of the clock.

Not worth it - to me.

As is: the bulb when turned on starts from OFF and brightens up to 100% over 4 seconds.
It isn't exactly smooth, but better than the flash when it is just TURNED ON - old bulb way.

What I COULD do - but that is now arching back to the ORIGINAL question:
(ok: When the bulb is powered on from COLD it goes from OFF to(say) 10% brightness and stops.
ITMT, it sends a birth certificate and NR sees it.
NR then sends a series of messages telling the bulb to go from current brightness to max brightness.

That would/could/should work ok.
But it was suggested I get the bulb to do the heavy lifting of brightening up.
And I DO appreciate that idea. It is good. Just not good in THIS case.

Does that help you with a better understanding of the situation?

What I have now is/could be ok for my main room lights as they can survive simply going from *OFF to full brightness when powered on from COLD (no power).
The only rub there is - as I mentioned in another reply
- if it is the morning, they go to a WARM light when turned on.
If it is after (say) 09:00 they go to COLD light.
Then after (again: say) 17:00 they go back to a WARM light - full brightness.

But I think I can live with them simply being COLD every time they are turned on.

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