Nodered making Auto Start Generator

hi i made nodered automation but i not 100% sure if i made it right… to detect if hydro is right wait 5 min if the power is out check if the power is still out if it still is then run the steps… i remember someone saying i shouldnt use delay it hangs but i wasnt sure how to use the trigger node as a delay… so i could use help this is what i got so far

[{"id":"b3afeaf7337c498c","type":"poll-state","z":"227346dedf06f0cc","name":"Line Voltage","server":"915baa48.9b1898","version":3,"exposeAsEntityConfig":"","updateInterval":"60","updateIntervalType":"num","updateIntervalUnits":"seconds","outputInitially":true,"outputOnChanged":false,"entityId":"sensor.bar_basement_lights_voltage","stateType":"num","ifState":"","ifStateType":"str","ifStateOperator":"is","outputs":1,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":70,"y":820,"wires":[["719b8ab0aaae9db7"]]},{"id":"719b8ab0aaae9db7","type":"switch","z":"227346dedf06f0cc","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"gte","v":"100","vt":"str"},{"t":"eq","v":"stop","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":250,"y":820,"wires":[["23af0d09ee369b25"],[],["dfc5719d35cbba60"]]},{"id":"2876e20dd0c32aae","type":"change","z":"227346dedf06f0cc","name":"Auto Turn On Generator","rules":[{"t":"set","p":"device","pt":"msg","to":"Generator_Back_Building","tot":"str"},{"t":"set","p":"command","pt":"msg","to":"Remote 2 Start","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":800,"wires":[["623f81b8c9cf4d8e"]]},{"id":"5e88c3890c2152d7","type":"trigger","z":"227346dedf06f0cc","name":"Check Every 5 Min For Line Voltage","op1":"ALARM","op2":"0","op1type":"str","op2type":"str","duration":"-5","extend":false,"overrideDelay":false,"units":"min","reset":"stop","bytopic":"all","topic":"topic","outputs":1,"x":300,"y":940,"wires":[["719b8ab0aaae9db7"]]},{"id":"23af0d09ee369b25","type":"delay","z":"227346dedf06f0cc","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":400,"y":800,"wires":[["9a357065351d94dd"]]},{"id":"ef338b148133c977","type":"poll-state","z":"227346dedf06f0cc","name":"Line Voltage","server":"915baa48.9b1898","version":3,"exposeAsEntityConfig":"","updateInterval":"60","updateIntervalType":"num","updateIntervalUnits":"seconds","outputInitially":true,"outputOnChanged":false,"entityId":"sensor.bar_basement_lights_voltage","stateType":"num","ifState":"100","ifStateType":"num","ifStateOperator":"gte","outputs":2,"outputProperties":[{"property":"payload","propertyType":"msg","value":"stop","valueType":"str"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":70,"y":940,"wires":[["5e88c3890c2152d7"],[]]},{"id":"623f81b8c9cf4d8e","type":"function","z":"227346dedf06f0cc","name":"Broadlink RM4 Pro Bedroom","func":"msg.entity =\"remote.broadlink_rm4_pro_bedroom\"\nmsg.hold_secs = \"2\"\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1160,"y":800,"wires":[["251d4449e72059a7"]]},{"id":"251d4449e72059a7","type":"api-call-service","z":"227346dedf06f0cc","name":"Send Remote Commands","server":"915baa48.9b1898","version":5,"debugenabled":false,"domain":"remote","service":"send_command","areaId":[],"deviceId":[],"entityId":[],"data":"{\t    \"device\": msg.device,\t    \"command\": msg.command,\t    \"entity_id\": msg.entity,\t    \"hold_secs\": msg.hold_secs\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1150,"y":840,"wires":[[]]},{"id":"9a357065351d94dd","type":"api-call-service","z":"227346dedf06f0cc","name":"Fuel Switch On","server":"915baa48.9b1898","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.generator_2_building_fuel_switch"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":560,"y":800,"wires":[["04b8377b86e523cd"]]},{"id":"04b8377b86e523cd","type":"delay","z":"227346dedf06f0cc","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":720,"y":800,"wires":[["2876e20dd0c32aae"]]},{"id":"dfc5719d35cbba60","type":"api-call-service","z":"227346dedf06f0cc","name":"Fuel Switch Off","server":"915baa48.9b1898","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.generator_2_building_fuel_switch"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":560,"y":860,"wires":[["6d9ffd2ae93f4e18"]]},{"id":"6d9ffd2ae93f4e18","type":"delay","z":"227346dedf06f0cc","name":"","pauseType":"delay","timeout":"10","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":730,"y":860,"wires":[["494755b026b71853"]]},{"id":"494755b026b71853","type":"api-call-service","z":"227346dedf06f0cc","name":"Turn Off Generator","server":"915baa48.9b1898","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.generator_2_building_fuel_servo_power","switch.generator_2_building_power_remote_starter"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":910,"y":860,"wires":[[]]},{"id":"fb06290cc822fb63","type":"comment","z":"227346dedf06f0cc","name":"Start Generator Info inside","info":"Checks every 5 Min for Hydro out\nif hydro out for 5 Min\nwait 5 min \nTurn On Fuel Value\nWait 2 Min For Fuel bowl to fill up\nStart Machine","x":590,"y":760,"wires":[]},{"id":"725cd102d91d57d5","type":"comment","z":"227346dedf06f0cc","name":"Stop Generator Info inside","info":"Checks every 5 Min for Hydro out or not\nif hydro back on after 5 Min\nTurn off Fuel Value\nlets Generator run till out of Fuel\n\nWait 10 Min For Fuel bowl to empty\nTurn Off Generator Power\nTurn off Servo Power\n","x":590,"y":900,"wires":[]},{"id":"6922402f91b9a30a","type":"comment","z":"227346dedf06f0cc","name":"Generator 2 (Back Building)","info":"","x":120,"y":760,"wires":[]},{"id":"915baa48.9b1898","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

i noticed it doesnt do what i also want tit to do
if it detects power is out for 5 min… and it starts its delay 5 min before it starts the generator… i want it to check 1 more time to see if power is back on or not if its not on continue… if its back on then cancel… i think u you do that with the trigger node but i not sure

It looks like you’re not using the best choice of nodes, and making life harder for yourself. The “events: state” node is generally used to trigger a flow when the state of an entity changes. I don’t fully understand what you’re trying to achieve, though. It would be helpful if you explained what outcomes you want for different events.

  • If line voltage is zero, you want to wait 5 minutes and turn the fuel switch on plus other stuff. This is clear and could be achieved with an “events: state” node, and setting “if state is” to 0, while also changing the state type to “number”. You could also omit the delay node by setting “for 5 minutes” in the same node. This is more consistent with your stated aim to “wait 5 min if the power is out check if the power is still out”. With your current code it does not recheck the line voltage is still zero after 5 minutes. Using the “for 5 minutes” will not trigger the flow until the line voltage has remained at 0 for 5 minutes. You’d also want to confirm that when the power goes out the line voltage goes to 0 and stays that way, rather than going to unavailable or unknown.

  • If the line voltage is 100+ you want to do nothing? There’s no condition for 0-100, so those states will do nothing too. I’m not clear on what’s going on here. (but then further down I’m making an assumption about this)

  • You have a condition where the payload is “stop”, but it looks like it should be “ALARM” as this is what the trigger is sending. You have “stop” in the trigger, but that’s to reset the trigger if it receives “stop” as the payload. And I assume the payload from line voltage will never be “stop”. I don’t know what you’re trying to do here. It looks like every 5 minutes you want the fuel switch to turn off again, but I doubt that is the case. Under what conditions are you wanting to turn the fuel switch off?

Assuming all you want to is detect the power is out for 5 minutes and then start the generator, then that can be done with just the first bullet point above - no need for delay or trigger nodes. I’m guessing that given you’ve got code to turn the generator off, if the line voltage is over 100 and the generator is on, it means power is back on so you want to turn the generator off. You could do this with another “events: state” node triggering if line voltage is 100+ for 10 minutes, and then check the “current state” of the generator is on, and if so, turn it off.

Something like this:

image

[{"id":"66bc3ffbd15b08bd","type":"server-state-changed","z":"ff2a2ce.5863ad","name":"Line Voltage 0 for 5m","server":"5c211963.f91a88","version":5,"outputs":2,"exposeAsEntityConfig":"","entityIdType":"exact","outputInitially":false,"stateType":"num","ifState":"0","ifStateType":"num","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"5","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":260,"y":3560,"wires":[["f6654fae5e3febbb"],[]]},{"id":"f6654fae5e3febbb","type":"api-call-service","z":"ff2a2ce.5863ad","name":"Fuel Switch On","server":"915baa48.9b1898","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_on","areaId":[],"deviceId":[],"entityId":["switch.generator_2_building_fuel_switch"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":500,"y":3560,"wires":[[]]},{"id":"f0da07fcf12b2432","type":"server-state-changed","z":"ff2a2ce.5863ad","name":"Line Voltage 100+ for 10m","server":"5c211963.f91a88","version":5,"outputs":2,"exposeAsEntityConfig":"","entityIdType":"exact","outputInitially":false,"stateType":"num","ifState":"100","ifStateType":"num","ifStateOperator":"gte","outputOnlyOnStateChange":true,"for":"10","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":270,"y":3640,"wires":[["b9b7f1193db08f03"],[]]},{"id":"b9b7f1193db08f03","type":"api-current-state","z":"ff2a2ce.5863ad","name":"Generator on ?","server":"5c211963.f91a88","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":500,"y":3640,"wires":[["fd83c0be57b04706"],[]]},{"id":"fd83c0be57b04706","type":"api-call-service","z":"ff2a2ce.5863ad","name":"Fuel Switch Off","server":"915baa48.9b1898","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.generator_2_building_fuel_switch"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":700,"y":3640,"wires":[[]]},{"id":"5c211963.f91a88","type":"server","name":"Home Assistant","version":5,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true},{"id":"915baa48.9b1898","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

And btw the delay node does not “hang” - other flows will run as expected. However, if you’re using delay for anything more that seconds, it’s possibly a sign you’re using the wrong approach.