Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Home automation controller logic

Status
Not open for further replies.

heydonms

Member
I'm currently working on a HA system and I'm a little stuck deciding how to handle the logic.

The simplest option is to hard code everything. The obvious down side is that a change to the logic requires that the program be recompiled. I don't really want to do that.

At the other end of the spectrum, everything could be a script. When an input comes in, the controller looks for a matching script which can then trigger outputs, timers, etc. This approach is much more flexible but involves a lot more work and requires a more powerful controller, more storage, etc.

At the moment I'm tending towards the middle ground. Certain common tasks have function specific logic built in and just load configuration data (e.g. the alarm system just loads a list of sensors and lights to associate with each zone) but a basic scripting capability is available for more advanced functions.

Has anyone here made their own HA system? How did you encode the logic? What are the pros/cons? What would you change if you were doing it again?
 
I have all wise used a computer to do Home Automation.
Each time the computer gets smaller.
Hard coding makes change difficult.

Last time I used a "BASIC" compiler but "PYTHON" or "C" are options.

Can you program?

If house_temp = too_hot
then open_window_3
end if
If house_temp = too_cool
then close_window_3
end if

Some where you define too_hot=93F, too_cool=65F, house_temp = ????, open_window= ?
 
I have variables that I can change by connecting a computer to the USB port. The variables are stored in EEPROM. I don't do that very often. If your system doesn't have a volatile state worth preserving, it doesn't give you any advantages over reprogramming.

I can set something wirelessly, but not much.

I also have an LCD with buttons where I can set simple things, such as disabling furnace for summer time.
 
...snip...
Hard coding makes change difficult.
...snip...
If house_temp = too_hot
then open_window_3
end if
If house_temp = too_cool
then close_window_3
end if

Some where you define too_hot=93F, too_cool=65F, house_temp = ????, open_window= ?

I'm specifically talking about the logic, so your example (assuming it was written in the controller's source code) would be what I refer to as hard coding. The variables might be defined elsewhere, but if you wanted to change it to:

If house_temp = too_hot && last_rain > 2hr
then open_all_windows
end if​

then you have to recompile and reflash the controller.

By using a scripting approach the code that is built into the controller would be more like:

function process_sensor_data (sensor_id, sensor_value) {
script = find_script_file (sensor_id)
execute (script, sensor_value)
}​

There would then be a bunch of files somewhere (SD card, USB stick, tftp server, RAM, whatever), find_script_file searches through them until it finds one that matches the sensor_id and execute runs whatever code is in that file (and passes in the value). To completely change what a given sensor does you just replace the script file for that one sensor.

If I did decide to use scripts, I'm tossing up between implementing them on the main controller (which would be a uC), since space and processing power would be limited I was thinking a simple stack based scripting language (sort of a mixture of the PIC10F instruction set with RPN and a touch of FORTH with some high level functions thrown in); or offloading to a separate computer so that the scripts could be written in a more full featured language, like python.

I had been shying away from the separate computer option because I wanted it to be self contained, but the more I think about it the more something like a RPi seems like it might be a good fit. The function specific code (alarms, motion activated lights, etc.), stuff that is unlikely to change could be hard coded and things that might need tweaking every now and then, but aren't as critical (AV gear, sprinklers, etc.) could be handled by the PC.

I have variables that I can change by connecting a computer to the USB port. The variables are stored in EEPROM. I don't do that very often. If your system doesn't have a volatile state worth preserving, it doesn't give you any advantages over reprogramming.

I can set something wirelessly, but not much.

I also have an LCD with buttons where I can set simple things, such as disabling furnace for summer time.

The main reason I don't want to have to reflash isn't so much the downtime or loss of state, but rather for usability reasons. If I go to all the trouble of installing this thing throughout the house, I don't want to then have to rip it out when we sell or if something happens to me then my wife needs to be able to manage it. Changing some basic "if-then" type code and saving it to a USB stick is probably within the capabilities of most people. Hooking up a programmer to the ICSP port, switching jumpers, recompiling a hex file, and flashing it probably a bit more trouble than most people want to go to. But then maybe I am overestimating how much reconfiguration is actually going to be required. Maybe once it is in and working, no one will worry about reprogramming it.

What does your system control? How much have you extended it since it was first installed?
 
What does your system control?

I have a water well that only supplies a small amount of water.
So I control 22 water valves (excluding the green house). The timer for the valves only counts when the well has water and does not count when the well is dry. If the wind is blowing hard the water is stored for later use.

There are fans that run based on inside and outside temperature and rain.

The house looks like some one is home (lights, movement, sound) when someone drives into the yard.

Motion detectors in the garden. (animals)

Reports all this on the internet.

Remote lights.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top