Thursday, May 1, 2008

Ambient alerts

Home automation is not just about 'clap on / clap off' bedroom lights. A good home automation system has many aspects that are not noticable by the occupants, things that you don't notice until you move to a new house that doesn't have a system. Occasionally you do need your house to give you information before it does something, and doing that in a smooth way is important to keeping the system 'in the background.'

This post will be about one of the ways my house communicates with me - controlling dimmable lights.

One of the tasks I've given my system is to shut off lights that are not in use. There are three sets of lights that would frequently be left on by a certain-someone that lives here who isn't as concerned about wasting power as me. There is a light in the entry way (right inside the front door), there is a pair of lights at our pantry (one inside the pantry, the other outside the door, both on separate circuits), and then the main set of kitchen lights.

The entry lights are on a simple timer, you turn it on and you have 15 minutes to get inside before they shut off. I can't imagine a time when it is going to take more than 15 minutes to put my shoes on and grab my keys and cell phone from the shelf.

The lights in the kitchen are not so simple. Cooking can take a long time, sitting and talking can take a long time, but the lights shouldn't stay on for hours and hours. Rather than going with motion detectors, I decided to go with what I deemed 'smart timers.' These are timers that start counting down, give you a warning before firing, and are resettable. 

I have implemented the 'warning' as a brief dimming of the overhead light. Enough to notice briefly, but not enough to distract or disrupt things. You notice the brief fade in/out, walk over to the switch and tap the 'on' position again and you reset the timer. 

Now for the details, how it is implemented. These instructions are for using Indigo v2, a great piece of Mac software, but the concepts should easily be converted to most any decent home automation software, and even some of the more robust hardware-based control systems. It might sound complicated, but once you get it set up once you can just clone the various pieces for use on other devices in your house.

First, lets assume that you have a dimmable light in your house, and you've named it 'Kitchen Overhead'.

Next, make a Trigger Action called 'Kitchen Overhead Watcher - On', and set it to watch for the 'Kitchen Overhead' light turning on. Don't worry about making it do anything yet, just save the trigger.

Then make another trigger called 'Kitchen Overhead Watcher - Disable', and have it watch for the light to turn off. Again, don't worry about making it do anything.

Create one more trigger called 'Kitchen Overhead Watcher - Reset', but this time you don't want to look for the light turning on or off, as this will be used to reset the timer while the light is still on. Instead, you want to set this up to just watch for the 'on' button being pressed.

Now switch to the 'Time/Date Actions' section, and create two Time/Date Actions called 'Kitchen Overhead Watcher - Off' and 'Kitchen Overhead Watcher - Warning'. Don't worry about making them do anything, and just set the time and date to the 'now', these will be programatically controlled later. Make sure that these are 'disabled', you don't want them to start going off on you.

Now switch over to the 'Action Groups' section and make one action group called 'Kitchen Overhead Watcher - Off'. This isn't necessary if your software doesn't support it, it is just a 'macro' to do a couple actions at once. It does make your other actions look nicer.

Okay, now that we have all these things made lets go back and make them 'do stuff.' You'll see in the next steps how having the various items made and named is a prereq to making any of them 'do stuff.'

First, switch to the Trigger Action tab and open up the 'Kitchen Overhead Watcher - On' trigger; we need it to do three actions (and they need to be done in order, if the 3rd one I list is done 1st you'll have a problem). 
The first action should be to "disable time/date action 'Kitchen Overhead Watcher - Off" and the second should be to disable the "Kitchen Overhead Watcher - Warning" t/d action. Basically that clears the system.
The third action should be to run embedded applescript. Type the following:
tell application "IndigoServer"
set now to the (current date) + 55 * minutes
set the absolute trigger time of the time date action "Kitchen Overhead Watcher - Warning" to now
enable time date action "Kitchen Overhead Watcher - Warning"
end tell

What that does is to set the 'warning' time to 55 minutes in the future. Obviously you can set this to whatever you want. This is the 'warning' time, not the time that the light will actually be shut off.

Save those actions off, and open up the 'Kitchen Overhead Watcher - Reset' trigger action and do the same 3 steps. You could get fancy and change the number of minutes in the 'reset' trigger to be smaller than the original set. This would basically be enabling something like 'you get an hour to have the light on, tap the button to extend it by a half hour' compared to 'you get an hour of light every time you tap the button.'

Now open the third trigger action, 'Kitchen Overhead Watcher - Disable' and this time only add the first two actions. (the 'disable time/date action...' pair)

Now switcher over to your Action Groups and open your 'Kitchen Overhead Watcher - Off' action group. Add three actions to it, first one to "Turn Off 'Kitchen Overhead'" to actually shut the light off, then the next two actions are the familiar 'disable time/date action...' pair. (Yes, that action pair could have been made in to its own macro since they get repeated several times, but really there is no big benefit to doing it.)

Only two left now, and they are on the 'Time/Date Actions' page. 

First open up the 'Kitchen Overhead Watcher - Off' one. The only action you need this to do is to "Execute Action Group 'Kitchen Overhead Watcher - Off'".

Now open up the 'Kitchen Overhead Watcher - Warning' one. This is the one that does the smooth 'ambient alert' dimming trick via 3 actions.

First an embedded applescript one that says:
set foo to the brightness of the device "Kitchen Overhead"
dim "Kitchen Overhead" to 30
delay 1
dim "Kitchen Overhead" to foo
So what that does is record the initial dim level (in case it had been manually dimmed to something other than 100%), then tells the light to dim down to 30% brightness (which obviously you can change) and then 1 second later go back to the original brightness. When combined with a SwitchLinc's built-in 'smooth dimming' / 'ramp rate' feature this enables a very brief 'whoosh' of light. Adjust the dim level and time to suit your needs, the key is to set them to something that is obvious but not jarring.

Next action in this set is to disable the time/date action 'Kitchen Overhead Watcher - Warning' - i.e. turn itself off. The warning just fired, so it needs to go ahead and disable itself for good measure.

The third action is another embedded applescript:
tell application "IndigoServer"
set now to the (current date) + 5 * minutes
set the absolute trigger time of the time date action "Kitchen Overhead Watcher - Off" to now
enable time date action "Kitchen Overhead Watcher - Off"
end tell
Which should be familiar since it is the same basic code used earlier. This time the system is set to turn off the lights 5 minutes from now. 

Now, with all of these triggers and timers in place you are ready to go. When you first turn the light on the 'warning' clock gets started (55 minutes in this case), when the warning fires you have 5 more minutes before the light is shut off. If you tap the switch again during those last 5 minutes the timers are reset and you get another hour of light.

Congratulations, you now have an even smarter smart-house!

No comments: