Some basic (?) scripting questions

Hi,

I’m about to automate some scenes and was hoping for a little (?) help getting me started. I know there are some code snippets, but I was hoping for something a little more specific.

This is what I was thinking of:

  1. get lux level, normalize to 0-100 (don’t know if it’ll report the amount of lux or if it steps from 1-100 yet)
  2. If some event, like media player playing or lux level over 80% (probably won’t be able to blind anyone over this level), jump to 4
  3. dim lights to level x, where x is normalized lux level * some multiplier ← this will be a work in progress for some time in order to make sure the lights in my glass cabinets don’t burn your eyes out in dark light conditions
  4. code to start some other scene (mom always told me not to make a scene - guess Vera showed her! :stuck_out_tongue: ) or continue with the scene’s auto generated stuff

Is this doable?

I think you’ll want to look up PLEG; it is a plug in that supports very complex if/then/else scenarios.

However I have LUUP code a on a scene that is similar to what you need. This checks a light’s status and if it’s on, turns it off. If it’s off, turns it on. It should get you started.


local device=40 ----bulb id
local switchOnOff = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, device)

if (switchOnOff == “1”) then
– Switch is on
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “0”}, device)
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },device)
else
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },device)
luup.call_action(“urn:upnp-org:serviceId:Dimming1”, “SetLoadLevelTarget”, {newLoadlevelTarget = “100”}, device)

end