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.

Light scenes KNX
#1
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
Reply
#2
Why don't you just use Scene for this?
------------------------------
Ctrl+F5
Reply
#3
(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
Reply
#4
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
Reply
#5
(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
Best Regards,
Reply
#6
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.
Reply
#7
(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
Best Regards,
Reply
#8
(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?
Reply
#9
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
Reply
#10
(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
Reply
#11
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
Reply


Forum Jump: