Motion controlled lights, Best practice?

I created a few rules to turn my lights on when motion in the rooms are detected then turn them off after a predefined period of no motion. So far it works pretty good and oddly enough there’s the problem. I still need to turn the sensitivity up on my detectors so that would help part of my problem but worsen another.

Until I get light sensors the rules turn the lights on to a specific brightness based on time of day and the delay to off also depends on time of day. I’m having a heck of a time programming in an override to this behavior. Sometimes we’re watching TV on the couch and apparently we’re not moving enough so the lights turn off. Then there are the times where we manually set the lights brighter or dimmer than the rule is configured and as soon as some one moves or the dog walks in the lights adjust back to the undesired level.

As i’m weighing my options to handle this i’m curious as to what others with motion detectors controlling their lights are doing to override the programming in their rules? I tried creating the rules so they would automatically be disabled for an hour if some one manually changed the lighting level at the wall but that broke everything all together. Anyone up for sharing what they’re doing? What’s the best way to handle this?

I wrote a short blog post about the first part of your problem - http://www.smartthingsnz.co.nz/store/presence-detection-using-wasp-box-algorithm/. I am using this technique and it is pretty good - but does of course mean you need sensors on all entry/exit points as well as motion sensors within the area.

The wasp in a box concept is great. I have been doing something similar with respect to my motion activated garage lights for a while but reading your blog really put a face to the concept. Thanks! I will look to incorporate it more.

One thought that comes to mind is depending on how much you have automated, you could trigger off of your activities around the house. Like if you can tell that the TV is running, assume somebody is watching it. You could also do dimming tricks like dim 30% after 10 minutes. That would be noticeable and you could move enough to keep it from going out. Not perfect but better than nothing perhaps :smile:

Additionally, as @ben_jones12 mentioned in his blog, the more sensors you have the better. Basically keeping track of the order of sensors triggered can tell you a lot about the occupants location. Such as living room motion followed by bedroom motion = in the bedroom.

I’ve been thinking of placing cheap arduino based nodes with a motion, temp, light sensor around the house. For about $10-15 and a little work, you could basically have all the info you could want (add as many sensors as you need) in a small box to set on a surface in each room. If you wanted to go “bigger” you could even incorporate a relay and build the whole thing into an outlet or switch box… automated outlet/switch.

Nice write up ben_jones12, Thanks for sharing.

Conceptually I understand wasp in a box but practically i’m having trouble wrapping my head around this. Can one of you share your rules to shed some light on this?

Here’s an example based on this concept from the blog where i’m confused. If I am understanding correctly:
Room = Kitchen
1. Assume the Kitchen is unoccupied (got it - makes sense)
**2.**Kitchen slider, Kitchen exterior door, or motion detector is tripped - Kitchen is occupied(here’s where I get lost)
How do I assume the kitchen is occupied until told otherwise? There’s always the PIR but we’ve already proven that unreliable to detect a unoccupied room. At what point does the lights turn off, or the temperature set back, or the audio turns off, etc, if I am to assume the kitchen is occupied until told otherwise?
**3.**Kitchen slider, Kitchen exterior door is tripped assume unoccupied(makes sense, I wonder about taking out the trash but then I guess you start back at 1), if the doors remain closed the kitchen is still occupied (this goes back to my questions on 2)

I’m very interest in this as I do have motion detectors for every room and hallway, well i guess i’ll need 3 more for the bathrooms. Adding sensors to interior doors would be easy to do as well. I’m just having difficulty visualizing it all in action. At a whole house level i think I understand it both conceptually and practically.

Yeah perhaps I didn’t explain that as well as I could have. The basic premise is that once you detect presence in a room, via whatever means, you assume that room is occupied up until one of the entry/exit points are tripped. This is not 100% accurate, since if two people walk into a room and sit down to watch TV you will have presence detected, but then one gets up and walks out, the wasp-in-a-box will reset, and if the remaining user doesn’t move and re-trip the motion detector, the room will assume it is un-occupied.

However in my experience it works pretty well most of the time. And I add a 5 mins timer so that once the wasp-in-a-box switch is cleared, I wait 5 mins before turning off any lights etc - this gives a buffer and time for someone to re-enter or re-trip the motion detector.

Forgive me, i’m not trying to be difficult here but does this work with an open floor plan? I guess that might be where i’m tripped up. I’m visualizing my space and i’m trying to figure out what kind of hardware i’d need to detect entry/exit. All of the actual rooms makes sense as there is a physical door. So I’m guessing to set a room as occupied something like(not properly formatted):

when door changed
then
if door.state = OPEN
if motion.state = ON && if presence.state = OFF
command Presence, ON

Then the opposite to set the room as unoccupied, maybe throw in some timers. How do the lights function? Do they automatically turn on with entry (when the room is set to occupied) but are manual after that? They turn off automatically, if on, when the room goes to unoccupied?

So back to an open floor plan or a room that is simply open to a hallway with no door, how would you address that scenario?

I have this situation and have motion sensors in the hallway - when that is tripped I assume the living room has been exited (via the hall) and thus the wasp is out of the box.

This is probably inefficient as writing code and such isn’t a strength of mine, so I welcome pointers. This is a sample of what i’m using, how far off am I from the wasp in a box concept?

So there are several rules in this one file. Each room has it’s own rules file and the intent is that one file will handle all rules for that room (lighting, media, etc). I started with one rules file for each system but the lighting rules file became huge and difficult to navigate so I changed direction.

rule "FamilyRoom2"
when
	Item Motion_FamilyRoom received command
then
	if(receivedCommand==ON) {
      if (now.getHourOfDay() >= 07 && now.getHourOfDay() < 19) {
			if(FamilyRoomcounter==null) {
			logInfo("Lighting Level", "FamilyRoom Timer started")
			FamilyRoomcounter = createTimer(now.plusSeconds(900)) [|
				FamilyRoomLightControl = 1
				sendCommand(Light_FF_Family_Ceiling, "1")
				logInfo("Lighting Level", "FamilyRoom Final Timer started")
				FamilyRoomcounter = createTimer(now.plusSeconds(60)) [|
				FamilyRoomLightControl = 1
                sendCommand(Light_FF_Family_Ceiling, "OFF")
				logInfo("Lighting Level", "FamilyRoom Lights out")                
				if(FamilyRoomcounter!=null) {
				FamilyRoomcounter.cancel
				FamilyRoomcounter = null}
				]]}}
		 else {
			logInfo("Lighting Level", "FamilyRoom Timer Restarted")
			FamilyRoomcounter.reschedule(now.plusSeconds(900))
		}}
end

rule "FamilyRoom Let There Be Light"
when
	Item Motion_FamilyRoom received command
then
	if(receivedCommand==ON) {
		if(LightingAutomation!=8 || LightingAutomation!=9)
			if(Light_FF_Family_Ceiling.state != FamilyRoomLevel){
		FamilyRoomLightControl = 1
		sendCommand(Light_FF_Family_Ceiling, FamilyRoomLevel)
   		logInfo("Lighting Level", "FamilyRoom Auto Update")
	}}
end

There is a rule that sets the brightness level to a variable (FamilyRoomLevel) that runs every 5 minutes. I tried to do the same to the delay to off but it looks like I can only use an integer so I have 4 blocks of rules where “if (now.getHourOfDay() >= 07 && now.getHourOfDay() < 19) {” changes.

How can I integrate this into wasp in a box concept?

got ya!! Okay. I’m understanding more of what you’re saying and I think the vision of my floor plan is what’s driving the confusion. I can and will use this concept for the bedrooms,bathrooms, office, gym, etc but I don’t think it will work for the main living area. At least I don’t know how I can.

So how do your lights function? Do they automatically turn on with entry (when the room is set to occupied) but are manual after that? They turn off automatically, if on, when the room goes to unoccupied after the hallway motion is tripped?

Nah my lights turn on at sunset and then off when I go to bed - they are always on in the living room. Unless we are not home when they are off. The only time I use the presence detection stuff for lighting is after we go to bed - i.e. if someone wakes up and comes into the living room for a drink or something.

@bob_dickenson solved a very similar problem in this posting here using proxy items.

The way I’ve addressed the “manual override” problem is by using the presence detection to control an intermediate Number item, which indicates the lighting state. The way presence detection and the like interacts with the lighting varies in each state. By drawing up a state diagram you can think about the rules to get from one state to another.

So, in practice my states are:

  • Auto. In this mode, lights change brightness according to time of day.
  • various scenes: “movie”, “very bright”, etc… That set lights to preset levels.
  • Off - all lights off
  • Custom - no change to lights, but unhides the controls for individual lights in the Sitemap.

On top of these, rules may trigger a transition from one state to another. My most relevant rule is:

  • Room presence detection will only change state from Off -> Auto or Auto -> Off.

Hence, with this structure if you’re in the living room and want to tinker with the lights, you can pick a preset or switch to Custom and fiddle manually and the presence detection won’t override your changes.

As others have said, this is one of those things that the more sensors and integration you have, the smarter this can be. In reality I have l also have transition rules for:

  • any state -> off: when whole house presence is goes off
  • Auto -> movie: when Chromecast starts playing Netflix,
  • movie -> Auto: when Chromecast stops playing.

For an open floor plan, you can use a laser trip sensor. This is activated only when you go through an exit of the room (not when somebody else walks in the hallway to go from the kitchen to the toilet, while you’re in the living room =)

At the risk of getting a bit off topic: How do you connect Chromecast with OpenHAB?

Thank you for all the responses. This has been very informative and helpful!!! Thanks to the information provided I was able to focus my research and I’ve identified two major personal problems that is the cause for my confusion and this issue. I’ve since applied components of all the examples given to a dummy switch to simulate a light and my sensors as the triggers and I think i’m heading down a pretty good path. I’m going to start applying this to my actual lights very soon.

I guess one of the best things about openhab is also one of the worse, there are many ways to perform the same task. With that we just have find what works for our specific use case. I think that’s a pretty good problem to have. If anyone does anything different than what was already mentioned please share what is working for you.

Extra reading - because I talk a lot, therefore I type a lot…
Others may have the same personal problems so In case someone stumbles across this one day here are my issues:
1. I’m over automating things. I’ve realized that I’m really obsessed with seeing openhab actually do something and this is leading to it always intervening when we don’t want it to. Partly due to the sensors needed for this level of automation either doesn’t exist or I don’t have them. For example it seems that for the most part your motion detectors turn the lights on at the first detection of presence and off at the detection of no presence. Exception for very specific events like media playback. It appears that the rest of the smart home community is doing the same, for the most part.

2. Specific to the open floor plan, I was viewing the room a little to literally and also applying a little of my fathers cheapness. Details: The room is 60’ x30’ and at one end it wraps around the corner adding another 30’x16’, it forms an “L” shape. The room is broken up into 4 zones as you would any open floor plan and the lighting is wired by zones. Each lighting zone can be controlled from anywhere in the room using 3-way wiring, this is separate from openhab and simply how the house and lights are wired. With that said, the cheap ass in me, for example, wants the kitchen lights off when no one is on that side of the room. Pretty easy to do since the lights on that side of the room does zero for lighting comfort or visibility on the other side of the room 60’ away. Also a single motion detector hardly covers half the room so this entire area has 3 PIRs for full coverage and there’s still a 8ft dead spot. I decided why not treat the entire room as one lighting zone, logical of course as i’m not going to rewire the room. Now all 22 lights work as one thanks to a couple of rules to keep them in sync. The cost of doing this? They’re all dimable LEDs, $80 per year, if they’re on at 100% for 12 hours per day, no big deal. The point is I can now use something like wasp in a box because i’m not trying to tell openhab that the wasp has left the kitchen or family room zone and instead use the exterior door sensors and the hallway motions to say this entire room was vacated. At least from a lighting point of view I think i’m on to something.

1 Like

I personally have a really high bar as to what I will automate with OH. The automation has to:

  • solve an actual problem or annoyance, not just be implemented because I can
  • the automated solution should be easier to use than the previous manual interface, preferably it should work without human interaction at all
  • if I have to resort to the sitemap to control something it is an HA failure; I only use the sitemap for debug and development

This helps to temper my enthusiasm and focus my attention.

Also, start simple and build up to the complex. First get your lights working with the motion sensors. Then look into ways to keep the motion sensors from triggering the lights when you don’t want it to. Then move on to the next problem.

Actually I think what most people do is when a PIR triggers it turns on a light for a certain period of time. Then it turns the light off after a certain amount of time after the last time the PIR triggered. Others, like myself, don’t even use PIRs at all and control my lights based on time of day and weather conditions.

I agree. This would follow my “start simple and build up to complex” approach. Perhaps there are other ways you can integrate later to help break the room apart into zones again but get it working as one zone first.