This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Cancel the saved command line after the os.sleep() command
#1
Hi guys ! I am having a problem, and want to solve it. I have the following code:
--------------------------------------
value = event.getvalue()
if value==true then
  os.sleep(60) --1p
  grp.write('6/1/18',false)
end
--------------------------------------
When I enable the value 6/1/18 it runs 60 seconds then 6/1/18==false. In some cases I want to be on 6/1/18=true, then on the 50th second I'm 6/1/18==false, on the 55th I'm 6/1/18=true, and I want it = =true forever. But after 5 seconds, it turned off 6/1/18=false(automatically), because the initial command it saved for 1 minute was =false . So I want when I activate it, it only saves the last command line, not the previous command lines. For example, I wrote the following:
-------------------------------------
value = event.getvalue()
if value==true then
  os.sleep(60) --1p
  grp.write('6/1/18',false)
end
break;
---------------------------------------
Is it right?

Thank so much ! everyone Smile
Reply
#2
As I see here you are using event script and same object triggers the script and and you write to the same object which is triggering the script again. Lucky it will run only once as you have the condition there. The only way to stop event script is to kill PID which you can see in staircase timer example on the forum. https://forum.logicmachine.net/showthrea...75#pid4175

Why don't you do it like this
https://forum.logicmachine.net/showthrea...3#pid22863
------------------------------
Ctrl+F5
Reply
#3
Hello Daniel !
I tried killing PID, but it gives error, do you know what is the error?
"User script:6: bad argument #1 to 'kill' (number expected, got nil)
stack traceback:
[C]: in function 'kill'
User script:6: in main chunk"
------------------event 6/1/18----
-- object mapped to this event must have its data type set
value = event.getvalue()
pid = os.getpid()
oldpid = storage.get('MyPID')
if oldpid ~= pid then
os.kill(oldpid, signal.SIGKILL)
os.sleep(60)
grp.write('6/1/18',false)
storage.set('MyPID', pid)
end
---------------------------------
Am I writing like this? I want that every 60 seconds without effect, it will be ==false. And if there is an impact, for example, the 55th second, if it has an effect, it will reset the time to be counted as 60 seconds later ==false
Thank so much!
Reply
#4
Use this:
Code:
key = 'pid_' .. event.dst

pid = storage.get(key)
if pid then
  os.kill(pid, signal.SIGKILL)
end

value = event.getvalue()
if value then
  storage.set(key, os.getpid())
  os.sleep(60)
  grp.write(event.dst, false)
end

storage.delete(key)
Reply
#5
Are there other options to abort just the os.sleep command and let the script run further? Many thanks.
Reply
#6
@pioneersteffen, what do you want to achieve with this? One solution is a loop that checks the current object value with short sleeps in between. But if the object value toggles twice quickly the script won't be able to catch it. Another option is to use a resident script like in this example: https://forum.logicmachine.net/showthrea...5#pid27075
Reply
#7
For example I want to set the presence in the house to the status inactive if there is no movement in the house for 180s. Therefore I made short sleeps, reread the presence object, check the object (no movement present), next sleep etc. That‘s why I was wondering if there is a better approach to stop a long sleep interrupt?
Reply
#8
This example will stop previously running script when an object is updated again: https://forum.logicmachine.net/showthrea...2#pid27062
Reply
#9
Many thanks I will try this solution.
Reply
#10
Hi everyone ..!
I have solved it ..Thank so much..Admin and everyone.
..Smile
Reply


Forum Jump: