Setting a variable value in msg.delay of a trigger node

When my lock become unlocked, I would like to use a trigger node that will relock the door after a certain number of minutes. I would like the msg.dealy to do so. The delay (in minutes) is store in a input.number helper (Home Assistant). I wish to take the state of the input.number (in minutes) and transform it in ms (*60000) and set it in the msg.dalay.
I do not want to use a fix value, because I have multiple locks with different autolock delay.

[{"id":"68f0521589e62f33","type":"api-current-state","z":"144c9bef.2833a4","name":"Get autolock Delay","server":"e447d17a.16a64","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_number.lock_1531_autolock_delay","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":0,"forType":"num","forUnits":"minutes","x":290,"y":3540,"wires":[["c9769ffb4f871fb4","4f0d29051c10df9d"]]},{"id":"c9769ffb4f871fb4","type":"change","z":"144c9bef.2833a4","name":"Set Delay","rules":[{"t":"move","p":"payload","pt":"msg","to":"delay","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":3540,"wires":[["0ce9bb6c8578bccf","4bf6c40d36b1de65"]]},{"id":"4f0d29051c10df9d","type":"debug","z":"144c9bef.2833a4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":510,"y":3460,"wires":[]},{"id":"0ce9bb6c8578bccf","type":"debug","z":"144c9bef.2833a4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":3460,"wires":[]},{"id":"0caf4c2450378708","type":"inject","z":"144c9bef.2833a4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":110,"y":3540,"wires":[["68f0521589e62f33"]]},{"id":"4bf6c40d36b1de65","type":"trigger","z":"144c9bef.2833a4","name":"Delay","op1":"","op2":"lock","op1type":"nul","op2type":"str","duration":"1","extend":false,"overrideDelay":true,"units":"min","reset":"lock","bytopic":"topic","topic":"door","outputs":1,"x":670,"y":3540,"wires":[["025d53d5455df831","a35a56f7540b72de"]]},{"id":"025d53d5455df831","type":"debug","z":"144c9bef.2833a4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":850,"y":3460,"wires":[]},{"id":"a35a56f7540b72de","type":"api-call-service","z":"144c9bef.2833a4","name":"Lock the door","server":"e447d17a.16a64","version":5,"debugenabled":false,"domain":"lock","service":"lock","areaId":[],"deviceId":[],"entityId":["lock.lock_1531_2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":860,"y":3540,"wires":[["f43355f2837f3bc0"]]},{"id":"f43355f2837f3bc0","type":"debug","z":"144c9bef.2833a4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1030,"y":3540,"wires":[]},{"id":"e447d17a.16a64","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

It doesn't help using the nodes, but I see what you are doing.

It works and the way to get a variable time is to change the value to a flow context value.

Where you are moving msg.payload to msg.delay.
Make it something like this:

[{"id":"c9769ffb4f871fb4","type":"change","z":"7e987ddf260bdf0d","name":"Set Delay","rules":[{"t":"move","p":"time_for_this_lock","pt":"flow","to":"delay","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":3620,"wires":[["0ce9bb6c8578bccf","4bf6c40d36b1de65"]]}]

Make the flow name better than the one I used, but for the sake of explaining I hope you get what I mean.

And you wouldn't move it.... Rather you would set.
Sorry.

You can use JSONata in the change node to multiply the minutes by 60000. Is the payload of the state node a string or a number

e,g

[{"id":"0caf4c2450378708","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":60,"y":700,"wires":[["68f0521589e62f33"]]},{"id":"68f0521589e62f33","type":"api-current-state","z":"bf9e1e33.030598","name":"Get autolock Delay","server":"e447d17a.16a64","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_number.lock_1531_autolock_delay","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":0,"forType":"num","forUnits":"minutes","x":240,"y":700,"wires":[["c9769ffb4f871fb4","4f0d29051c10df9d"]]},{"id":"c9769ffb4f871fb4","type":"change","z":"bf9e1e33.030598","name":"Set Delay","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number($$.payload)*60000","tot":"jsonata"},{"t":"move","p":"payload","pt":"msg","to":"delay","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":700,"wires":[["0ce9bb6c8578bccf","4bf6c40d36b1de65"]]},{"id":"4f0d29051c10df9d","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":460,"y":620,"wires":[]},{"id":"0ce9bb6c8578bccf","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":620,"y":620,"wires":[]},{"id":"4bf6c40d36b1de65","type":"trigger","z":"bf9e1e33.030598","name":"Delay","op1":"","op2":"lock","op1type":"nul","op2type":"str","duration":"1","extend":false,"overrideDelay":true,"units":"min","reset":"lock","bytopic":"topic","topic":"door","outputs":1,"x":620,"y":700,"wires":[["025d53d5455df831","a35a56f7540b72de"]]},{"id":"025d53d5455df831","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":800,"y":620,"wires":[]},{"id":"a35a56f7540b72de","type":"api-call-service","z":"bf9e1e33.030598","name":"Lock the door","server":"e447d17a.16a64","version":5,"debugenabled":false,"domain":"lock","service":"lock","areaId":[],"deviceId":[],"entityId":["lock.lock_1531_2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":810,"y":700,"wires":[["f43355f2837f3bc0"]]},{"id":"f43355f2837f3bc0","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":980,"y":700,"wires":[]}]

Also what id msg.door?

Hi, I am not sure if the payload is a string or a number. Within the object of the debug node, it is display as [delay: "3.0"]. I try different JSON entry in the change node without success. For example [payload * 60000] or [{{payload}} * 60000] both give an error message [Invalid To JSON property]. I am not a programmer and I don't very much about creating JSON code.
As far as msg.door; this is a left over of my original flow where multiple door are using the same routine and each one have is own trigger. Multiple delays at the same time for multiple door.

I try to set the value payload of my [current state node ] to flow.delay. I got [NaN] in this flow.delay when I look into the context page.

Please show the whole msg object, so we know if it's msg.delay or msg.payload.delay. Use the copy value button in the debug sidebar to the left to the msg object, it will appear when you hover the cursor there. set the debug to show the complete message object. Place the debug after the state input node.

here it is

{"_msgid":"f6998a5234526177","payload":"3.0","topic":"input_number.lock_1531_autolock_delay"}

hoping I did it right.

Try this , I tried to post earlier, but looks like i only posted the api node by mistake.

[{"id":"0caf4c2450378708","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":60,"y":700,"wires":[["68f0521589e62f33"]]},{"id":"68f0521589e62f33","type":"api-current-state","z":"bf9e1e33.030598","name":"Get autolock Delay","server":"e447d17a.16a64","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_number.lock_1531_autolock_delay","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":0,"forType":"num","forUnits":"minutes","x":240,"y":700,"wires":[["c9769ffb4f871fb4","4f0d29051c10df9d"]]},{"id":"c9769ffb4f871fb4","type":"change","z":"bf9e1e33.030598","name":"Set Delay","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number($$.payload)*60000","tot":"jsonata"},{"t":"move","p":"payload","pt":"msg","to":"delay","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":700,"wires":[["0ce9bb6c8578bccf","4bf6c40d36b1de65"]]},{"id":"4f0d29051c10df9d","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":460,"y":620,"wires":[]},{"id":"0ce9bb6c8578bccf","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":620,"y":620,"wires":[]},{"id":"4bf6c40d36b1de65","type":"trigger","z":"bf9e1e33.030598","name":"Delay","op1":"","op2":"lock","op1type":"nul","op2type":"str","duration":"1","extend":false,"overrideDelay":true,"units":"min","reset":"lock","bytopic":"topic","topic":"door","outputs":1,"x":620,"y":700,"wires":[["025d53d5455df831","a35a56f7540b72de"]]},{"id":"025d53d5455df831","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":800,"y":620,"wires":[]},{"id":"a35a56f7540b72de","type":"api-call-service","z":"bf9e1e33.030598","name":"Lock the door","server":"e447d17a.16a64","version":5,"debugenabled":false,"domain":"lock","service":"lock","areaId":[],"deviceId":[],"entityId":["lock.lock_1531_2"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":810,"y":700,"wires":[["f43355f2837f3bc0"]]},{"id":"f43355f2837f3bc0","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":980,"y":700,"wires":[]}]

I think I found my initial mistake. My edit current state node 'Get auto lock Delay' state type was set as String instead of Number.

Now I need to find out how to set a msg.mydelay with the value of the payload [in minutes]. What would be a JSON way to do it?

Resolved. In edit change node, is set msg.waitfor to JSON msg.delay * 60000.
From there on I can set my trigger node with is value.
Thank to you, for helping to find a solution to my initial challenge.

1 Like

You would have needed to set it else where in the flow.

The initial number (in minutes)is set in Home Assistant into an input_number helpers.
I get this value in a 'edit current state node' with a 'state type' set to number.
Then I calculate the msg.delay in a 'edit change node' with JSON 'msg.payload * 60000'.
This is then connected to the 'edit trigger node' where is delay is made and finally my door get lock.
Unfortunately, I cannot provide my flow because it contain many other elements (example should I send a message or not; it is within a period of automatic locking or now). All of them use template because my flow control multiples locks. Each one with its own variable.
Let me know if I can help you further

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