I’ve tried to read different posts but can not get it to work.
Here is what I want:
When the light level is 15 or below, and motion is detected it should turn on my to switch plugin. And if no motion is detected in 15 min the light should turn off
Can this be done with a single scene or should i use LUUP Code and how ?
Which Vera and which firmware version are you running?
Basically, you would go to your device options and set the parameter for light level to 15 so that the device doesn’t trigger in higher light levels. Then your scene to turn on the lights specifies which lights you want to turn on and what you want to use as the trigger - in this case the motion sensor is tripped.
I’ve tried what you suggested.
The problem is if the light is on and there still being detected motion, the light will not turn off even if the light level is above 15.
Create a scene that turns on your light when motion is detected and add this code. This will check every TIME_PERIOD minutes if there was any motion in this period. If there wasn’t any motion it turns off the light. You must set the correct values for LIGHT_SENSOR_DID, MOTION_SENSOR_DID and LIGHT_DID. I haven’t tested the code, but it should work.
LIGHT_SENSOR_DID = 30 -- Light sensor device ID
MOTION_SENSOR_DID = 31 -- Motion sensor device ID
LIGHT_DID = 32 -- Light device ID
LIGHT_THRESHOLD = 15 -- Light level threshold
TIME_PERIOD = 15 -- Number of minutes of no motion
LS_SID = "urn:micasaverde-com:serviceId:LightSensor1"
SS_SID = "urn:micasaverde-com:serviceId:SecuritySensor1"
SP_SID = "urn:upnp-org:serviceId:SwitchPower1"
function checkMotion()
local lastTrip = luup.variable_get(SS_SID, "LastTrip", MOTION_SENSOR_DID) or 0
if (os.difftime(os.time(), lastTrip) > TIME_PERIOD) then
luup.call_action(SP_SID, "SetTarget", {newTargetValue = "0"}, LIGHT_DID)
else
luup.call_timer("checkMotion", 1, TIME_PERIOD.."m")
end
end
local lightLevel = luup.variable_get(LS_SID, "CurrentLevel", LIGHT_SENSOR_DID)
lightLevel = tonumber(lightLevel, 10) or 100
if (lightLevel <= LIGHT_THRESHOLD) then
luup.call_timer("checkMotion", 1, TIME_PERIOD.."m")
return true
end
return false
[quote=“jj_79, post:6, topic:170625”]Thanks for your help.
But I am a bit unsure about what LIGHT_DID is ?
Br JJ[/quote]
That’s where you put the device ID number for the light you want to control. All that stuff at the top is to set up definitions for your system to use when it runs the code. You just substitute your device number where his says “32”. Same with all the other device IDs that will be used - light sensor, motion sensor. and you can change the light level at whch it works or the time period simply by changing the “15” to a different number in the line that applies.