Node Red timer with time set from Home assistant

Hi,
Im trying to get a timer in node red that will trigger based on a the minutes set in text box in Home Assistant in one of my dashboards. I can turn on the relay with a time node, but cannot turn the relay off after x minutes set from home assistant.
Any help would be greatly appreciated.

Thanks Danny

image

[{"id":"9a10fdeb0b6ebd6c","type":"ha-time","z":"ffbd7f06.4a014","name":"Turn on","server":"","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityId":"sensor.timer","property":"state","offset":0,"offsetType":"num","offsetUnits":"minutes","randomOffset":false,"repeatDaily":false,"payload":"$entity().state","payloadType":"jsonata","debugenabled":false,"x":144,"y":2688,"wires":[["a828badc6c2750d7"]]},{"id":"47bd8d542db1f28c","type":"ha-time","z":"ffbd7f06.4a014","name":"Turn off","server":"","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityId":"sensor.timer","property":"state","offset":"$entities(\"input_number.duration\").state","offsetType":"jsonata","offsetUnits":"minutes","randomOffset":false,"repeatDaily":false,"payload":"$entity().state","payloadType":"jsonata","debugenabled":false,"x":146,"y":2736,"wires":[["a828badc6c2750d7"]]},{"id":"a828badc6c2750d7","type":"api-call-service","z":"ffbd7f06.4a014","name":"","server":"","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.relay","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":330,"y":2688,"wires":[[]]}]

[{"id":"9a10fdeb0b6ebd6c","type":"ha-time","z":"ffbd7f06.4a014","name":"Turn on","server":"","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityId":"sensor.timer","property":"state","offset":0,"offsetType":"num","offsetUnits":"minutes","randomOffset":false,"repeatDaily":false,"payload":"$entity().state","payloadType":"jsonata","debugenabled":false,"x":144,"y":2688,"wires":[["a828badc6c2750d7"]]},{"id":"a828badc6c2750d7","type":"api-call-service","z":"ffbd7f06.4a014","name":"","server":"","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.relay","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":330,"y":2688,"wires":[["d809ddf12a011f9d"]]},{"id":"cafdb451477a8a07","type":"delay","z":"ffbd7f06.4a014","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":844,"y":2688,"wires":[["f9be2f6edb971c20"]]},{"id":"d809ddf12a011f9d","type":"api-current-state","z":"ffbd7f06.4a014","name":"","server":"","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_number.duration","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"delay","propertyType":"msg","value":"$number($entity().state) * 60000","valueType":"jsonata"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":598,"y":2688,"wires":[["cafdb451477a8a07"]]},{"id":"f9be2f6edb971c20","type":"api-call-service","z":"ffbd7f06.4a014","name":"","server":"","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.relay","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1034,"y":2688,"wires":[[]]}]

If you set a value in your input text, it automatically triggers. If you update the value of your input while the timer is running, the timer will get updated. If you set it to 0, it’ll stop. If you set a string, it won’t do anything.

[{"id":"72386163.88be5","type":"server-state-changed","z":"c6dd4022.7c84","name":"Input text","server":"9405c3fe.d0a6c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_text.your_input","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":200,"y":360,"wires":[["a38da304.58bbf"]]},{"id":"a38da304.58bbf","type":"change","z":"c6dd4022.7c84","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"str","to":"0.00000000001","tot":"str"},{"t":"set","p":"delay","pt":"msg","to":"$number(payload)*60*1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":360,"wires":[["7cd25ad.e9514a4"]]},{"id":"7cd25ad.e9514a4","type":"trigger","z":"c6dd4022.7c84","name":"","op1":"","op2":"","op1type":"pay","op2type":"pay","duration":"250","extend":true,"overrideDelay":true,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":485,"y":360,"wires":[["9358b86e.9d8108"],["b43d8841.9c8248"]],"l":false},{"id":"9358b86e.9d8108","type":"api-call-service","z":"c6dd4022.7c84","name":"relay on","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":590,"y":340,"wires":[[]]},{"id":"b43d8841.9c8248","type":"api-call-service","z":"c6dd4022.7c84","name":"relay off","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":590,"y":380,"wires":[[]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","addon":true}]

Sory guys for not getting back to you and thanks for the above advice. I did mange to get it working by doing something like this, but not sure if what have done was exactly right.
I do need to add a function node (or other node) after the first time node to stop the flow should it not meet the bolean requirement for the day of operation, eg not set to run on monday etc.

[{"id":"7a1b589d332eb2a5","type":"tab","label":"Flow 12","disabled":true,"info":""},{"id":"b3952025102ed885","type":"ha-time","z":"7a1b589d332eb2a5","name":"","server":"e7f83bdc.15f068","version":0,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityId":"input_datetime.only_time1","property":"state","offset":0,"offsetType":"num","offsetUnits":"minutes","randomOffset":false,"repeatDaily":false,"payload":"$entity().state","payloadType":"jsonata","debugenabled":false,"x":190,"y":140,"wires":[["54eb289f58bd8abe","9c811d6a6d3b4b51"]]},{"id":"54eb289f58bd8abe","type":"api-call-service","z":"7a1b589d332eb2a5","name":"Relay 1 on","server":"e7f83bdc.15f068","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.relay_1","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":990,"y":100,"wires":[[]]},{"id":"649e2d441ca7a6f0","type":"api-call-service","z":"7a1b589d332eb2a5","name":"Relay 1 off","server":"e7f83bdc.15f068","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.relay_1","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":990,"y":180,"wires":[[]]},{"id":"439c73b992bd1f26","type":"api-call-service","z":"7a1b589d332eb2a5","name":"Relay 2 on","server":"e7f83bdc.15f068","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.relay_2","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1010,"y":300,"wires":[[]]},{"id":"e02e8dd481a7ab25","type":"api-call-service","z":"7a1b589d332eb2a5","name":"Relay 2 off","server":"e7f83bdc.15f068","version":3,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.relay_2","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1010,"y":420,"wires":[[]]},{"id":"535333d30bfbb89d","type":"ha-wait-until","z":"7a1b589d332eb2a5","name":"","server":"e7f83bdc.15f068","version":0,"outputs":2,"entityId":"switch.relay_1","entityIdFilterType":"exact","property":"context.id","comparator":"is","value":"on","valueType":"str","timeout":"$round($number($globalContext(\"homeassistant.homeAssistant.states['input_number.relay1_runtime_1'].state\")))","timeoutType":"jsonata","timeoutUnits":"minutes","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":580,"y":400,"wires":[[],["e02e8dd481a7ab25"]]},{"id":"9c811d6a6d3b4b51","type":"ha-wait-until","z":"7a1b589d332eb2a5","name":"","server":"e7f83bdc.15f068","version":0,"outputs":2,"entityId":"switch.relay_1","entityIdFilterType":"exact","property":"context.id","comparator":"is","value":"on","valueType":"str","timeout":"$round($number($globalContext(\"homeassistant.homeAssistant.states['input_number.relay1_runtime_1'].state\")))","timeoutType":"jsonata","timeoutUnits":"minutes","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":600,"y":180,"wires":[[],["439c73b992bd1f26","535333d30bfbb89d","649e2d441ca7a6f0"]]},{"id":"e7f83bdc.15f068","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}] 

I tried the following for the function node but did not work

[{"id":"45fa8931a015c6c3","type":"tab","label":"Flow 7","disabled":false,"info":""},{"id":"a1d9470d505dd25e","type":"function","z":"45fa8931a015c6c3","name":"","func":"var d=new Date()\nvar weekday=d.getDay()\nif (weekday == 5 && \"input_boolean.saturday1\" == true)\n{\n    msg.payload =\"on\";\n{\n    elseif\n    msg.payload =\"off\";\n}\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":240,"y":240,"wires":[[]]}]