Calculating Time / Washing Machine Notification

Hey Guys!
Im trying to get a notification 10 minutes before my washing machine is finishing. There was a remaining time sensor in the past (siemens home connect) but it isn't there anymore. The only sensor left, is a sensor with shows the actual end time of the program. So I put in a current state node and the payload is: 2021-11-03T14:07:53.797900+00:00. I thought about calculating the time difference between the time now and the programm end time and substract 10 minutes. What do you think? Is there a more convenient way to archive this or how would you do that?

Regards

You can use the Trigger node and pass in a delay in milliseconds. So you need to do the calculation to convert now - washingEnd into ms. You can do that in a function node or in a change node using JSONata. Send the resulting delay ms to the Trigger node and it will send a msg when the delay time expires.

If you are comfortable with JavaScript, you could also do it all in a function node using a setTimeout function.

1 Like

Or
A delay node set to use msg.delay as input then use a simle JSONata expression to calculate the delay
e.g.

[{"id":"3a357922.18ca1e","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2021-11-03T11:10:00.000000+00:00","payloadType":"str","x":160,"y":4840,"wires":[["586bd900.831e58"]]},{"id":"586bd900.831e58","type":"change","z":"b779de97.b1b46","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"$toMillis($$.payload) - $millis() - 600000","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":4860,"wires":[["ff4bd691.5eb148"]]},{"id":"ff4bd691.5eb148","type":"delay","z":"b779de97.b1b46","name":"","pauseType":"delayv","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":580,"y":4840,"wires":[["1e2cb213.f6f5be"]]},{"id":"1e2cb213.f6f5be","type":"debug","z":"b779de97.b1b46","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":560,"y":4940,"wires":[]}]
$toMillis($$.payload) - $millis() - 600000

set timestamp in inject to test

1 Like

I'm not familiar with coding at all. Just took snippets from here and adjusted them to my needs :-).

First question is how can i calculate the time: "payload time" - "now". In minutes or miliseconds? what is easier to do? So I imagine if the washer is finishing at 16.00 and now it is 14.00 then the result should be 120 minutes difference. And then the flow goes and somehow sends a notification if the value is 10?

Thank you

My example calculates how many milliseconds until 10 minutes before stop time. that figure is then used in delay/trigger node to delay message for that set amount of milliseconds.

1 Like

Hmm. Okay sorry I didn't fully understand what's going on there. Tried it like this:

Okay! the delay value is the value in ms until 10minutes before end? And this value sets the delay node to exact 10min before machine end?

You need to post the exported flow along with a inject node that contains the incoming msg from the HA node. That image is like going to a mechanic and saying my engine is not working and not opening the bonnet(hood). We need to see the expression used and other settings to

Thank you. Tried to kind of reverse engineered your flow and I think it works :-).

Will try to tinker around a little bit!

Is $millis() the expression for the current time?

Yes in milliseconds

1 Like

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