Time loop control of a lamp

unfortunately I have no idea right now. I would like to control a lamp for which I would like to set the time (in minutes) how long the lamp is "ON" and how long (in minutes) the lamp is "OFF" afterwards. This should run continuously, after the time luminaire "off" has expired should start again the time luminaire "on". I have no idea how I can solve this easily by using a little UI. Thanks for the support!

I'm using the below toggle switch for several FANS and LIGHTS

you can:

  • specify overall runtime (e.g. 2h)
  • specify the ON-Time (e.g. 20min on)
  • specify the OFF-Time (e.g 10min off)
  • trigger with ON/OFF
  • reset runtime (MOTION trigger)

toggle_timer.json (44.4 KB)

Welcome to the Node-Red Forum.

Try the below flow, should do what you want i have put in 10 seconds to check the flow, you can change it to the time you like.

[{"id":"deaea39345ead11a","type":"trigger","z":"777d1097bd4779da","name":"","op1":"true","op2":"false","op1type":"bool","op2type":"bool","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":500,"y":990,"wires":[["42c77ecfefd5af72"],["a51d19ae690d547a"]]},{"id":"42c77ecfefd5af72","type":"debug","z":"777d1097bd4779da","name":"debug 330","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":730,"y":990,"wires":[]},{"id":"a51d19ae690d547a","type":"trigger","z":"777d1097bd4779da","name":"","op1":"false","op2":"true","op1type":"bool","op2type":"bool","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":520,"y":1080,"wires":[["42c77ecfefd5af72"],["deaea39345ead11a"]]},{"id":"ed7d71db8338cfcb","type":"inject","z":"777d1097bd4779da","name":"Start","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":230,"y":990,"wires":[["deaea39345ead11a","1a39788bbdd1b33f"]]},{"id":"f289fb40dc6d2c30","type":"inject","z":"777d1097bd4779da","name":"Stop","props":[{"p":"reset","v":"true","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","x":230,"y":930,"wires":[["deaea39345ead11a","a51d19ae690d547a"]]},{"id":"1a39788bbdd1b33f","type":"change","z":"777d1097bd4779da","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":1080,"wires":[["a51d19ae690d547a"]]}]

loop

Thanks, that looks very good and easy. Is it possible to enter the time for ON / OFF over two input fields in the Dashboard and send this values to both triggers?

1 Like

Would probably just use one trigger node and change the output and time each loop. Using a ui-form to send times.
e.g.

[{"id":"f289fb40dc6d2c30","type":"inject","z":"b9860b4b9de8c8da","name":"Stop","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"stop","payloadType":"str","x":270,"y":4020,"wires":[["deaea39345ead11a"]]},{"id":"deaea39345ead11a","type":"trigger","z":"b9860b4b9de8c8da","name":"","op1":"","op2":"","op1type":"pay","op2type":"payl","duration":"10","extend":false,"overrideDelay":true,"units":"s","reset":"stop","bytopic":"all","topic":"topic","outputs":2,"x":450,"y":4080,"wires":[["42c77ecfefd5af72","27aaa2ae0581c601"],["1a39788bbdd1b33f"]]},{"id":"1877b30966c68335","type":"ui_button","z":"b9860b4b9de8c8da","name":"","group":"2d4fe667.28f8ba","order":26,"width":0,"height":0,"passthru":false,"label":"Stop","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"stop","payloadType":"str","topic":"topic","topicType":"msg","x":250,"y":4080,"wires":[["deaea39345ead11a"]]},{"id":"1a39788bbdd1b33f","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload = true ? false : true","tot":"jsonata"},{"t":"set","p":"delay","pt":"msg","to":"$$.payload = true ? $$.time.on * 1000 : $$.time.off * 1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":4140,"wires":[["deaea39345ead11a"]]},{"id":"42c77ecfefd5af72","type":"debug","z":"b9860b4b9de8c8da","name":"debug 330","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":670,"y":4060,"wires":[]},{"id":"27aaa2ae0581c601","type":"ui_led","z":"b9860b4b9de8c8da","order":26,"group":"2d4fe667.28f8ba","width":0,"height":0,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"false","valueType":"bool"},{"color":"#008000","value":"true","valueType":"bool"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":false,"name":"","x":670,"y":4120,"wires":[]},{"id":"28533b8df9915e15","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"time","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":4200,"wires":[["def7ab8ac8db5ac0","1a39788bbdd1b33f"]]},{"id":"def7ab8ac8db5ac0","type":"ui_form","z":"b9860b4b9de8c8da","name":"","label":"Times in seconds","group":"2d4fe667.28f8ba","order":24,"width":0,"height":0,"options":[{"label":"On time","value":"on","type":"number","required":true,"rows":null},{"label":"Off time","value":"off","type":"number","required":true,"rows":null}],"formValue":{"on":"","off":""},"payload":"","submit":"start","cancel":"","topic":"topic","topicType":"msg","splitLayout":"","className":"","x":190,"y":4200,"wires":[["28533b8df9915e15"]]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":2,"disp":true,"width":"12","collapse":false,"className":""},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
1 Like

Yes, add a payload msg.delay in the input of trigger node and make sure the override delay with msg.delay dialog is ticked inside the trigger node.
the input value will be in milliseconds.

image

I like the @E1cid 's idea of using 1 trigger, slightly complicated (for me), but efficient.

great, working well i prefer to use @E1cid solution - thanks!

:+1:
no worries ... whatever works best for your use-case

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