Logic Machine Forum
Scenes Process - 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: Scenes Process (/showthread.php?tid=1998)



Scenes Process - sjfp - 01.04.2019

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.


RE: Scenes Process - admin - 03.04.2019

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)



RE: Scenes Process - sjfp - 04.04.2019

(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


RE: Scenes Process - admin - 04.04.2019

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)



RE: Scenes Process - sjfp - 05.04.2019

(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.


RE: Scenes Process - admin - 05.04.2019

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


RE: Scenes Process - sjfp - 08.04.2019

(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.


RE: Scenes Process - DGrandes - 27.05.2019

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


RE: Scenes Process - admin - 28.05.2019

There's no built-in function for that, you will have to use db queries to add scenes from a script.


RE: Scenes Process - ceddix - 10.08.2019

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.


RE: Scenes Process - admin - 12.08.2019

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")