I just started working on something similar.
Your link to http://wiki.micasaverde.com/index.php/Scripts_for_scenes is a great resource. I will have to roll it into my lighting logic.
I’m pretty new to Vera/LUUP scripting so I’m not qualified to directly answer your question. However to the issue of control based upon existing light levels, I thought I would share what I’ve created thus far. Like you, I want to avoid turning on lights based upon current lighting levels. In my case, I found it worked well to use the current outdoor ambient light level to decide when to permit indoor lights to activate.
Here’s how my solution looks. It contains three “modules”.
They are:
- “Add-In” module Variable Container provided by Geckotech’s. This provides a container to share ambient light levels to all other scense.
- Scene to capture and save valid ambient light level to the Variable container
- Scene (one per zone) to control lights. It uses the light levels saved in the Variable container to decide if lights should be permited.
Geckotech’s add-in is very handy not just for control, but trouble shooting as well. Besides light levels, I also use it to display temperatures from Google’s weather add-in.
I have a “HMS100 3-in-one sensor” mounted in the carport, protected from weather but exposed to outdoor light levels. I converted this device to run from AC power so as to make it easy to tap into it’s values at any time.
From Item #2 above, I created a scene to save valid light levels to the Variable container. It runs every 15 minutes and does NOT record value if car port light is currently on.
Here is the logic for this scene:
Step-1: Set the SCHEDULE to run every 15 minutes.
LUUP Code:
Step-1: Check if the Car Port light is currently on. If it’s on, the current light level is not correct, therefore I exit the scene.
Step-2: Cause the value of the HMS100 sensor to “refresh”. I dont want stale values.
luup.call_action(“urn:micasaverde-com:serviceId:HaDevice1”, “Poll”, {}, dev_carportsensor)
I have found it necessary to wait a bit for the values to refresh. Therefore I choose an arbitrary delay of 10 seconds before proceeding.
After the delay I call a function to grab the current light levels and store them in the Variable container, variable #1
NOTE: unrelated to this topic, you can see where I grab the Google Current and LOW temps for placement in the variable container’s slot 2 and 3.
Here is the code:
–~ This code resides in GetSunshineValue scene.
–~ ==========================================
–~ Version 1.06 1/21/2012
–~ Sequence of operation:
–~ Purpose:
–~ Record and hold value of outside light level while Garage light is OFF (to not spoil reading)
–~ If lights are on, preserve existing value.
local cur_sunshine
local dev_carport_lgt = 91
local dev_hallsconse = 92
local dev_varcontainer1 = 131
local dev_carport_lightlevel = 129
local dev_carportsensor = 127
local f_lightison
local googletemp
–~ This function refreshes Car Port Light & Motion Sensor
function getlight()
cur_sunshine =luup.variable_get(“urn:micasaverde-com:serviceId:LightSensor1”,“CurrentLevel”,dev_carport_lightlevel)
cur_sunshine = tonumber(cur_sunshine)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”,“Variable1”,cur_sunshine,dev_varcontainer1)
luup.variable_set(“HallSconce”, “SunshineVal”,cur_sunshine, dev_hallsconse)
end
– Get carport light status
f_lightison = luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”,“Status”, dev_carport_lgt)
f_lightison = tonumber(f_lightison)
– Get Google temp, put into Var3 as OSA Temp
local googletemp = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”, 63)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”,“Variable2”,googletemp,dev_varcontainer1) – Set Var 2 OSA temp
local googletemp = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”, 64)
luup.variable_set(“urn:upnp-org:serviceId:VContainer1”,“Variable3”,googletemp,dev_varcontainer1) – Set Var 2 Low Forecast
if (f_lightison == 1) then – If light currently on, do nothing as the Lgt Level value is tarnished by the Garge Lights
return false
else
– Poll light sensor, wait then update Variable1 with the new information
luup.call_action(“urn:micasaverde-com:serviceId:HaDevice1”, “Poll”, {}, dev_carportsensor)
luup.call_delay( ‘getlight’, 10)
return false
end
The above scene assures my variable container provides a current ambient light level for use in other scenes. The zone scene code looks like this.
–~ Car Port ON Scene Event Version 1.2
local cur_sunshine
local dev_varcontainer1 = 131
cur_sunshine = luup.variable_get(“urn:upnp-org:serviceId:VContainer1”,“Variable1”,dev_varcontainer1)
cur_sunshine = tonumber (cur_sunshine)
if (cur_sunshine > 30) then
return false
else
return true
end
This is the simple version. Totally unrelated to this topic, I use the PROWL service to send messages to my iPad every time a light event happens. I stripped the SEND MESSAGE code from this scene as provided to the post to avoid polluting the post with unrelated topics. However if you have an iPad you will find sending messages to Prowl EXTREMELY handy.
My apologies for not getting the code inside boxes like I’ve seen others do. My skills using this forum are weak at best. If anyone cares to tell me how?..