Controlling lights based on presence

I suspect that like many of us one of my objectives in setting up my home automation system was to have lights switch on and off based on presence. There are lots of ways to achieve this and none of them are perfect and I’ve tried many. I’m really interested in other peoples experiences and what has worked for them.

To try and make my presence detection more reliable I’ve added door switches where they lead to closed rooms. I’ve tried to establish some logic that works on the principal that if we detect movement in the room after the door has closed we can assume that room is occupied (regardless of not detecting more motion) until such time as the door is opened again. I’ve attached some example code that I use to do this, I should point out I’m not an experienced LUA programmer so it isn’t pretty but it works for me. I would certainly appreciate any suggestions on how to improve both my approach and the code!

For me some of the challenges have included:

a) The main issue with IR Motion detectors is revealed in their name… they are motion detectors so if you don’t move much they don’t detect you are there and inevitably you end up doing the Home Automation wave to get lights to turn back on. You can stretch out the time period you allow between motion events but that means you are leaving lights on for a longer period when there really isn’t anyone there. I’ve started working on a better presence detection system using Kinect Cameras which will provide real presence detection but that’s best left for another post.

b) I’m using a DSC alarm system with an Envisalink module for all my motion and door switch sensors as I was doing a reno and had access to put wiring in and the cost per sensor is much lower (I’m in Australia and Zwave devices have only recently dropped under the $80 mark). This works really well but I have had a few issues. Different motion detectors behave differently in respect to their trigger/reset time. The better ones from my perspective trigger and reset quite quickly and repeat motion is sensed often which makes accessing the LastTrip reliable (eg DSC branded PIRs). Other PIRs have much longer reset times (especially if they continue to see motion) and they often remain tripped for long periods making LastTrip unreliable.

c) While I love the DSC plugin and having a nice reliable and comparatively cheap security system, it appears to me that the DSC interface is very busy and as a result the DSC plugin is kept pretty busy and it slows Vera down. I’m keen to understand other peoples experiences? My DSC 1832 has all 32 devices populated with door or motion swtiches and I’m about to upgrade to a DSC1864 to jump up to 64. I’ve started working a microcontroller prototype to convert DSC KEYBUS interface to IP, eliminate the Envisalink, and provide a more intelligent interface to Vera (or other IP enabled devices) which has internal logic (managed via a web interface). With this device I can plan to configure it to only sends events to indicate that a Room is either occupied or unoccupied.

The way I use the attached code is to place the code in the attached file (CheckDoorMotion) in APPS / DEVELOP APPS / EDIT LUA STARTUP

I then have three scenes for each room.

  1. MOTION DETECTED - triggered when motion is detected and turns on the lights and/or devices I want on.
  2. DOOR CLOSED - triggered when the door is closed and runs LUA code to call the CheckDoorMotion function after a delay,

eg: local DELAY = 30
local DATA = “YourRoomName” … yourDoorDeviceID … “;” … yourMotionDeviceID … “;” … yourOffSceneID
luup.call_delay(“CheckDoorMotion”, DELAY , DATA )

  1. Off - the Scene that turns the lights/devices off (note the scene number and use it as “yourOffSceneID”

I also have a separate CheckOccupancy function that I run every few minutes to turn off lights that are not within closed rooms and cleanup any lights left on for more than 30 minutes without any motion (happy to share if it is useful to anyone)

You have to resort do code so it isn’t for everyone but I find this approach easier to maintain and setup than using coundown timers and other plug-ins and it seems to place less load on VERA.

I’m interested in what other people doing and what you think of my attempts to date and what opportunities for improvement you can see.

Have you seen the ‘Wasp in a Box’ algorithm?

[ul][li]http://forum.micasaverde.com/index.php/topic,13920.msg105059.html#msg105059[/li]
[li]Stylish and environmental smart home design & build

Really simple and effective and, in fact, can be used (with PIR sensors) even when you don’t have a closed door.

Thanks akbooer,
I had seen the WaspInABox link but not Thomasss’s post. My aim is to have the sub-zone approach rather than just the whole house, and I don’t want long timeouts, for example in perimetric zones I am doing the check 30 seconds after the door is closed and turning off lights if no motion has been detected. I don’t see how you can do it without door sensors (or motion sensors on the perimeters), am I missing something?

I’ve been looking at pressure matts and other sensors too but haven’t found a reasonably priced one that ships to Australia yet.

[quote=“akbooer, post:2, topic:187657”]Have you seen the ‘Wasp in a Box’ algorithm?

[ul][li]http://forum.micasaverde.com/index.php/topic,13920.msg105059.html#msg105059[/li]
[li]Stylish and environmental smart home design & build

Really simple and effective and, in fact, can be used (with PIR sensors) even when you don’t have a closed door.[/quote]

I didn’t say “without door sensors”, I said without “a closed door”…
… it’s simply a space (perhaps an open doorway, or archway, or even a corridor.)

Ignoring the specific sensor technology, let’s say we have detectors which sense movement in a ‘room’ and in a ‘doorway’. A room can have multiple doorways. If we consider a ‘doorway’ event to be a ‘lid of the box opened and closed’ event in the WIAB algorithm, then a ‘room’, once movement is detected there, must remain occupied until any ‘doorway’ event. At that time, its state effectively becomes ‘unknown’ (depending on the context you may also choose this to be occupied, or not) until the next ‘room’ event.

If properly sited, there is no need for long latency. A ‘room’ can be any sub zone. ‘doorways’ can belong to several sub-zones (if they connect them.)

I didn’t say “without door sensors”, I said without “a closed door”…
… it’s simply a space (perhaps an open doorway, or archway, or even a corridor.)[/quote]

My bad! I should have read it properly! I think we are on the same page, I like your suggested approach and will give it a go.

@Akbooer,

Do you have specific scene(s) that you could share with the rest of us “newbies” that you’ve used, would be greatly appreciated. I would like to use for bathroom occupancy, thanxs in advance Mike

[quote=“akbooer, post:2, topic:187657”]Have you seen the ‘Wasp in a Box’ algorithm?

[ul][li]http://forum.micasaverde.com/index.php/topic,13920.msg105059.html#msg105059[/li]
[li]Stylish and environmental smart home design & build

Really simple and effective and, in fact, can be used (with PIR sensors) even when you don’t have a closed door.[/quote]

There was just a bathroom question last week. [url=http://forum.micasaverde.com/index.php/topic,32626.0.html]http://forum.micasaverde.com/index.php/topic,32626.0.html[/url]

I attached my bathroom PLEG that controls the lights and bathroom fans. Requires both an occupancy/motion and a door sensor. (The door sensors are part of my DSC alarm…)

[quote=“akbooer, post:2, topic:187657”]Have you seen the ‘Wasp in a Box’ algorithm?

[ul][li]http://forum.micasaverde.com/index.php/topic,13920.msg105059.html#msg105059[/li]
[li]Stylish and environmental smart home design & build

Really simple and effective and, in fact, can be used (with PIR sensors) even when you don’t have a closed door.[/quote]

Interesting approach. We would have to adjust for pet motion, but wonder if we could do this by setting the detector up high.

I’d love to do this with ibeacons, but can’t get them working reliably enough.