What's the best way to handle a long-running script?

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

Moderator: leecollings

Post Reply
Timmiej93
Posts: 64
Joined: Saturday 26 December 2015 0:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

What's the best way to handle a long-running script?

Post by Timmiej93 »

I want to create my own wakeuplight script, which should be interruptible.

I started off writing a script that just queues up a lot of tasks by using light.dimTo(x).afterSec(y), with incrementing values for x and y, but this doesn't seem to work that great. As far as I know, this is also not interruptible, and will continue until all queued commands have been executed.

So my questions:
Is it possible to interrupt / cancel items queued by .afterSec(y)?
Is there a better way to have the script running for the entire duration, with the possibility to interrupt it?
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: What's the best way to handle a long-running script?

Post by dannybloe »

yes, either you wait for 2.4 which has a cancelQueuedCommands() on the device. Until then reissuing a command should clear the queue (device.setState(device.state)). But I'm not sure that always works as expected.

Other than that you can create a timer trigger like every minute and check against a time stamp (perhaps you set it in a uservariable in the gui) and read that value in your script. Perhaps in combination with persistent variables (see dzVents doc).

I know that allangam has scripts for exactly this situation. He's on the forum as well.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: What's the best way to handle a long-running script?

Post by emme »

dannybloe wrote: Friday 05 January 2018 14:41 yes, either you wait for 2.4 which has a cancelQueuedCommands() on the device.
Image
The most dangerous phrase in any language is:
"We always done this way"
Timmiej93
Posts: 64
Joined: Saturday 26 December 2015 0:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: What's the best way to handle a long-running script?

Post by Timmiej93 »

^^ Couldn't express it any better than that.

On the topic of allangam, I can't find him for the life of me, unfortunately. I think I'm gonna have to go back to bash for now (the horror...)
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: What's the best way to handle a long-running script?

Post by dannybloe »

Oops, his forum name is BakSeeDaa
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Timmiej93
Posts: 64
Joined: Saturday 26 December 2015 0:37
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: What's the best way to handle a long-running script?

Post by Timmiej93 »

That probably explains why that name came up a lot, lol. Thanks for the tip, I'll look into it.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest