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.

How to control event based script
#1
I have a event based script, that turns off the toilet light after ten minutes. This is working very well, but I want to control the script so that if we have guests we can turn it on while the guests are here. The Gira tastsensor with three rows are somewhat difficult for everyone to read.

I have created a virtual object thet I can control with a mosaic widget. If I set it to off the script turns off the light after ten minutes. If I set it to on the lights stays on.

Problem is it is not working. Here is the script

value = event.getvalue(0/2/10)
keep_on = grp.getvalue(32/1/4)
if keep_on == false then
if value == true then
os.sleep(600)
grp.write('0/2/10', false)
end
end
Reply
#2
Hi,

Have not checked your script fully, but in the first lines i already see mistakes..

1) event.getvalue(0/2/10) needs to be event.getvalue() without any value passing to the function.

2) grp.getvalue(32/1/4) is missing the quotes and needs to be grp.getvalue(‘32/1/4’)

Your script will probably start to work better if you change these mistakes, but i expect you notice more problems as you use a os.sleep() in a event based script without script to avoid paralell execution.

This will probably not going to work as you expect..

BR,

Erwin
Reply
#3
I did what you told me and now the script works. Thank you very much. The new code look like this:

value = event.getvalue('0/2/10')
keep_on = grp.getvalue('32/1/4')
if keep_on == false then
if value == true then
os.sleep(600)
grp.write('0/2/10', false)
end
end

I didnt fully understand what you meant by number 1. Should you not insert which object you want to check in event.getvalue like I have done now?

Do you also have another and better method for waiting in the script?
Reply
#4
Hi,

event.getvalue() already knows it's current event.dst, so you don't need to pass a variable to the function.

This script below also kills a eventual parallel running script:
Code:
keep_on = grp.getvalue('32/1/4')
if keep_on == false then
  value = event.getvalue()
  if value == true then
     tpid = storage.get('PID:' .. _SCRIPTNAME)
     if tpid ~= nil then
        os.kill(tpid, signal.SIGKILL)
     end
     pid = os.getpid()  
     storage.set('PID:' .. _SCRIPTNAME, pid)
     os.sleep(600)
     grp.write(event.dst, false)
     storage.delete('PID:' .. _SCRIPTNAME)
  end
end
BR,

Erwin
Reply
#5
Thank you Erwin, I will try that new script. Much better to not have several parallell threads running, and I will use these lines in scripts in the future.

Yeah, I eventually understood that of course the entire script is mapped to an object so that is why you dont need this.
Reply
#6
(23.09.2018, 13:05)Erwin van der Zwart Wrote: Hi,

event.getvalue() already knows it's current event.dst, so you don't need to pass a variable to the function.

This script below also kills a eventual parallel running script:
Code:
keep_on = grp.getvalue('32/1/4')
if keep_on == false then
  value = event.getvalue()
  if value == true then
     tpid = storage.get('PID:' .. _SCRIPTNAME)
     if tpid ~= nil then
        os.kill(tpid, signal.SIGKILL)
     end
     pid = os.getpid()  
     storage.set('PID:' .. _SCRIPTNAME, pid)
     os.sleep(600)
     grp.write(event.dst, false)
     storage.delete('PID:' .. _SCRIPTNAME)
  end
end
BR,

Erwin

Hi Erwin,
just a clearify. This script above you mean to add in the same event base script created or we have to add another event base script?

Thanks.
Reply
#7
Hi,

The sample above includes the logic and the parallel script kill, so yes only 1 script is needed.

BR,

Erwin
Reply


Forum Jump: