Let script pause for few minutes

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
JeroenG
Posts: 27
Joined: Monday 06 January 2020 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 20231
Contact:

Let script pause for few minutes

Post by JeroenG »

Trying to build a script which calculates electricity costs based on variable pricing (per hour).

I have a script running which updates a domoticz device with the current price (updates every first minute of the hour). Because the price is updated at minute 0 of the hour, and the electricity usage is only available short after the hour I have a timing challenge.

My thoughts: Create as script which retreives the current price at minute 58 of the hour, pause for 5 minutes and then collect the usage of the past hour and calculate the costs.

In concept this looks ok to me, but how to have a dz-script waiting for 5 minutes? I could build this in bash, but would like to try putting it in Domoticz itself.

Thanks,
Jeroen
User avatar
jvdz
Posts: 2328
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Let script pause for few minutes

Post by jvdz »

JeroenG wrote: Sunday 08 January 2023 16:01 In concept this looks ok to me, but how to have a dz-script waiting for 5 minutes? I could build this in bash, but would like to try putting it in Domoticz itself.
You do not want any event script to pause/sleep as the event system is single threaded and any script running for longer than 10 seconds is killed.
So those steps need to be separate steps and the first one could set a persistent variable which is then used in the second script.
The whole think could also be put into one script with 2 triggers, and then do these steps base on the current time.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
JeroenG
Posts: 27
Joined: Monday 06 January 2020 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version: 20231
Contact:

Re: Let script pause for few minutes

Post by JeroenG »

jvdz wrote: Sunday 08 January 2023 16:13 You do not want any event script to pause/sleep as the event system is single threaded and any script running for longer than 10 seconds is killed.
This makes sense, did not think of it :-(. Splitting the script in 2 parts will then be the way to go.

Thanks!
Sarcas
Posts: 86
Joined: Wednesday 11 October 2017 8:50
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1ß
Location: Friesland
Contact:

Re: Let script pause for few minutes

Post by Sarcas »

Never tried this, but could you perhaps use a virtual switch and use light.switchOn().forMin(5) to turn it on for a few minutes and use that virtual switch as trigger device so you 'catch' it again after 5 minutes when it goes off, and then do the calculations you want...?
--

Domoticz on rPi4 - RFXCOM RFXtrx433 USB - ZW090 Z-Stick Gen5 EU - IKEA Tradfri - Philips HUE - YouLess meter - SolarEdge
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest