# Time loop control of a lamp

**URL:** <https://discourse.nodered.org/t/time-loop-control-of-a-lamp/78968>\
**Category:** Dashboard\
**Created:** [5 June 2023 17:28 UTC](https://discourse.nodered.org/t/time-loop-control-of-a-lamp/78968 "2023-06-05T17:28:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![gumue](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gumue](https://discourse.nodered.org/u/gumue)\
**Post date:** [5 June 2023 17:28 UTC](https://discourse.nodered.org/t/time-loop-control-of-a-lamp/78968/1 "2023-06-05T17:28:42Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)\
**Post date:** [6 June 2023 06:52 UTC](https://discourse.nodered.org/t/time-loop-control-of-a-lamp/78968/2 "2023-06-06T06:52:02Z")

</div>

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](https://discourse.nodered.org/uploads/short-url/mBgrZKbPXJpMzuVip0HSWICjRZQ.json) (44.4 KB)

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [6 June 2023 07:30 UTC](https://discourse.nodered.org/t/time-loop-control-of-a-lamp/78968/3 "2023-06-06T07:30:51Z")

</div>

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.

```auto
[{"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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/c/dc897ad01c80b1b368f568acbf08eeba4b88937b.gif)

---

<div class="post-metadata">

**Author:** ![gumue](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gumue](https://discourse.nodered.org/u/gumue)\
**Post date:** [6 June 2023 09:58 UTC](https://discourse.nodered.org/t/time-loop-control-of-a-lamp/78968/4 "2023-06-06T09:58:44Z")

</div>

> [@smanjunath211](#):
>
> `[{"id":"deaea39345ead11a","type":"trigger","z":"777d109`

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?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [6 June 2023 10:55 UTC](https://discourse.nodered.org/t/time-loop-control-of-a-lamp/78968/5 "2023-06-06T10:55:15Z")

</div>

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

```auto
[{"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}]

```

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [6 June 2023 11:03 UTC](https://discourse.nodered.org/t/time-loop-control-of-a-lamp/78968/6 "2023-06-06T11:03:14Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/4/340dae77067f0d8e540539edc9f50381f1956a5e.png)

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

---

<div class="post-metadata">

**Author:** ![gumue](https://avatars.discourse-cdn.com/v4/letter/g/b487fb/32.png) [@gumue](https://discourse.nodered.org/u/gumue)\
**Post date:** [6 June 2023 12:58 UTC](https://discourse.nodered.org/t/time-loop-control-of-a-lamp/78968/7 "2023-06-06T12:58:27Z")

</div>

> [@smanjunath211](#):
>
> @E1cid

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

---

<div class="post-metadata">

**Author:** ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)\
**Post date:** [7 June 2023 02:36 UTC](https://discourse.nodered.org/t/time-loop-control-of-a-lamp/78968/8 "2023-06-07T02:36:26Z")

</div>

👍  
no worries ... whatever works best for your use-case

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 June 2023 02:36 UTC](https://discourse.nodered.org/t/time-loop-control-of-a-lamp/78968/9 "2023-06-21T02:36:52Z")

</div>

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