How can I slowly increase the brightness of a light in Node-red?.
apply for() to the Dashboard with slider...Or what else?
How can I slowly increase the brightness of a light in Node-red?.
apply for() to the Dashboard with slider...Or what else?
To send msg in a loop you can use node.send
, eg;
s = msg.payload
for(x=s;x<255;x++){
node.send({"brightness":x})
}
Then add a delay node, set it rate limit 1 per second, or a fraction; 0.2
Example flow
[{"id":"230ec9aa.d10f3e","type":"inject","z":"46161f77.3c21d","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"payload":"200","payloadType":"num","x":250,"y":500,"wires":[["dd0be8e0.063e98"]]},{"id":"dd0be8e0.063e98","type":"function","z":"46161f77.3c21d","name":"","func":"s = msg.payload\n\nfor(x=s;x<255;x++){\n\n node.send({\"brightness\":x})\n\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":400,"y":500,"wires":[["cec8de22.da0a4"]]},{"id":"e19bad9a.a09f98","type":"debug","z":"46161f77.3c21d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":500,"wires":[]},{"id":"cec8de22.da0a4","type":"delay","z":"46161f77.3c21d","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"0.5","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":550,"y":500,"wires":[["e19bad9a.a09f98"]]}]
Thank you for answering my questions.
I'm a beginner and studying.
I did it exactly the same. But The output data keeps generating errors.
Do you know why?
Can I just send out number?
Set the debug node to output 'complete msg object'
well - msg.payload
can be just a number - but msg
cannot - it must be an object.
To receive data with dashboard sliders, it must be transformed into numbers.
Is there any other way...?
yes - use a change node ? move msg.payload.brightness to msg.payload ?
Eveything worked out the best
(+ I changed. brightness > bright)
Sorry, but I have to ask:
s = msg.payload
for(x=s;x<255;x++){
node.send({"brightness":x})
}
The for(x=s;x<255;x++){
Ok, I get it that x has to be set to what was sent in as the starting point - I'm guessing.
But the x=s
is inside the for
. So why isn't it stuck with x being 200?
Yeah, I'm stupid. This has been well established.
I'm not upset / angry / (what ever) with you for posting it. It works.
But I can't see the how.
Is it that the x++
only goes back to the previous part where it is x<255
?
Anyway, thanks in advance.
(I hope.)
Oh, and P.S.
Aren't you forgetting the let
or var
in the first line for s
?
for( initial; condition; increment ){ statement }
Initial is the start value upon starting the loop. As long as condition is true, statement is executed after which initial is incremented with the increment value (ie. increment is an expression. ++ means: current value +1)
ie. start at 130, is 130 lower than 255 ? yes, execute and increment with 1 (=131), etc.
Aren't you forgetting the
let
orvar
in the first line fors
?
In javascript it is not required to declare variables (yes it is better practice), if they are not declared, they do require a value to be set, which applies here.
Thanks.
So
Is it that the
x++
only goes back to the previous part where it isx<255
?
Thanks.
Sorry, you lost me there to what you mean.
So
Is it that thex++
only goes back to the previous part where it isx<255
?
Read it again. the initial value is the starting value and it increments. Loop is stopped when condition is false (ie when x = 256)
Sorry, you lost me there to what you mean.
let a // ok - declaration
var a // ok - declaration
let a = 'value' // ok - declaration with a value set
a = 'value' // ok - value set
a // not ok - no declaration and no value set
Thanks.
The if( )
but.... Understood. There was confusion to what was meant by me with the:
Is it that the
x++
only goes back to the previous part where it isx<255
?
line.
All good now.
BTW, I'm guessing you are using the new Beta? Y/N?
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.