Posts: 3
Threads: 1
Joined: Aug 2021
Reputation:
0
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
Posts: 4643
Threads: 24
Joined: Aug 2017
Reputation:
207
Why don't you just use Scene for this?
------------------------------
Ctrl+F5
Posts: 3
Threads: 1
Joined: Aug 2021
Reputation:
0
25.08.2021, 08:49
(This post was last modified: 25.08.2021, 08:50 by lf96player.)
(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
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
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
Posts: 321
Threads: 72
Joined: Jan 2021
Reputation:
0
(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,
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
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.
Posts: 321
Threads: 72
Joined: Jan 2021
Reputation:
0
(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,
Posts: 3
Threads: 1
Joined: Aug 2021
Reputation:
0
(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?
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
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
Posts: 92
Threads: 16
Joined: Jan 2020
Reputation:
2
(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%?
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
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
|