Hi everyone,
I recently started using a little bit more Node-RED in my HA, and stumbled upon a problem that I couldn’t solve with a simple google search so here I am:
I am trying to set up a ‘delay node’ that will be controlled via Lovelace via home assistant helpers. I have set up an automation helper called “Fan duration” and I can read its values in node-red via state changed node. My main automation is a simple action that starts a fan every two hours and then turns it off after 30 seconds. I want to customize those 30 seconds to be easily changeable via lovelace.
Current situation: Main loop works well, the fan starts every 2 hours and turns off after 30 seconds. Changing the state of “fan duration” results in sending a msg.delay to delay node and an expected delay of X seconds.
Two issues here:
- The delay node starts upon receiving the msg.delay - it should only start upon receiving the signal from the ‘main loop’ / ‘store’ the value from state changed node
- The supplied msg.delay isn’t taken into account when delay node is triggered via the ‘svc: switch:turn_on’ aka the main loop and uses the default 30 seconds
Here is my flow:
[{"id":"577f93c7.ee91bc","type":"debug","z":"a56901d8.cb95c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"delay","targetType":"msg","statusVal":"","statusType":"auto","x":1050,"y":280,"wires":[]},{"id":"77cee045.4b177","type":"server-state-changed","z":"a56901d8.cb95c","name":"State changed: Fan duration","server":"3d0bc4e7.618a6c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.air_exchanges_per_day","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":280,"y":220,"wires":[["764e28d.2a67cd8"]]},{"id":"b8eccb98.3ae318","type":"delay","z":"a56901d8.cb95c","name":"variable delay","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":820,"y":360,"wires":[["577f93c7.ee91bc","1e60f318.6f084d"]]},{"id":"764e28d.2a67cd8","type":"change","z":"a56901d8.cb95c","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"delay","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":280,"wires":[["7a4008c7.c7f258"]]},{"id":"7a4008c7.c7f258","type":"function","z":"a56901d8.cb95c","name":"Multiply msg.delay * 1000","func":"msg.delay = msg.delay * 1000;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":550,"y":280,"wires":[["b8eccb98.3ae318"]]},{"id":"d65b8954.6bae08","type":"api-call-service","z":"a56901d8.cb95c","name":"","server":"3d0bc4e7.618a6c","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.air_exchange_intake_fan","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":570,"y":360,"wires":[["b8eccb98.3ae318"]]},{"id":"1e60f318.6f084d","type":"api-call-service","z":"a56901d8.cb95c","name":"","server":"3d0bc4e7.618a6c","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.air_exchange_intake_fan","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1070,"y":360,"wires":[[]]},{"id":"b5be1798.4a4de8","type":"inject","z":"a56901d8.cb95c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":340,"y":360,"wires":[["d65b8954.6bae08"]]},{"id":"92ba5148.16d","type":"inject","z":"a56901d8.cb95c","name":"Run every 2h","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"3600","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":320,"y":440,"wires":[["d65b8954.6bae08"]]},{"id":"3d0bc4e7.618a6c","type":"server","name":"Home Assistant","addon":true}]
Sorry if this is a basic question, I just can’t figure this out and would appreciate some pointers. Thank you!