I stumbled upon a bug in the Vera firmware that they say will be fixed in a later firmware release (am using latest v5).
My goal is to use the Aeotec 4-in-1’s motion sensor to turn on lights, but only when its light sensor says the area is dark.
The approach I used was to create one scene that armed the motion sensor at dark (the trigger was light level < 100) and another scene that bypassed the motion sensor at daybreak (the trigger was light level > 150). (The trigger values were recommended by Aeon Labs after they heard of the problem I was having.)
THE PROBLEM I WAS HAVING: at dark and daybreak both scenes were triggered every 10 minutes, which was the light sensor’s reporting interval. I asked Vera how, for example, light values like 50 or 0 could be interpreted as > 100 while also being properly detected as < 100. Looking at the alert log I could see that the motion sensor would be armed because the detected light level was, say 50, but then immediately afterwards the motion detector would be bypassed by the other scene with its trigger looking for a light level > 150. This cycle of contradictory triggers would occur throughout the night as light levels changed slightly (dataMine would show a change from 0 to 2, for example – neither of which should have triggered either scene). Note that I was using this LUA code to limit when the scenes were valid.
return luup.is_night() == false
I used dataMine to track the light sensor’s actual output (CurrentLeveL) and the results looked perfectly normal. As night approached the levels reported would go from (for example) 1000 to 600 to 50 to 2 to 0, and the reverse at daybreak. (dataMine reports only changes in a variable.)
As a workaround Vera Support recommended I create two Scenes for arming and bypassing the motion sensors that would use LUA code. (and here’s where I’m asking for advice)
Scene to arm Motion Sensor, in LUUP tab add the following LUA code:
local luminosite = luup.variable_get(?urn:micasaverde-com:serviceId:LightSensor1?,?CurrentLevel?, 15)
luminosite=tonumber(luminosite)
if luminosite > 150 then
luup.variable_set(?urn:micasaverde-com:serviceId:SecuritySensor1?, ?Armed?, ?1?, 7)
end
Scene to bypass Motion Sensor, in LUUP tab add the following LUA code:
local luminosite = luup.variable_get(?urn:micasaverde-com:serviceId:LightSensor1?,?CurrentLevel?, 15)
luminosite=tonumber(luminosite)
if luminosite < 100 then
luup.variable_set(?urn:micasaverde-com:serviceId:SecuritySensor1?, ?Armed?, ?0?, 7)
end
It’s unclear to me if I need to assign a Trigger or a Schedule to make the above scenes run. Also, please correct me if I’m wrong, but I assume that since the above LUA code arms and bypasses the motion detector there’s no need to change anything about motion detector in the Devices tab.
Under the likely mistaken belief that I’m actually starting to understand this stuff it occurred to me that instead of using two scenes and LUA code to arm and bypass the motion sensors I could simply create a single Scheduled Scene that would arm the motion sensor at, say, 5pm (the earliest hour at which it starts to turn dark) and bypass it later at 2am (there being no need to use the sensors after 2am). I would then add the following LUA code to the Scene that turns on a light when motion is detected.
luup.call_action(?urn:micasaverde-com:serviceId:HaDevice1?, ?Poll?, {}, 15)
local luminosite = luup.variable_get(?urn:micasaverde-com:serviceId:LightSensor1?,?CurrentLevel?, 15)
luminosite=tonumber(luminosite)
if luminosite > 100 then
return false
end
Is that valid code and reasoning?
It seems to me that I can either use light level to arm/disarm the motion sensor, or use light level to determine when to allow an already-armed motion sensor to turn on a light – and the latter approach seems simpler.