Hi, I'm trying to do a Luup script inside a Scene that has a Command to turn on a light when a Door sensor is triggered. I want that the light is only turned on if it is dark. So what I did is enter a Luup script inside the Event that triggers the door sensor adding a Luup script as follows:
---------------------------
local LOW_LEVEL = 20 -- the light level threshold for night
local HIGH_LEVEL = 40 -- the light level threshold for day
local DEVICE_NO = 33 -- the light sensor device number
local LS_SID = "urn:micasaverde-com:serviceId:LightSensor1" -- the LightSensor service ID
local currentLevel = luup.variable_get (LS_SID, "CurrentLevel", DEVICE_NO) or 0
currentLevel = tonumber(currentLevel)
if currentLevel <= LOW_LEVEL then
return true
elseif currentLevel >= HIGH_LEVEL then
return false
end
--------------------------------------
But the script does not work the light is always turned on even if it is day (light sensor over 20). What am I doing wrong? How can I do some debugging but putting the currentLevel value into a log?
Thanks for every help ;-)