Overcoming bug in Vera firmware related to Aeontec 4-in-1 Multisensor

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.

I created a scene and entered the LUA code Vera suggested for arming the motion detectors. After dark I checked the Vera’s GUI and the scene had not run. I SAVEd it again and this time happened to notice in the blue area at the top of the Vera GUI, after the progress bar and “Unit busy” disappeared, a brief display of some messages:

ERROR : Error in lua for scenes and event
dataMind graphing and logging[19]: running Lua Startup
ERROR : Error in lua for scenes and event

Does this indicate that there’s an error in the code?

Part of the code Vera recommended was:
local luminosite = luup.variable_get(?urn:micasaverde-com:serviceId:LightSensor1?,?CurrentLevel?, your4in1maindevicenumber(=motion device))
luminosite=tonumber(luminosite)

They said that the only item I need to replace in it is “your4in1maindevicenumber(=motion device))”, which in my case is “15”. I questioned why I should use the device number of the motion detector instead of the light sensor (17, which I used in dataMine to track its output), but was told that in this case I must use the parent device’s ID number.

BTW, when I discovered that the motion detector had not been armed, I ran the scene manually just to see if it would function. The “ERROR : Error in lua for scenes and event” message appeared.

I had a similar situation involving a Aeon 4-in-1 which I solved with a PLEG

The objective is for the lights in the Family room to be triggered by motion UNLESS the room is already light enough. If it is already light enough and the lights are OFF it prevents them from going on, if they are ON and the light level rises above the threshold then it turns the OFF with or without motion.

The threshold is stored in a Variable Container that is accessed by the PLEG rather than coded into the PLEG logic.

Attached are screen captures of the Triggers and Conditions for the PLEG. (The code is not as elegant as Richard Schaefer would have made it but I’m still learning PLEG :slight_smile: ) There is some excess code lying around from other attempts and I still need to build in some hysteresis but right now it works so its OK. The Aeon reports the light level every 5 minutes so that prevents a rapid ON/OFF cycling if the light level is sitting right on the threshold.

There is also logic to control the ceiling fan by threshold in a similar manner using the temperature function of the Aeon.