MisterHouse is an active, community-driven, open source home automation project

King of the House

Article from Issue 178/2015
Author(s):

MisterHouse offers a practical approach to home automation – if you are ready to get creative and you know a little Perl.

The explosion of Internet of Things (IoT) devices and technologies has renewed interest in a topic that has actually been percolating within the hacker subculture for years: home automation. Why not let your computer serve as a "brain" for your house, turning on and off light switches, adjusting the thermostat, or opening the curtains at the perfect time of day to optimize passive solar energy. Creative coders have been asking themselves these questions since long before the first Raspberry Pi and Arduino boards fell into the hands of amateur home designers.

One tool that has been around for many years as an aid for home automation is a practical and easy-to-learn utility called MisterHouse. MisterHouse offers a structure, and a simple user interface, for Perl scripts that provide home automation functions. You need to know a little about Perl programming to use MisterHouse, but you don't need to be an expert in electronic circuits or embedded systems programming.

Bruce Winter first released MisterHouse to the Usenet newsgroup: comp.home.automation on April 1, 1999. MisterHouse started out as a way for Bruce to manage the environment of his passive solar and south-facing, earth-bermed home. He also built custom curtain controllers, which MisterHouse controlled while monitoring sunlight level, outdoor temperature, and indoor temperature to control the curtains, fans, and a furnace.

Of course, automation technology has changed significantly since 1999, and you might be thinking that MisterHouse would be showing signs of age, but the simple, flexible design of MisterHouse makes it easy to accommodate new technologies. To quote my favorite author, Samuel Clemens: "The report of my death was an exaggeration." MisterHouse Version 4.x is just around the corner, and new protocols and features have been added to equip MisterHouse for the IoT era, including support for Nest, MQTT, Pushbullet, Philips Hue, Z-Wave, and a lot more.

Bruce Winter is still involved with MisterHouse, and an active community of users and developers now contribute to the project. Lieven Hollevoet set up the main GitHub repository for MisterHouse [1], which allows users easy access to the code.

What Is It?

At the most basic level, home automation is nothing more than communication. A controller sends a command to a device. The device then listens for the command and executes the instruction. The device transmits information about its state to the controller. The controller then listens for information on the state of the device, and, if the state changes in some predefined way, it sends a command to the device to take an action.

Several protocols exist for managing the communication between controllers and devices on a home network. Earlier versions of MisterHouse made extensive use of the X10 automation protocol to communicate with X10-compatible home devices. Such devices include power switches, temperature sensors, doorbell chimes, and electric light sockets. MisterHouse still supports X10, but a number of alternative automation protocols exist today; MisterHouse has added support for KNX/EIB, Insteon, UPB, Z-Wave, ZigBee, and a very long list of other devices.

MQTT has recently gained popularity as a "machine-to-machine Internet-of-Things connectivity protocol" [2]. The MQTT protocol is now an OASIS standard, and many new-age IoT devices support MQTT. This article will show you how to use MQTT to receive information from a weather station device. If you want to automate a device that isn't designed to operate as a client for X10, MQTT, or another automation protocol, another option is to set up a single-board system, such as an Arduino or a Raspberry Pi, to act as the communication client that then controls the device using an electrical circuit.

One of MisterHouse's strengths is its ability to get different technologies to play together nicely. The community is also working on speech-to-text, as well as integration with other smart home and IoT services, such as Wink, Nest, and SmartThings. Often, these codebases show up in a forked MisterHouse project while the developer works on the development code. When completed, the MisterHouse pieces are merged back into the stable code.

How It Works

MisterHouse has an extensive library of support functions to handle timers, triggers, an object's state, and devices. Yet at MisterHouse's core is a rather simple loop. At startup, MisterHouse reads in all the device and user code and initializes each device, which adds some polling code to check for data to MisterHouse's main loop.

The device code also adds the device's objects to MisterHouse for use in the user code. Example objects are lamp, temperature sensors, weather information, or garage doors. Next MisterHouse drops into the main loop, where it does some housekeeping, polls each device, then runs the user code. User code can then access the state of any object and make a decision based on the object's state, timers, or other information MisterHouse has available.

MQTT [2] is a publish/subscribe technology. Under Linux, I am using Mosquitto as the MQTT broker. The broker allows you to publish and subscribe to topics, which allows many-to-many communication.

On an MQTT network, a topic defines a device, task, or area of interest that will be a subject for communication over the network. For instance, as you will learn later in this article, home weather information might be a topic that defines a category of communication for the network. Choosing a topic name is a lot like choosing paths in a filesystem. For example: your living room ceiling lamp might be: home/livingroom/ceiling/lamp. You create the topics in a manner that makes sense to you.

In addition to the full path, MQTT subscriptions support wildcards in the form of: home/livingroom/#. The # is the wildcard, and it allows you to subscribe to everything in the living room which might be: home/livingroom/table/lamp, home/livingroom/floor/lamp or home/livingroom/hutch/lights.

When a device on an MQTT network "subscribes" to a topic, it listens for commands and information related to that topic. The subscription process creates a kind of virtual channel for passing commands and status information related to the topic. Devices publish information when they send an update, such as when a light switch has been turn on or off.

MisterHouse sets up its subscription to a topic when it initializes a new MQTT object. Then, main MisterHouse polls for messages on topics to which it is subscribed. A status message might announce that the garage door has opened or the temperature of the house has changed. The loop also monitors the clock, waiting to activate any commands that might be configured to execute at a specific time. MisterHouse can then publish commands to the MQTT item's topic to control the specific device, such as telling a lamp to turn on.

MisterHouse will run better with more RAM, more disk space, and a faster processor. My main MisterHouse system currently runs on a 1GHz x86 with 512MB of RAM and a 300GB disk. I also run a DHCP server, a local DNS, local NTP, Samba, Apache, mail, and various cronjobs on the server. Most of the time, the computer runs idle, but it does use some swap.

Installing MisterHouse

Once you have the prerequisites (see the box called "Prerequisites,") installing MisterHouse is not too difficult. All the same, I have provided a link to a VM tarball with MisterHouse installed and configured so you won't have to install everything to try it out [3]. (See the box called "Using the VM and VMware Player.")

Using the VM and VMware Player

If you want to jump into using MisterHouse without too much trouble, try the VM I've set up at http://ushomeautomation.com/MH/debianvm.tgz, which is roughly 3GB in size. After you've installed the VMplayer from VMware [4], download and untar the file (tar xvf debianvm.tgz ) into your VMware directory. Then, start up your VMplayer, select Open a Virtual Machine, select the path to the new VM directory debianvm, select the file debianvm.vmx, and click Okay. This should start up VMware, and it should ask you if you are copying or moving the VM. Choose to copy and VMware will perform its reconfiguration. Everything else is installed and configured. The root password is root and the password for mh is mh. (These credentials are extremely insecure, so I recommend changing both right away!)

Also note that this entire server has loose security. So, don't set this up directly on the Internet and expect it to last more than five seconds before it's pwned. I've taken the liberty of disabling a number of services and performing the installation and the necessary configuration steps. I have also set up the first Ethernet (eth0) as a DHCP client. There is an additional interface (eth0:1), which is hard-coded to the IP address 192.168.255.44. This configuration should allow you to connect through either IP address. To find the DHCP IP address at the VM's console, log in as mh and type: ip addr show eth0. You should get back the IP address delivered to the eth0 interface from your local DHCP server.

Prerequisites

MisterHouse doesn't need much to run but it does have requirements. These requirements are for a basic to moderate MisterHouse setup and might grow once you start adding some features. Because MisterHouse is written in Perl, it will run on any recent Linux distribution that has Perl 5.

To run MisterHouse, you will need:

  • Linux (any distribution is fine; I'm using Debian, but I also have Ubuntu and an ancient Fedora server still running)
  • 8GB hard disk minimum (MisterHouse needs about 500MB with extra Perl modules; the rest is for Linux)
  • 256MB RAM minimum
  • Interfaces: Serial, USB, IP
  • Perl (version 5.10 minimum)
  • Git (optional but recommended)

If you don't have the luxury of using a VM, you can open a shell as user root and add the user mh by entering the following command:

useradd -G dialout -c "Misterhouse" -p mh mh

Then, log in as the user mh:

su - mh

Make the local mh directories with:

mkdir -p local/code local/data

Download the stable MisterHouse software

git clone http://github.com/hollie/misterhouse.git

or use:

wget http://github.com/hollie/misterhouse/archive/stable.zip
unzip stable.zip

Download and untar the sample startup script and user code with the following:

wget http://ushomeautomation.com/MH/mh-samples.tgz
tar xvf mh-sample.tgz

Use your package manager to install the mosquitto and mosquitto-client packages, then use the CPAN Perl module archive to install the Net::MQTT modules (BEANZ/Net-MQTT-1.143260.tar.gz or later).

After you follow the preceding steps, everything will be put into the correct places. So, you don't need to worry about moving anything.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

News

njobs Europe
What:
Where:
Country:
Njobs Netherlands Njobs Deutschland Njobs United Kingdom Njobs Italia Njobs France Njobs Espana Njobs Poland
Njobs Austria Njobs Denmark Njobs Belgium Njobs Czech Republic Njobs Mexico Njobs India Njobs Colombia