Basic Logic for Multi-Step Home Automation Tasks

Standard

The information presented here is probably not interesting to anyone with a background in programming or other areas that require an understanding of basic logic. However, I thought I’d add a brief post for those who may be interested in dabbling with home automation but have a hard time figuring out the steps required to execute tasks that require multiple conditionals.

Some home automation packages may handle the logic for you. Other packages will require more steps. At home, I’m currently working with mControl 3 (beta). My intention isn’t to provide a step-by-step guide for working within a specific program but just to provide some basic info for anyone that may find it useful.

In a few cases it may not be possible to do something like this – the home automation software must support multiple conditionals.

In this example I’m setting up a couple of macros and devices with the goal of turning on three lamps when a motion sensor is triggered. Specifically, this will only occur once per weekday, after a certain time of day. The key is to use virtual devices (switches), which I think of as “flags” (a term I’ve more often heard when working with older programming languages – think of these as boolean true/false variables). They are assigned to unused addresses – I’m currently using virtual X10 appliance switches for these. Much of what’s used is arbitrary – it’s the logic that counts.

Devices

Living Room Lamp – OFF
Dining Room Lamp – OFF
Bedroom Lamp – OFF
Motion Sensor – OFF

Virtual Devices (Flags)

F1 (Device Name and X10 Address) – OFF

Macros

Trigger Lights
Reset Flag

I’d start by creating the “Trigger Lights” macro first, just so I know it works. Initially, I’ll setup the macro but without the time conditional, so I can test the basic elements of the macro. Note that for testing purposes, since the “Reset Flag” macro isn’t established yet, I’d just change the state of the F1 flag to ON myself. Here’s what it would do:

Trigger Lights

IF Motion Sensor STATUS CHANGE = ON

AND F1 STATUS = ON

AND Day = M|T|W|Th|F

AND Time Range is after 8:15 AM before 11:59 PM

THEN

Living Room Lamp = ON

Dining Room Lamp = ON

Bedroom Lamp = ON

F1 = OFF

END IF

Note that depending on the program used it may be necessary to break some conditionals down into further elements. For example, testing for a specific time range may be more complex. In addition, the program may support combining conditionals. For example, in mControl I can test for the day or days as well as a time range within the same conditional.

Note that F1 is set to OFF. This is so the lights are not turned on every time the motion sensor is triggered. For example, when we get home the motion sensor will turn those lights on only once that evening.

Reset Flags

Obviously, in this case we’d want the Trigger Lights macro to run each weekday. Since it depends on that status of F1, and we don’t want to have to manually set the flag to ON each morning, we just setup a macro to do that for us:

IF Day = M|T|W|Th|F

AND Time of Day = 8:15 AM

THEN

F1 = ON

END IF

Of course, this logic isn’t perfect for every situation. In our home it will work fine most of the time. However, if we leave the house after 8:15 AM, or come home for lunch, we’ll trigger the specified lights to come on earlier than desired. There are several adaptations that can be made. For example, one can easily set the flag to be reset later in the day, perhaps closer to 5 PM.

I use similar methods to automatically change certain behaviors if we’re going to be away from our home for a night. Several macros are pre-established that will somewhat randomly turn lights on and off. All I have to do is change the status of one flag, which I can easily do remotely.

Depending on the software that you’re using, you can do much more. For example, my next step is to have the computer speak a greeting when we come home (I already have the software – I just have to work out a permissions problem that occurs when one process calls another). Previously, with a slightly different setup, I had it play a one-minute section of an 80s song every time we came home from work. It really doesn’t take a lot of work to do this. Aside from the home automation software itself, many of the necessary tools are free or built into Windows and OS X.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s