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.

Scenes Process
#1
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.
Reply
#2
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)
Reply
#3
(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
Reply
#4
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)
Reply
#5
(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.
Reply
#6
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
Reply
#7
(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.
Reply
#8
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
Reply
#9
There's no built-in function for that, you will have to use db queries to add scenes from a script.
Reply
#10
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.
Reply
#11
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")
Reply


Forum Jump: