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.

Staircase timer
#1
Being new to LUA I´m finding it difficult to get everything right. Could some one help me with below.?? Please Huh

I have tried to create a simple Staircase timer for lighting control with the following functions:

1bit KNX command = true activates (From presence detector)

(1.) Sends a KNX Byte value  "90%"

(2.) After not receiving (1bit from presence detector) in 30 min send KNX byte value 20%

(3.) After not receiving (1bit from presence detector) in 60 min send KNX byte value 0%

(( If triggered by 1bit from presence detector it should re-trigger the staircase timer.))

I need to run multiple staircase timers for different areas with the same LM unit.!
Reply
#2
(03.08.2017, 08:05)Kuronen Wrote: Being new to LUA I´m finding it difficult to get everything right. Could some one help me with below.?? Please Huh

I have tried to create a simple Staircase timer for lighting control with the following functions:

1bit KNX command = true activates (From presence detector)

(1.) Sends a KNX Byte value  "90%"

(2.) After not receiving (1bit from presence detector) in 30 min send KNX byte value 20%

(3.) After not receiving (1bit from presence detector) in 60 min send KNX byte value 0%

(( If triggered by 1bit from presence detector it should re-trigger the staircase timer.))

I need to run multiple staircase timers for different areas with the same LM unit.!
Hi!
here is example. but its not good to use so big os.sleep timer in event based script
just add event based script for your presense sensor group address

Code:
scale_adress= '1/1/4'
value = event.getvalue()
storage_name = 'staircase '..event.dst
if value then
 -- writing 100% to scale object
 grp.write(scale_adress, 100)
 -- getting object info
 obj = grp.find(event.dst)
 
 --getting update time of presense sensor in seconds
 upd_time = obj.updatetime
 --setting this update time to storage
 storage.set(storage_name, upd_time)

 --(watinng for 40 minutes)
 os.sleep (40*60)
 -- checking if the sensor was updated
 n_obj = grp.find(event.dst)
 n_upd_time = n_obj.updatetime
 old_upd_time = storage.get(storage_name)
 -- if update times does not equal - exiting from script
 if n_upd_time ~= old_upd_time then
   return
 end
 -- if times are equal writing 20
 grp.write(scale_adress, 20)
 -- wating for 20 minutes
 os.sleep (20*60)
 -- again checking update time
 n_obj = grp.find(event.dst)
 n_upd_time = n_obj.updatetime
 old_upd_time = storage.get(storage_name)
 -- if update times does not equal - exiting from script
 if n_upd_time ~= old_upd_time then
   return
 end
 -- if stil equal write 0
 grp.write(scale_adress, 0)
 
end
Reply
#3
Thanks for the quick response, I got this to almost work.

Issues i have are thus: If "" scale_adress= 'x/x/x' "" has no previous value the script will not write "100" until a value is written once. (problem if power goes out) ""

Also for every PIR-trigger that is sent a new event based script is started which puts everything out of sync.

Should it be a resident script instead?
Reply
#4
Hi,

Check this article:

https://forum.logicmachine.net/showthrea...75#pid4175

BR,

Erwin
Reply
#5
Thanks Erwin,

I found that and started from there. But with my limited experience of LUA, and no need or possibility to write values since these are fixed it seemed to komplex for me att this point of time. But if that is the only way then i have to go down that road ;-) . The function i wanted to achieve is usually only a couple of mouse-clicks away with KNX-devices, and i have no spent hours in trying to get this to work. :-( .
Reply
#6
Ok Guys,

I copied it straight off and put it in an event based script. But i do not get it to work. Could some one help me with a step by step explanation on how to proceed to get this script to work? Erwin??

The shorter basic scripts I made work.
Reply
#7
Hi,

Did you put it as event linked to the same address as the input address you have set in the start of the script?

I pointed out this script as it holds the function to kill a previous running script by store the program id and kill previous pid on next execution.

BR,

Erwin
Reply
#8
Yes

Event 6/0/0 also tired other adresses

-- Set input address
AddressInput = '6/0/0'

/J
Reply
#9
Create an event script for each PIR. It will only react when PIR sends true. In this case it will store current time in storage under unique key and will set output value to 90% if it's not already 90%. This is done by using checkwrite which does not pollute the bus with telegrams with duplicate values. Adjust output group address for each PIR script as needed.
Code:
if event.getvalue() then
  key = 'pir_timer_' .. event.dst
  now = os.time()
  storage.set(key, now)
  grp.checkwrite('2/1/1', 90)
end

Create a resident script which will monitor PIR timers and will set output values as needed. Tune sleep interval as needed, don't use 0, otherwise it will consume all system resources. If you really need to wait 30/60 minutes after last movement detection then you can use maximum sleep time of 60 seconds. You can add as many elements to pirs table as needed, input is PIR group address, output is your dimmer. You need to disable/enable the script if you change pirs table.
Code:
if not pirs then
  pirs = {
    { input = '1/1/1', output = '2/1/1' },
    { input = '1/1/2', output = '2/1/2' },
  }
end

now = os.time()
for _, pir in ipairs(pirs) do
  key = 'pir_timer_' .. pir.input
  delta = now - storage.get(key, 0)

  -- set output to 0% after 1 hour
  if delta > 60 * 60 then
    grp.checkwrite(pir.output, 0)
  -- set output to 20% after 30 minutes
  elseif delta > 30 * 60 then
    grp.checkwrite(pir.output, 20)
  end
end
Reply


Forum Jump: