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



Simple event-based script - Superjohn - 07.02.2017

Hi for me scripting is completely new, I have some tutorials followed but should really start doing it.

But to make the first start I find difficult.

Could someone help me with a simple script that I can build on through?

I'm looking for an "event-based script" that:

call's a scene,
waits a few seconds,
and call's the next scene

Can anyone help me get started? Or is this question too simple for this forum?

Thx John.


RE: Simple event-based script - Erwin van der Zwart - 07.02.2017

Hi,

I assume your scenes are stored in your KNX actuators so try this:

Code:
grp.write('1/1/1', 0) -- call scene 1
os.sleep(3) -- wait a few seconds
grp.write('1/1/1', 2) -- call scene 3

Rookie info (: -> Make sure the byte object (in this sample '1/1/1') that is used for your scenes is created in the controller, otherwise this script won't send it to the bus.

BR,

Erwin


RE: Simple event-based script - Superjohn - 08.02.2017

Thx!, That looks very simple Big Grin 

Scene object is 0/1/0 so that i will cover.
Ill try to get it working and than try to ad the next step; setting the heating to nightstatus.

It is for going to bed, is now one scene, want to make scene to put on lights upstairs on first, and shut down lights downstairs a lttle later.

I think I have to add:
Code:
grp.write('3/6/1', 3) -- status heating to standby

I going to test!


RE: Simple event-based script - Superjohn - 13.02.2017

It works, including the heating to standby Big Grin 

up to the next script Shy


RE: Simple event-based script - Superjohn - 24.02.2017

Does the command "os.sleep" stops the script or the complete "operating system"? so can i use this command for a longer delay?


RE: Simple event-based script - mlaudren - 24.02.2017

If i'm correct it stop only the script it's in. You can execute multiple script with os.sleep in each of them.


RE: Simple event-based script - Erwin van der Zwart - 25.02.2017

Hi,

os.sleep only stops the script where it is used, for event based scripts take into account that each event  creates a new script procedure, so if you use os.sleep in a event based script you might have multiple instances of this script running in parallel. We have a small script to kill the previous script with os.sleep to avoid this.

BR,

Erwin


RE: Simple event-based script - Superjohn - 20.01.2018

(25.02.2017, 08:09)Erwin van der Zwart Wrote: Hi,

os.sleep only stops the script where it is used, for event based scripts take into account that each event  creates a new script procedure, so if you use os.sleep in a event based script you might have multiple instances of this script running in parallel. We have a small script to kill the previous script with os.sleep to avoid this.

BR,

Erwin

Hi Erwin,


where can I find this small script?
 
I want to start a toilet ventilation.
After light goes on wait for 1 minute then turn on ventilation for 2 minutes.
 
It would be possible somebody else goes to the toilet in that time.
 
Or maybe better turn on ventilation when light goes out.



Thanks John.


RE: Simple event-based script - Erwin van der Zwart - 20.01.2018

Hi,

Try this as event based on your light switching object:
Code:
value = event.getvalue()
if value == false then
 storagename = 'toilet_pid'
 oldpid = storage.get(storagename)
 pid = os.getpid()
 storage.set(storagename, pid)  
 if oldpid ~= nil then  
   os.kill(oldpid, signal.SIGKILL)
 end
 grp.write('1/1/2', true) -- Ventilator object
 os.sleep(120)
  grp.write('1/1/2', false) -- Ventilator object
 storage.remove(storagename)
end
BR,

Erwin