Motion Sensor + Light Level = Switch on lights

Hi

Im brand new to this home automation lark, and just cant get my head around having multiple actions met to trigger a light.

I have a motion detector with built in light level and temp sensor. All im trying to do is this:

IF Lightsensor<10 and MotionDetected, turn on light.

Can someone please point me in the right direction?

Many thanks

Vera is not able to do AND conditions by default. It can only do OR conditions. So, by default, Vera can only do:
IF Lightsensor<10 OR MotionDetected, turn on light.

To utilize AND conditions as well as a whole lot more, look at the Program Logic Event Generator(PLEG) plugin.

If you decide to use it(and fail to read the docs) make sure that you first install its dependency, the Program Logic Core(PLC) plugin.

You could have a scene triggered my the motion sensor and add Lua code to the scene to stop it running if the light level is greater than 10. There is an explanation of how this works and example code for light level in Conditional Scene Execution.

I do agree with @Z-Waver, though. PLEG is a powerful and flexible tool for implementing almost any automation logic you may require. You can read more about it in PLEG Basics.

Thanks guys for taking the time to reply, I’ll check out the PLEG plugin.

Howdy DengoDave,

I’ve accomplished exactly what you’ve described within UI5 without using PLEG. It’s actually fairly simple to do. Here’s how I did it:

  1. Create a new scene in UI5 that turns your light on. In my case, it is a garage light, so I named the scene “Garage Lights ON”
  2. Go to the “Devices” tab and select the “ON” button on the light, so that when the scene runs, it turns on the light.
  3. Go to the “Triggers” tab and select Add Trigger → Select Device (Motion Sensor), What Type of Event is this trigger? (A sensor is tripped), Name the trigger (I called it, “Garage sees motion”), and select from the drop-down, “Device is tripped”. Then click “Back to Triggers”.
  4. Go to the “LUUP” tab at the top of the UI5 page (not the “LUUP Event” button on the Triggers page, though that would work - but only for that particular trigger. And we want it to affect all conditions, so we use the “LUUP” tab instead.)
  5. When you click the “LUUP” tab, you’ll see a big blank field. Paste the following LUUP code into that field, replacing the ID numbers with your ID number:
local lightID = XX -- Device ID of your light local sensorID = yy -- Device ID of your light sensor local status = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",lightID) -- Gets the status of the light (On or Off?) local light = tonumber((luup.variable_get("urn:micasaverde-com:serviceId:LightSensor1","CurrentLevel",sensorID))) --Converts the light sensor value to a number so that it can be logically evaluated.

local isNight = luup.is_night() – Checks to see if it is night time

if (((light < 10) or isNight) and status == “0”) then – Checks to see if the light level is less than 10 OR if it is night AND if the light is off
return true – then return the “true” value to allow the scene to run and turn on the light
else
return false – Otherwise, return false and stop the scene from running.
end

So, basically, when the motion sensor triggers, the scene runs. If the LUUP code evaluates to “true” (the light is off AND the light sensor sees a level less than 10 OR it is night), then the scene continues and turns on the light. Otherwise, it stops the scene from running and the light stays in its current state. Make sure you save your work as you go through.

You can also use the same idea to turn the light off when it no longer sees motion. You would create another scene (called “Lights OFF”) and then use a trigger from the motion sensor, but instead the trigger would be when the “Device is not tripped”. Just make sure that the delay on your motion sensor is 4 or 5 minutes so that it has to see motion during that time before it turns off the light. No LUUP required here. Bottom line - when the sensor no longer sees motion (for that 4 or 5 minutes), it sends a signal to turn off the light, no matter if it’s night or day, on or off. (Even though you could write a quick LUUP code to check the light status if you wanted to… but it’s not necessary.)

BTW - many thanks to Rex who’s example codes made this possible.

Melsman