Logic Machine Forum
Light scenes KNX - 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: Light scenes KNX (/showthread.php?tid=3524)



Light scenes KNX - lf96player - 25.08.2021

Hi,

I wanted to make a scene where I have three lights (later more lights). It should first dim one light from 0% to 100%, after that another one, and finally the last one. Objects that I have for lights are on/off, dim, value, on/off status and value status. Perhaps I only need value and value status objects. Can anyone help me how to write the script in lua? Script should be called when I press the button on touch panel or at a certain time of day.

Thanks


RE: Light scenes KNX - Daniel - 25.08.2021

Why don't you just use Scene for this?


RE: Light scenes KNX - lf96player - 25.08.2021

(25.08.2021, 08:29)Daniel. Wrote: Why don't you just use Scene for this?

I am using SpaceLYnk, and I can't find option to make it dim to 100%, and after that to start another light to do the same thing. I want to time for dimming of one light to be like 3-5s


RE: Light scenes KNX - admin - 25.08.2021

This example will dim 3 lights from 0% to 100% in 10% steps with 0.2 seconds delay between each step. You can adjust the step/delay as needed and also add new group addresses to the list.
Code:
step = 10
delay = 0.2
addrs = { '32/1/15', '32/1/16', '32/1/17' }

for _, addr in ipairs(addrs) do
  obj = grp.find(addr)
  for value = 0, 100, step do
    obj:write(value)
    os.sleep(delay)
  end
end



RE: Light scenes KNX - khalil - 25.08.2021

(25.08.2021, 09:26)admin Wrote: This example will dim 3 lights from 0% to 100% in 10% steps with 0.2 seconds delay between each step. You can adjust the step/delay as needed and also add new group addresses to the list.
Code:
step = 10
delay = 0.2
addrs = { '32/1/15', '32/1/16', '32/1/17' }

for _, addr in ipairs(addrs) do
  obj = grp.find(addr)
  for value = 0, 100, step do
    obj:write(value)
    os.sleep(delay)
  end
end
excuse me admin dor this question, it's for learning.
why do you use grp.find.
could we use grp.write(add,value) instead


RE: Light scenes KNX - admin - 25.08.2021

It's a tiny bit faster since each grp.write call requires a database query. You can also use grp.write(addr, value, dt.scale) so no query is needed as the datatype is set directly.


RE: Light scenes KNX - khalil - 25.08.2021

(25.08.2021, 09:39)admin Wrote: It's a tiny bit faster since each grp.write call requires a database query. You can also use grp.write(addr, value, dt.scale) so no query is needed as the datatype is set directly.

thank you for this info


RE: Light scenes KNX - lf96player - 25.08.2021

(25.08.2021, 09:26)admin Wrote: This example will dim 3 lights from 0% to 100% in 10% steps with 0.2 seconds delay between each step. You can adjust the step/delay as needed and also add new group addresses to the list.
Code:
step = 10
delay = 0.2
addrs = { '32/1/15', '32/1/16', '32/1/17' }

for _, addr in ipairs(addrs) do
  obj = grp.find(addr)
  for value = 0, 100, step do
    obj:write(value)
    os.sleep(delay)
  end
end

Thanks for your response. 

How can I make it go like that and then opposite. When the third light reaches 100%, then it should dim to 0%, then the second should dim to 0%, and then first. And how to make a loop that the whole process repeats again, and how to stop that loop?


RE: Light scenes KNX - admin - 27.08.2021

Create a resident script with sleep time set to 0 and set the script name to light scene
Code:
step = 10
delay = 0.2

addrs = { '32/1/15', '32/1/16', '32/1/17' }

for _, addr in ipairs(addrs) do
  for value = 0, 100, step do
    grp.write(addr, value, dt.scale)
    os.sleep(delay)
  end
end

for i = #addrs, 1, -1 do
    addr = addrs[ i ]

  for value = (100 - step), 0, -step do
    grp.write(addr, value, dt.scale)
    os.sleep(delay)
  end  
end

Then you can create an event script (1-bit object) which can be used to turn the scene on and off:
Code:
value = event.getvalue()
if value then
  script.enable('light scene')
else
  script.disable('light scene')
end



RE: Light scenes KNX - victor.back - 12.03.2022

(27.08.2021, 07:37)admin Wrote: Create a resident script with sleep time set to 0 and set the script name to light scene
Code:
step = 10
delay = 0.2

addrs = { '32/1/15', '32/1/16', '32/1/17' }

for _, addr in ipairs(addrs) do
  for value = 0, 100, step do
    grp.write(addr, value, dt.scale)
    os.sleep(delay)
  end
end

for i = #addrs, 1, -1 do
    addr = addrs[ i ]

  for value = (100 - step), 0, -step do
    grp.write(addr, value, dt.scale)
    os.sleep(delay)
  end 
end

Then you can create an event script (1-bit object) which can be used to turn the scene on and off:
Code:
value = event.getvalue()
if value then
  script.enable('light scene')
else
  script.disable('light scene')
end

How can I get this script to dim the first groupadress 0-100%, and at the same time thr first groupadres dims from 100-0%, the second goupadress dims from 0-100%? Smile


RE: Light scenes KNX - admin - 15.03.2022

Try this:
Code:
step = 10
delay = 0.2

addrs = { '20/3/0', '20/3/1', '20/3/2', '20/3/3' }

for i = 1, #addrs + 1 do
  curr = addrs[ i ]
  prev = addrs[ i - 1 ]

  for value = 0, 100, step do
    if curr then
      grp.write(curr, value, dt.scale)
    end

    if prev then
      grp.write(prev, 100 - value, dt.scale)
    end

    os.sleep(delay)
  end
end