# Day/Night Device Duty Cycle

**URL:** <https://discourse.nodered.org/t/day-night-device-duty-cycle/23936>\
**Category:** General\
**Created:** [31 March 2020 04:18 UTC](https://discourse.nodered.org/t/day-night-device-duty-cycle/23936 "2020-03-31T04:18:16Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![napalm99](https://avatars.discourse-cdn.com/v4/letter/n/a587f6/32.png) [@napalm99](https://discourse.nodered.org/u/napalm99)\
**Post date:** [31 March 2020 04:18 UTC](https://discourse.nodered.org/t/day-night-device-duty-cycle/23936/1 "2020-03-31T04:18:16Z")

</div>

Hi there, I've got Node Red running on a Raspi 3B+ and a couple ESP8266s connected to the network. I'm using these ESP8266 to turn ON and OFF devices via MQTT. I'm pretty new to Node Red and I am struggling to achieve this:

Daytime Duty Cycle :  
-Turn ON a device for 15 min then OFF for 15 min. (Repeat from 6 AM to 6 PM).

Nighttime Duty Cycle:  
-Turn ON a device for 15 min then OFF for 1 Hour and 45 min. (Repeat from 6 PM to 6 AM).

I am using a Big Timer node each 2 hours of "night interval" (as shown in the image) but when it comes to the short 15 min ON/15 min OFF times I need a LOT of nodes. Is there a more efficient node configuration? Any Ideas?

![img1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/2/d2e34f32f8cd5314da69ba811cacd8d87e2a6e40.jpeg)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [31 March 2020 06:58 UTC](https://discourse.nodered.org/t/day-night-device-duty-cycle/23936/2 "2020-03-31T06:58:55Z")

</div>

Maybe look to use trigger nodes set to repeat, and trigger them once at 6am and 6pm and reset the other at the same time

---

<div class="post-metadata">

**Author:** ![napalm99](https://avatars.discourse-cdn.com/v4/letter/n/a587f6/32.png) [@napalm99](https://discourse.nodered.org/u/napalm99)\
**Post date:** [31 March 2020 22:00 UTC](https://discourse.nodered.org/t/day-night-device-duty-cycle/23936/3 "2020-03-31T22:00:33Z")

</div>

Solved the Daytime cycle with good old Astable NE555. Now I gonna try to solve the night cycle (15min ON / 1 hour 45 min OFF) cycle with a combination of Big Timer and Trigger nodes. Let's see what happens.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [31 March 2020 22:20 UTC](https://discourse.nodered.org/t/day-night-device-duty-cycle/23936/4 "2020-03-31T22:20:01Z")

</div>

I agree with @dceejay's suggestion about `trigger` nodes.

Here is a flow which may help you with ideas.

The two `inject` nodes are one output from `bigtimer` node.

the two `debug` nodes could be the same also.

I just used separate ones to help you see what is happening.

```auto
[{"id":"b95543c8.1478f8","type":"tab","label":"Flow 13","disabled":false,"info":""},{"id":"571318e0.ac25e8","type":"gate","z":"b95543c8.1478f8","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":310,"y":680,"wires":[["cc8f353b.57f9c","d5b7a0f0.dfd4a8"]]},{"id":"9a50daa5.3df158","type":"inject","z":"b95543c8.1478f8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":680,"wires":[["571318e0.ac25e8"]]},{"id":"d5b7a0f0.dfd4a8","type":"debug","z":"b95543c8.1478f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":450,"y":680,"wires":[]},{"id":"cc8f353b.57f9c","type":"change","z":"b95543c8.1478f8","name":"close","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":760,"wires":[["571318e0.ac25e8"]]},{"id":"7d7923c1.884144","type":"inject","z":"b95543c8.1478f8","name":"","topic":"control","payload":"open","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":720,"wires":[["571318e0.ac25e8"]]},{"id":"abb4eee7.21ed1","type":"inject","z":"b95543c8.1478f8","name":"One","topic":"GATE","payload":"open","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":930,"wires":[["21cb4fa1.ccdaf"]]},{"id":"21cb4fa1.ccdaf","type":"function","z":"b95543c8.1478f8","name":"One only V2","func":"var full = context.get(\"FULL\") || 0;\nif (msg.topic == \"GATE\")\n{\n //\n if (msg.payload == \"FULL\")\n {\n // Allow all messages\n context.set(\"FULL\", 1);\n context.set(\"ALLOW\",1);\n node.status({fill: \"green\",text:\"FULL\"});\n return;\n } else\n if (msg.payload == \"CLOSE\")\n {\n // Stop messages\n context.set(\"FULL\", 0);\n context.set(\"ALLOW\",0);\n node.status({});\n return;\n } else\n //\n {\n context.set(\"ALLOW\",1);\n node.status({fill: \"green\",text:\"ONE\"});\n return;\n }\n}\nif (context.get(\"ALLOW\") == 1)\n{\n //\n if (full == 0)\n {\n context.set(\"ALLOW\",0);\n node.status({});\n return msg;\n } else\n return msg;\n}\n\n","outputs":1,"noerr":0,"x":320,"y":890,"wires":[["d075c6f8.b05ce"]]},{"id":"4227af45.46904","type":"inject","z":"b95543c8.1478f8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":890,"wires":[["21cb4fa1.ccdaf"]]},{"id":"d075c6f8.b05ce","type":"debug","z":"b95543c8.1478f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":490,"y":890,"wires":[]},{"id":"f0301d00.1606c8","type":"inject","z":"b95543c8.1478f8","name":"Full","topic":"GATE","payload":"FULL","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":970,"wires":[["21cb4fa1.ccdaf"]]},{"id":"3bb58a03.9e67be","type":"inject","z":"b95543c8.1478f8","name":"Close","topic":"GATE","payload":"CLOSE","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":1010,"wires":[["21cb4fa1.ccdaf"]]},{"id":"479fd43e.358454","type":"function","z":"b95543c8.1478f8","name":"Cycle next value","func":"switch (msg.next) {\n \n case 1:\n msg.delay = msg.runtime1;\n msg.payload = 1; \n msg.next = 2;\n break;\n case 2:\n msg.delay = msg.runtime2;\n msg.payload = 2;\n msg.next = 3;\n break; \n case 3:\n msg.delay = msg.runtime3;\n msg.payload = 3;\n msg.next = 4;\n break; \n \n case 4:\n msg.delay = msg.runtime4;\n msg.payload = 4;\n// msg.payload = \"OFF\";\n msg.next = 5;\n break; \n case 5:\n msg.delay = msg.runtime5;\n msg.payload = \"OFF\";\n msg.next = 6;\n break; \n case 6:\n msg.reset = true;\n break;\n}\nmsg.who = \"auto off\";\nnode.status(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":480,"y":270,"wires":[["ca5e2f2a.1f74f"]]},{"id":"ca5e2f2a.1f74f","type":"delay","z":"b95543c8.1478f8","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":460,"y":330,"wires":[["479fd43e.358454","102643e2.790e94"]]},{"id":"4666bd6c.b6c854","type":"function","z":"b95543c8.1478f8","name":"Initialize","func":"var delay = flow.get('delay') || 15; //15 if not set\n\nvar interval = delay * 1000; // convert value to seconds.\n//var interval = 30*60000; // (30 minutes)\n// interval = 3000; // Test\n// Define runtime1\nmsg.runtime1 = interval;\n\n// Define runtime2\nmsg.runtime2 = interval;\n\n// Define runtime3\nmsg.runtime3 = interval;\n\n// Define runtime4\nmsg.runtime4 = interval;\n\n// Define runtime5\nmsg.runtime5 = interval;\n\n// Define runtime6\nmsg.runtime6 = interval;\n\n// Next to be activated is number 1\nmsg.next = 1;\n\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":270,"wires":[["479fd43e.358454"]]},{"id":"ce83e5eb.580578","type":"inject","z":"b95543c8.1478f8","name":"","topic":"","payload":"foo","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":270,"wires":[["4666bd6c.b6c854"]]},{"id":"c5d2d8f5.c3614","type":"inject","z":"b95543c8.1478f8","name":"Set","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":200,"wires":[["d17dcd3d.6fb34"]]},{"id":"d17dcd3d.6fb34","type":"change","z":"b95543c8.1478f8","name":"","rules":[{"t":"set","p":"delay","pt":"flow","to":"4","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":200,"wires":[[]]},{"id":"102643e2.790e94","type":"debug","z":"b95543c8.1478f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":650,"y":330,"wires":[]},{"id":"8dfd6227.642908","type":"function","z":"b95543c8.1478f8","name":"","func":"var act = context.get(\"activate\");\nif (msg.payload == 'on'){\n act = 1;\n context.set(\"activate\", act)\n}\nelse {\n act = 0;\n context.set(\"activate\", act)\n}\nif(msg.topic == 'turnon' && act == 1){\n msg.payload = 1;\n}\nelse{\n msg.payload = 0;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":490,"wires":[["c182ddfe.f2e2f"]]},{"id":"dfa4949b.3af7e8","type":"inject","z":"b95543c8.1478f8","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":420,"wires":[["8dfd6227.642908"]]},{"id":"c182ddfe.f2e2f","type":"debug","z":"b95543c8.1478f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":530,"y":490,"wires":[]},{"id":"2dee088a.238868","type":"inject","z":"b95543c8.1478f8","name":"","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":460,"wires":[["8dfd6227.642908"]]},{"id":"e6e62134.e97498","type":"inject","z":"b95543c8.1478f8","name":"Active","topic":"active","payload":"active","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":500,"wires":[["8dfd6227.642908"]]},{"id":"d20f5a68.c104c","type":"mqtt in","z":"b95543c8.1478f8","name":"IR_Command_RX","topic":"IR_REMOTE_CONTROL/#","qos":"2","datatype":"auto","broker":"8a2e80be.f7c928","x":170,"y":1200,"wires":[["2df2942d.674894","8be3cb06.ea8248"]]},{"id":"92a365c6.af355","type":"mqtt out","z":"b95543c8.1478f8","name":"IR_TX","topic":"","qos":"","retain":"","broker":"8a2e80be.f7c928","x":1070,"y":1310,"wires":[]},{"id":"2df2942d.674894","type":"debug","z":"b95543c8.1478f8","name":"RX","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":370,"y":1160,"wires":[]},{"id":"a0855ef3.c05038","type":"debug","z":"b95543c8.1478f8","name":"TX","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1070,"y":1360,"wires":[]},{"id":"25b3f758.654538","type":"function","z":"b95543c8.1478f8","name":"TV Volume DOWN","func":"msg.payload = {\"Protocol\":\"SAMSUNG\",\"Bits\":32,\"Data\":\"0xE0E0D02F\",\"Repeat\":1};\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":1420,"wires":[["934095df.d92c58"]]},{"id":"2fa6f939.231a8e","type":"inject","z":"b95543c8.1478f8","name":"","topic":"","payload":"SEND","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1420.0001220703125,"wires":[["25b3f758.654538"]]},{"id":"f7cda1f4.a7a3c","type":"json","z":"b95543c8.1478f8","name":"","property":"payload","action":"","pretty":false,"x":700,"y":1310,"wires":[["7702a364.a2a29c"]]},{"id":"321433cf.9ee7cc","type":"function","z":"b95543c8.1478f8","name":"TV Volume UP","func":"msg.payload = {\"Protocol\":\"SAMSUNG\",\"Bits\":32,\"Data\":\"0xE0E0E01F\", \"Repeat\":1};\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":1480,"wires":[["934095df.d92c58"]]},{"id":"9a4daee5.b5a278","type":"inject","z":"b95543c8.1478f8","name":"","topic":"","payload":"SEND","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1480.0001220703125,"wires":[["321433cf.9ee7cc"]]},{"id":"9ffc62ed.cb77d","type":"json","z":"b95543c8.1478f8","name":"","property":"payload","action":"","pretty":false,"x":520,"y":1200,"wires":[["5286737b.d7e184","e5787bd0.59ac"]]},{"id":"5286737b.d7e184","type":"debug","z":"b95543c8.1478f8","name":"1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":1160,"wires":[]},{"id":"e2110fb4.905c28","type":"debug","z":"b95543c8.1478f8","name":"2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":870,"y":1160,"wires":[]},{"id":"e5787bd0.59ac","type":"split","z":"b95543c8.1478f8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":700,"y":1200,"wires":[["720ad775.e7c638","e2110fb4.905c28"]]},{"id":"5da16990.0481b","type":"debug","z":"b95543c8.1478f8","name":"This is the packet","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1110,"y":1200,"wires":[]},{"id":"28925c4f.5ca8bc","type":"inject","z":"b95543c8.1478f8","name":"Capture","topic":"GATE","payload":"open","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":350,"y":1290,"wires":[["8be3cb06.ea8248"]]},{"id":"8be3cb06.ea8248","type":"function","z":"b95543c8.1478f8","name":"One only.","func":"if (msg.topic == \"GATE\")\n{\n context.set(\"ALLOW\",1);\n node.status({fill: \"green\",text:\"ONE\"});\n return;\n}\nif (context.get(\"ALLOW\") == 1)\n{\n //\n context.set(\"ALLOW\",0);\n node.status({fill: \"red\",text:\"BLOCK\"});\n return msg;\n}","outputs":1,"noerr":0,"x":380,"y":1200,"wires":[["9ffc62ed.cb77d"]]},{"id":"720ad775.e7c638","type":"change","z":"b95543c8.1478f8","name":"","rules":[{"t":"delete","p":"payload.DataLSB","pt":"msg"},{"t":"set","p":"payload.Repeat","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":1200,"wires":[["5da16990.0481b","d3fc936e.09cfd"]]},{"id":"d3fc936e.09cfd","type":"function","z":"b95543c8.1478f8","name":"","func":"if (msg.payload != \"SEND\")\n{\n context.set(\"Keep\",msg.payload);\n node.status({fill: \"green\",text:\"Holding\"});\n return;\n}\nmsg.payload = context.get(\"Keep\");\nreturn msg;\n","outputs":1,"noerr":0,"x":1070,"y":1240,"wires":[["f7cda1f4.a7a3c"]]},{"id":"dd909bd.daef368","type":"inject","z":"b95543c8.1478f8","name":"Test","topic":"","payload":"SEND","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":520,"y":1240,"wires":[["d3fc936e.09cfd"]]},{"id":"be05e17b.591238","type":"comment","z":"b95543c8.1478f8","name":"IR capture flow","info":"","x":660,"y":1100,"wires":[]},{"id":"934095df.d92c58","type":"fan","z":"b95543c8.1478f8","x":510,"y":1420,"wires":[["dee385b9.d925c8"]]},{"id":"dee385b9.d925c8","type":"change","z":"b95543c8.1478f8","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"IR_REMOTE_CONTROL/cmnd/IRSend","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":1380,"wires":[["f7cda1f4.a7a3c"]]},{"id":"7702a364.a2a29c","type":"change","z":"b95543c8.1478f8","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"IR_REMOTE_CONTROL/cmnd/IRSend","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":920,"y":1310,"wires":[["92a365c6.af355","a0855ef3.c05038"]]},{"id":"2f3ac5b1.e1c602","type":"inject","z":"b95543c8.1478f8","name":"","topic":"","payload":"SEND","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1530,"wires":[["b7a051d2.d8139"]]},{"id":"b7a051d2.d8139","type":"function","z":"b95543c8.1478f8","name":"TV Volume MUTE","func":"msg.payload = {\"Protocol\":\"SAMSUNG\",\"Bits\":32,\"Data\":\"0xE0E0F00F\",\"Repeat\":1};\nreturn msg;\n","outputs":1,"noerr":0,"x":330,"y":1529.9998779296875,"wires":[["934095df.d92c58"]]},{"id":"a4c63d.a0a731c","type":"comment","z":"b95543c8.1478f8","name":"Test area","info":"","x":300,"y":1380,"wires":[]},{"id":"c47b2d3f.a530c8","type":"inject","z":"b95543c8.1478f8","name":"Sunrise","topic":"","payload":"sunrise","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":2090,"wires":[["6f49ff46.40275","5bbf8fa9.155c38"]]},{"id":"f542a998.2d0928","type":"inject","z":"b95543c8.1478f8","name":"Sunset","topic":"","payload":"sunset","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":2170,"wires":[["6f49ff46.40275","5bbf8fa9.155c38"]]},{"id":"6f49ff46.40275","type":"trigger","z":"b95543c8.1478f8","op1":"on","op2":"off","op1type":"str","op2type":"str","duration":"5","extend":false,"units":"s","reset":"sunset","bytopic":"all","name":"ON time","x":400,"y":2090,"wires":[["dcb31570.db6cc8","be5e67f3.da732"]]},{"id":"be5e67f3.da732","type":"switch","z":"b95543c8.1478f8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":2140,"wires":[["449a4598.8d063c"]]},{"id":"dcb31570.db6cc8","type":"debug","z":"b95543c8.1478f8","name":"Day mode","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":660,"y":2050,"wires":[]},{"id":"449a4598.8d063c","type":"delay","z":"b95543c8.1478f8","name":"OFF time","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":530,"y":2140,"wires":[["6f49ff46.40275"]]},{"id":"5bbf8fa9.155c38","type":"trigger","z":"b95543c8.1478f8","op1":"on","op2":"off","op1type":"str","op2type":"str","duration":"5","extend":false,"units":"s","reset":"sunrise","bytopic":"all","name":"ON time","x":400,"y":2250,"wires":[["b7a46866.00479","4365f87.891ea88"]]},{"id":"b7a46866.00479","type":"switch","z":"b95543c8.1478f8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":2300,"wires":[["5cebc78.4686c38"]]},{"id":"5cebc78.4686c38","type":"delay","z":"b95543c8.1478f8","name":"OFF time","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":530,"y":2300,"wires":[["5bbf8fa9.155c38"]]},{"id":"4bb8edd7.37af6c","type":"comment","z":"b95543c8.1478f8","name":"BIG TIMER ouptut","info":"","x":160,"y":2050,"wires":[]},{"id":"4365f87.891ea88","type":"debug","z":"b95543c8.1478f8","name":"Night mode","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":660,"y":2210,"wires":[]},{"id":"8a2e80be.f7c928","type":"mqtt-broker","z":"","name":"MQTT host","broker":"192.168.0.99","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"2","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<div class="post-metadata">

**Author:** ![napalm99](https://avatars.discourse-cdn.com/v4/letter/n/a587f6/32.png) [@napalm99](https://discourse.nodered.org/u/napalm99)\
**Post date:** [31 March 2020 23:09 UTC](https://discourse.nodered.org/t/day-night-device-duty-cycle/23936/5 "2020-03-31T23:09:23Z")

</div>

Thank you! Your flow really helped me to understand the usage of these nodes! Now I'm playing with it, gonna do some tests. I'll let you know if it can get the job done.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [31 March 2020 23:45 UTC](https://discourse.nodered.org/t/day-night-device-duty-cycle/23936/6 "2020-03-31T23:45:50Z")

</div>

> [@napalm99](#):
>
> Daytime Duty Cycle :  
> -Turn ON a device for 15 min then OFF for 15 min. (Repeat from 6 AM to 6 PM).
> 
> Nighttime Duty Cycle:  
> -Turn ON a device for 15 min then OFF for 1 Hour and 45 min. (Repeat from 6 PM to 6 AM).

This can be achieved by 1 node  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/6/c6c9f07a4f029b4abd516b4af022857124d265c5.png)

Let me simplify...  
Daytime Duty Cycle :

- Turn ON a device for 15 min then OFF for 15 min. (Repeat from 6 AM to 6 PM).

**is the same as**

- Send ON every 30 mins starting at 0 mins past the hour between 6am and 6pm
- Send OFF every 30 mins starting at 15 mins past the hour between 6am and 6pm

Nighttime Duty Cycle:

- Turn ON a device for 15 min then OFF for 1 Hour and 45 min. (Repeat from 6 PM to 6 AM).

**is the same as**

- Send ON every 120 mins starting at 0 mins past the hour between 6pm and 6am
- Send OFF every 120 mins starting at 15 mins past the hour between 6pm and 6am

 ![ILO4BAXNZH](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/d/9d239c3cbe9c8cdeb6983d00db9ca61cb348c3cc.gif)

```auto
[{"id":"6543c46d.aaafac","type":"cronplus","z":"5da5bc89.9d65a4","name":"","outputField":"payload","timeZone":"","commandResponseMsgOutput":"output1","outputs":1,"options":[{"expressionType":"cron","topic":"day_on","payload":"on","type":"str","expression":"0 0/30 6-17 * * * *","location":"","offset":"0"},{"expressionType":"cron","topic":"day_off","payload":"off","type":"str","expression":"0 15/30 6-17 * * * *","location":"","offset":"0"},{"expressionType":"cron","topic":"night_on","payload":"on","type":"str","expression":"0 0/120 18-5 * * * *","location":"","offset":"0"},{"expressionType":"cron","topic":"night_off","payload":"off","type":"str","expression":"0 15/120 18-5 * * * *","location":"","offset":"0"}],"x":240,"y":120,"wires":[[]]}]

```

NOTE: This uses [node-red-contrib-cron-plus](http://flows.nodered.org/node/node-red-contrib-cron-plus)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [1 April 2020 01:04 UTC](https://discourse.nodered.org/t/day-night-device-duty-cycle/23936/7 "2020-04-01T01:04:00Z")

</div>

Yes, that is nice, but how does it deal with the dynamic sunrise and sunset times?

---

<div class="post-metadata">

**Author:** ![napalm99](https://avatars.discourse-cdn.com/v4/letter/n/a587f6/32.png) [@napalm99](https://discourse.nodered.org/u/napalm99)\
**Post date:** [1 April 2020 01:30 UTC](https://discourse.nodered.org/t/day-night-device-duty-cycle/23936/8 "2020-04-01T01:30:44Z")

</div>

It's difficult to synchronize Big Timer with other nodes. Non-dynamic timings should work, though it will require adjustment every now and then when dawn/dusk hour change. The final goal is to make a variable Duty Cycle Timer that can be synchronized with Big Timer. This project has a lot of potential and I think it has a LOT of applications, from Industrial IoT to Home Automation. I will test both flows and see what happens. Thank you all for your replies.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 April 2020 01:34 UTC](https://discourse.nodered.org/t/day-night-device-duty-cycle/23936/9 "2020-04-01T01:34:03Z")

</div>

I didn't see a request to handle dynamic sunrise/sunset times.

The op said

> Daytime Duty Cycle :  
> -Turn ON a device for 15 min then OFF for 15 min. (Repeat from 6 AM to 6 PM).

> Nighttime Duty Cycle:  
> -Turn ON a device for 15 min then OFF for 1 Hour and 45 min. (Repeat from 6 PM to 6 AM).

And that's what I offered. Nothing more, nothing less.

* * *

Ps, in the git repo version (to be published soon) sunrise and sunset capabilities have been added.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [1 April 2020 03:11 UTC](https://discourse.nodered.org/t/day-night-device-duty-cycle/23936/10 "2020-04-01T03:11:25Z")

</div>

Sincerest apologies.

You are right.

I am stuck with sunrise/set times and it just translated to this thread because I saw day and night mentioned.

---

<div class="post-metadata">

**Author:** ![napalm99](https://avatars.discourse-cdn.com/v4/letter/n/a587f6/32.png) [@napalm99](https://discourse.nodered.org/u/napalm99)\
**Post date:** [5 April 2020 00:53 UTC](https://discourse.nodered.org/t/day-night-device-duty-cycle/23936/11 "2020-04-05T00:53:51Z")

</div>

Got a question Steve, on your night schedule, although it is set to send every 120mins, it sends a "on message" every hour. I'm having trouble finding what is causing this. Any ideas?

![nightschedule](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/7/b72b6843d7741d20f0e7797c321999ad63d88072.jpeg)

I'm getting these debug messages right now:

![debug](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/4/144b14e493f201586a82248b6f11ae2ae161cbb5.jpeg)

Would you mind explaining expression format? So I can tweak some of the values?.  
Thank you for your time.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [5 April 2020 09:08 UTC](https://discourse.nodered.org/t/day-night-device-duty-cycle/23936/12 "2020-04-05T09:08:05Z")

</div>

My apologies - i was wrong, the cron describer (in the tooltip) shouldn't parse that expression as the `m` (2nd element) is limited to 0-59 as can be see in the info panel on the side bar...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/c/4c1fcddf631320a1bc7d136caf59bcb5b6207123.png)

I'll look at that and update the node soon.

In the mean time, use the following expressions...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/4/d404024418ce8144af4a8a3e1b2e93ee24033a22.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/9/0907932d1e6e89674e6e226482570d8e34558815.png)

---

<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:** [4 June 2020 09:17 UTC](https://discourse.nodered.org/t/day-night-device-duty-cycle/23936/13 "2020-06-04T09:17:09Z")

</div>

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