Need help with a flow

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

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

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?

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.

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

Why not use the simple "delay" node?

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.

This should do the trick - node-red-contrib-countdown (node) - Node-RED

2 Likes

Thank you I try this

/Martin

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.

@ smcgann99 this should work, what to use to control the seconds left? Any tips for a newbie :slight_smile:

Can you explain more what you mean ?

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

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

Thank you i try it out tomorrow and test it

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

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.