Logic Machine Forum
Delaytime not os.sleep() - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Delaytime not os.sleep() (/showthread.php?tid=789)



Delaytime not os.sleep() - d25m07y1993 - 16.05.2017

Hi,
I need a delay time function other than Os.sleep (). I have a problem when using the Os.sleep (30) function for the lamp, when counting time to 10s I turn off the lights and turn it back after nearly 20s the lights are off ....
I want to interrupt the os.sleep () function in the script when disabled

Please help me .. Sad  

Tks


RE: Delaytime not os.sleep() - buuuudzik - 16.05.2017

How you interrupt the counting? By the same group address?


RE: Delaytime not os.sleep() - d25m07y1993 - 16.05.2017

(16.05.2017, 15:22)buuuudzik Wrote: How you interrupt the counting? By the same group address?

Hi buuuudzik,
I have a problem using Os.sleep..It still stores count values and I have no way to change that.

Example:
When the script "Sleep" is triggered: the wall light will light for 5 minutes and then turn off.

As time goes by 2 minutes: I turn on the script "Living": turn on the wall light and downlight.

3 minutes after wall light off ...
------------ This is the problem that I encountered, this annoys me.

Plz help me, thank you very much


RE: Delaytime not os.sleep() - buuuudzik - 16.05.2017

For me the easiest solution is using Resident script. You can trigger resident script by some event.
Code:
grp.write('0/0/5', true)
os.sleep(10)
grp.write('0/0/5', false)

When you switch off the resident script it stops working without finishing script.


RE: Delaytime not os.sleep() - Erwin van der Zwart - 16.05.2017

Hi,

Event based scripts are running in parallel when executed multiple times. To avoid this you need to kill the previous instance of the script. Try using this  and fill it up with your original script and make sure to use a unique storage name for each script you use it in:

Code:
-- check if previous script needs to be killed
storage_name = 'PID_SCRIPT_1'
tpid = storage.get(storage_name)  
if tpid == nil then
   pid = os.getpid()
   storage.set(storage_name, pid)
else
   pid = os.getpid()  
   storage.set(storage_name, pid)  
   os.kill(tpid, signal.SIGKILL)
end

-- put here your script with os.sleep
os.sleep(10)
-- end of your scrript

-- clean up storage
storage.delete(storage_name)

BR,

Erwin


RE: Delaytime not os.sleep() - admin - 16.05.2017

This might help:
http://forum.logicmachine.net/showthread.php?tid=43


RE: Delaytime not os.sleep() - d25m07y1993 - 17.05.2017

Hi,
I try to try again in many ways.
Thank you very much Big Grin