Logic Machine Forum
How to control event based script - 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: How to control event based script (/showthread.php?tid=1607)



How to control event based script - 02dag - 22.09.2018

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


RE: How to control event based script - Erwin van der Zwart - 22.09.2018

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


RE: How to control event based script - 02dag - 23.09.2018

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?


RE: How to control event based script - Erwin van der Zwart - 23.09.2018

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


RE: How to control event based script - 02dag - 24.09.2018

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.


RE: How to control event based script - Domoticatorino - 04.10.2018

(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.


RE: How to control event based script - Erwin van der Zwart - 04.10.2018

Hi,

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

BR,

Erwin