# Need help with a flow

**URL:** <https://discourse.nodered.org/t/need-help-with-a-flow/61122>\
**Category:** General\
**Tags:** home-assistant\
**Created:** [11 April 2022 13:48 UTC](https://discourse.nodered.org/t/need-help-with-a-flow/61122 "2022-04-11T13:48:37Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![tellblom](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tellblom/32/59924_2.png) [@tellblom](https://discourse.nodered.org/u/tellblom)\
**Post date:** [11 April 2022 13:48 UTC](https://discourse.nodered.org/t/need-help-with-a-flow/61122/1 "2022-04-11T13:48:37Z")

</div>

Using Node Red in HomeAssistant and need some help with a flow.  
To be fair I am quite new to Node Red 🙂

To understand what I want to do I have created this flowchart

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/b/6b93c848da24697650b3a3c71a570d71676e8d96.jpeg)

The problem I have is setting a timer? How do I set a timer for 1 hour and how can I check if that timer still counting down?

---

<div class="post-metadata">

**Author:** ![ch-zacmo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ch-zacmo/32/59923_2.png) [@ch-zacmo](https://discourse.nodered.org/u/ch-zacmo)\
**Post date:** [11 April 2022 14:48 UTC](https://discourse.nodered.org/t/need-help-with-a-flow/61122/2 "2022-04-11T14:48:42Z")

</div>

Hi

I created this. It's a counter and it add 1 every second until it reach 3600 then the msg.payload become true.  
You can check if it is counting by checking the msg.value (current elapsed time in sec.) or with the msg.work (true if it's counting).

Hope this help.

```auto
[{"id":"c7ea6ebf.518a6","type":"function","z":"eeca8943.a75718","name":"","func":"// Retrieve local data\n\nvar count=context.get('count') || 0;\n\n// retrieve flow data\nvar work=flow.get('work') || false;\n\n// Timer count if work set to true true\n\nif (work == true){\ncount += 1;\n}\n\n// Timer reset AND stop if set to false\nif (work == \"reset\") {\n count = 0\n flow.set('work', false)\n}\n\n// Output true if timer elapsed one hour\nif (count >= 3600) {\n result = true\n} \nelse {\n result = false\n}\n\nmsg = {topic : \"Timer\", payload : result, value : count, work : work};\n\n\ncontext.set('count',count);\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":620,"wires":[["2c5a09fb.3e49c6"]]},{"id":"1d202705.5e5209","type":"inject","z":"eeca8943.a75718","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":470,"y":620,"wires":[["c7ea6ebf.518a6"]]},{"id":"2c5a09fb.3e49c6","type":"debug","z":"eeca8943.a75718","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":790,"y":620,"wires":[]},{"id":"e195ecff.f1fa3","type":"inject","z":"eeca8943.a75718","name":"Start","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":450,"y":700,"wires":[["abb86b89.e34bd8"]]},{"id":"2dad53d4.17e7cc","type":"inject","z":"eeca8943.a75718","name":"Stop","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":450,"y":760,"wires":[["abb86b89.e34bd8"]]},{"id":"abb86b89.e34bd8","type":"change","z":"eeca8943.a75718","name":"","rules":[{"t":"set","p":"work","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":700,"wires":[[]]},{"id":"4d4ca73f.66ab18","type":"inject","z":"eeca8943.a75718","name":"Reset (and stop)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"reset","payloadType":"str","x":470,"y":820,"wires":[["abb86b89.e34bd8"]]}]

```

---

<div class="post-metadata">

**Author:** ![manjha](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/manjha/32/29301_2.png) [@manjha](https://discourse.nodered.org/u/manjha)\
**Post date:** [11 April 2022 14:52 UTC](https://discourse.nodered.org/t/need-help-with-a-flow/61122/3 "2022-04-11T14:52:58Z")

</div>

Why not use the simple "delay" node?

---

<div class="post-metadata">

**Author:** ![ch-zacmo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ch-zacmo/32/59923_2.png) [@ch-zacmo](https://discourse.nodered.org/u/ch-zacmo)\
**Post date:** [11 April 2022 14:59 UTC](https://discourse.nodered.org/t/need-help-with-a-flow/61122/4 "2022-04-11T14:59:41Z")

</div>

I thought about this one but you can't have a feedback of it's value and if it's counting as far as I know.

But It would certainly be a less complicated solution.

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [11 April 2022 15:17 UTC](https://discourse.nodered.org/t/need-help-with-a-flow/61122/5 "2022-04-11T15:17:01Z")

</div>

This should do the trick - [node-red-contrib-countdown (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-countdown)

---

<div class="post-metadata">

**Author:** ![tellblom](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tellblom/32/59924_2.png) [@tellblom](https://discourse.nodered.org/u/tellblom)\
**Post date:** [11 April 2022 15:36 UTC](https://discourse.nodered.org/t/need-help-with-a-flow/61122/6 "2022-04-11T15:36:40Z")

</div>

Thank you I try this

/Martin

---

<div class="post-metadata">

**Author:** ![tellblom](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tellblom/32/59924_2.png) [@tellblom](https://discourse.nodered.org/u/tellblom)\
**Post date:** [11 April 2022 15:38 UTC](https://discourse.nodered.org/t/need-help-with-a-flow/61122/7 "2022-04-11T15:38:57Z")

</div>

I check the timer and another value and if one of them false it continue.  
With a delay it always waits for an hour regardless of the other value.

---

<div class="post-metadata">

**Author:** ![tellblom](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tellblom/32/59924_2.png) [@tellblom](https://discourse.nodered.org/u/tellblom)\
**Post date:** [11 April 2022 16:45 UTC](https://discourse.nodered.org/t/need-help-with-a-flow/61122/8 "2022-04-11T16:45:05Z")

</div>

@ [smcgann99](https://discourse.nodered.org/u/smcgann99) this should work, what to use to control the seconds left? Any tips for a newbie 🙂

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [11 April 2022 16:49 UTC](https://discourse.nodered.org/t/need-help-with-a-flow/61122/9 "2022-04-11T16:49:50Z")

</div>

Can you explain more what you mean ?

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [11 April 2022 18:08 UTC](https://discourse.nodered.org/t/need-help-with-a-flow/61122/10 "2022-04-11T18:08:21Z")

</div>

Try this I think it should do what you need without any "fancy" nodes 😉

```auto
[{"id":"c28848d3008f38d5","type":"inject","z":"624963ed82f87a01","name":"5min between 09:00 and 20:00","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"*/1 9-19 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":360,"y":700,"wires":[["7f7292690d5c1168"]]},{"id":"444c14aca6976e26","type":"debug","z":"624963ed82f87a01","name":"Pump control","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1290,"y":700,"wires":[]},{"id":"c4b419c7fd8b6ced","type":"inject","z":"624963ed82f87a01","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":270,"y":620,"wires":[["3fa6faf007d72053"]]},{"id":"7e9db50b81f3dd1f","type":"inject","z":"624963ed82f87a01","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":270,"y":660,"wires":[["3fa6faf007d72053"]]},{"id":"3fa6faf007d72053","type":"change","z":"624963ed82f87a01","name":"","rules":[{"t":"set","p":"1700W","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":640,"wires":[[]]},{"id":"10bd5d3afd799371","type":"trigger","z":"624963ed82f87a01","name":"","op1":"true","op2":"false","op1type":"bool","op2type":"bool","duration":"1","extend":false,"overrideDelay":false,"units":"hr","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":950,"y":680,"wires":[["a243eea030dfb0f6"]]},{"id":"7f7292690d5c1168","type":"switch","z":"624963ed82f87a01","name":"","property":"1700W","propertyType":"flow","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":590,"y":700,"wires":[["5d3aa52641be23b5"],["3699c8e7c703400f"]]},{"id":"3699c8e7c703400f","type":"change","z":"624963ed82f87a01","name":"Not enough power","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":870,"y":740,"wires":[["a243eea030dfb0f6"]]},{"id":"5d3aa52641be23b5","type":"delay","z":"624963ed82f87a01","name":"","pauseType":"rate","timeout":"30","timeoutUnits":"seconds","rate":"1","nbRateUnits":"2","rateUnits":"hour","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":false,"outputs":1,"x":760,"y":680,"wires":[["10bd5d3afd799371"]]},{"id":"a243eea030dfb0f6","type":"rbe","z":"624963ed82f87a01","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":1130,"y":700,"wires":[["444c14aca6976e26"]]}]

```

---

<div class="post-metadata">

**Author:** ![tellblom](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tellblom/32/59924_2.png) [@tellblom](https://discourse.nodered.org/u/tellblom)\
**Post date:** [11 April 2022 19:12 UTC](https://discourse.nodered.org/t/need-help-with-a-flow/61122/11 "2022-04-11T19:12:53Z")

</div>

Thank you i try it out tomorrow and test it

---

<div class="post-metadata">

**Author:** ![tellblom](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tellblom/32/59924_2.png) [@tellblom](https://discourse.nodered.org/u/tellblom)\
**Post date:** [12 April 2022 08:18 UTC](https://discourse.nodered.org/t/need-help-with-a-flow/61122/12 "2022-04-12T08:18:05Z")

</div>

This was my solution I tried.... Your is soo much cleaner

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/6/b68fcecd5b3f39f28e77d35f9009efef27b2a26b.png)

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [12 April 2022 15:04 UTC](https://discourse.nodered.org/t/need-help-with-a-flow/61122/13 "2022-04-12T15:04:57Z")

</div>

It's easy to get carried away. I just broke it down in to relevant parts.

time range - inject node makes this easy  
power - store as flow variable, makes it easy to compare in switch node  
1 hour on 1 hour off - 2 hour delay node with 1 hour trigger to flip flop

If this works for you can you mark the solution.

---

<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:** [11 June 2022 15:05 UTC](https://discourse.nodered.org/t/need-help-with-a-flow/61122/14 "2022-06-11T15:05:09Z")

</div>

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