Posts: 99
Threads: 39
Joined: Apr 2018
Reputation:
0
Hi, looking for some help.
What I want to try is to have a way of changing the groups levels in scenes, without effecting the current lighting levels.
Like having an OFF Line area to adjust and save scene values. But only get called the next time the particular scene is called.
Example, a store OPEN scene sets lighting cir's 1=50% 2=70% 3=40% etc.
Then we need to adjust those values to say cir's 1=75% 2=20% 3=80% but they cant effect the current lighting levels is the store until the next time the OPEN scene is pressed.
Any help would be appreciated.
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
Here's a function you can use. Scene name which values you want to modify must be unique for it to work correctly.
Code: function setscenevalues(name, values)
local json = require('json')
local sceneid = db:getone('SELECT id FROM scenes WHERE name=?', name)
sceneid = tonumber(sceneid)
if not sceneid then
return nil, 'scene not found'
end
for addr, value in pairs(values) do
local ga = buslib.encodega(addr)
local update = { value = json.encode(value) }
local where = { scene = sceneid, object = ga }
db:update('scene_sequence', update, where)
end
scene.reload()
return true
end
name = 'my scene name'
values = {
['32/1/1'] = 1,
['32/1/2'] = 2,
['32/1/3'] = 3,
}
res, err = setscenevalues(name, values)
log(res, err)
Posts: 99
Threads: 39
Joined: Apr 2018
Reputation:
0
(03.04.2019, 07:49)admin Wrote: Here's a function you can use. Scene name which values you want to modify must be unique for it to work correctly.
Code: function setscenevalues(name, values)
local json = require('json')
local sceneid = db:getone('SELECT id FROM scenes WHERE name=?', name)
sceneid = tonumber(sceneid)
if not sceneid then
return nil, 'scene not found'
end
for addr, value in pairs(values) do
local ga = buslib.encodega(addr)
local update = { value = json.encode(value) }
local where = { scene = sceneid, object = ga }
db:update('scene_sequence', update, where)
end
scene.reload()
return true
end
name = 'my scene name'
values = {
['32/1/1'] = 1,
['32/1/2'] = 2,
['32/1/3'] = 3,
}
res, err = setscenevalues(name, values)
log(res, err)
Thank you for the script works great, how can I add the ramp rate like 4seconds or 8 seconds to the level
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
You need to specify value as a table. You can get this table format like this:
Code: value = grp.getvalue('32/1/1', dt.cbus)
log(value)
Posts: 99
Threads: 39
Joined: Apr 2018
Reputation:
0
(04.04.2019, 13:03)admin Wrote: You need to specify value as a table. You can get this table format like this:
Code: value = grp.getvalue('32/1/1', dt.cbus)
log(value)
Admin, thank you. Sorry could you explain how to implement, not sure on wow to use tables etc.
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
Try this:
Code: values = {
['32/1/1'] = { target = 75, ramprate = 8 },
['32/1/2'] = { target = 50, ramprate = 8 },
['32/1/3'] = { target = 25, ramprate = 8 },
}
If it does not work try replacing target key name with level or value
Posts: 99
Threads: 39
Joined: Apr 2018
Reputation:
0
(05.04.2019, 09:42)admin Wrote: Try this:
Code: values = {
['32/1/1'] = { target = 75, ramprate = 8 },
['32/1/2'] = { target = 50, ramprate = 8 },
['32/1/3'] = { target = 25, ramprate = 8 },
}
If it does not work try replacing target key name with level or value
Thank you. Worked with the target and ramprate.
Posts: 237
Threads: 31
Joined: May 2018
Reputation:
2
Hi,
I have to create a lot of scenes, and I want to do that by lua, in the same way as "group.create" function. It's possible to do that?
Thanks
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
There's no built-in function for that, you will have to use db queries to add scenes from a script.
Posts: 3
Threads: 1
Joined: Jun 2019
Reputation:
0
Hi,
I'm new to this functions and scripting.
This function would be perfect to a new project i'm working on now.
The setup i want to show the end user, is like a visualization site to change values to a scene and then save with a button.
So im out on deep water, and really could need some help that someone could describe where like to put the scirpt above, and how proceed to get all working.
Is it in "common functions", and how to do the setup in the visualization site?
Sorry for the questions, i hope someone have the patience to describe.
Posts: 7758
Threads: 42
Joined: Jun 2015
Reputation:
447
If you want to save current values for a pre-defined scene then you only need a simple event script. Create a Boolean object and assign an event script to it, change MY_SCENE_NAME to your scene name.
Code: scene.savelive("MY_SCENE_NAME")
|