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.

Simple event-based script
#1
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.
Reply
#2
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
Reply
#3
Smile 
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!
Reply
#4
It works, including the heating to standby Big Grin 

up to the next script Shy
Reply
#5
Does the command "os.sleep" stops the script or the complete "operating system"? so can i use this command for a longer delay?
Reply
#6
If i'm correct it stop only the script it's in. You can execute multiple script with os.sleep in each of them.
Reply
#7
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
Reply
#8
(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.
Reply
#9
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
Reply


Forum Jump: