Skip to content
Lieven Hollevoet edited this page May 4, 2020 · 13 revisions

Installing MisterHouse on a Raspberry Pi

This page will describe how to set up a Raspberry Pi mini computer to run MisterHouse controlling an Insteon PLM. I think the setup is actually easier than installing unix on an old spare machine because the operating system comes as an image already setup with all the drivers for the hardware and it even includes all the software you need for a typical MisterHouse installation.

The resulting Raspberry Pi server should only cost about $2 of electricity per year to run (in the U.S.), plus under $2 for the Insteon PLM in the case discussed below. Compare that to some typical PCs that use 50 to 150 watts (that's about $50 to $150 per year if left on all the time). The Pi will quickly pay for itself if you avoid turning on that old PC or leaving your main computer on all the time.

The Raspberry Pi is a credit-card sized computer originally designed for educational purposes in the UK, but it's taken off as a platform for low cost, low power hobby computing projects. It works wonderfully as a full MisterHouse server. The original Raspberry Pi (Model A) has 256mb memory and one USB port for $25, and the Raspberry Pi Model B has 2 USB ports, adds an ethernet port and 512mb memory for $35. Both models have a 700 mhz ARM processor, an HDMI video port, 3.5mm sound jack, and an SD memory card slot accommodating 2 GB to 32 GB as the main hard drive replacement. It also has GPIO pins you should be able to use for advanced projects. For only $10 more, it's worth getting the Model B to double the memory, and an ethernet port, and double the USB ports, although MH should theoretically run on the Model A as well. More recent models sport even faster processors and more memory, all that are more than sufficient to run MisterHouse on.

The Pi, as I will call it, may not be as cheap as it first appears because it doesn't come with everything a typical computer comes with. A lot of people have spare parts that can be used with the Pi, but if you need to buy a lot of peripheral parts your price will be higher. Here's what you need:

  • A "power supply". The Pi is powered from a micro USB port, and most people will have a spare USB charger that plugs into the wall capable of powering the Pi. The catch is that you need more milliamps than a typical USB wall charger if you're going to run much of anything off the Pi's USB ports. If all you need to do is plug an Insteon PLM into the Pi's USB, then you'll be fine with a typical 500ma wall charger because the PLM powers itself.
  • An ethernet cable that will reach the Pi Model B (Model A has no ethernet port) or a wifi USB dongle. If you add a dongle you might need a larger power supply. You could potentially skip the internet connection if you don't want to remotely control the Pi, but that means you need to plug in a keyboard, monitor, and maybe a mouse.
  • A real-time clock module, if necessary. The Pi keeps its time by using the internet, but if you need it to operate without an internet connection, you'll need to add a real-time, battery powered clock module.
  • A powered USB hub if you run out of USB ports. Since a powered USB hub provides its own power, you won't need a bigger power supply for the Pi to run USB-powered devices.
  • An SD card. A basic MH installation only uses about 1.6GB so even a 2GB SD card can be used, but 4gb is preferable. You can currently buy a 32GB for $22, but that's overkill unless you want to put that in some other device and take the old low GB card from the other device and use it for the Pi. You can also find SD cards for sale with the Raspberry Pi operating system already installed. That might be a good option for some as getting the operating system onto the SD card is perhaps one of the harder steps in the Pi setup process, but it shouldn't be very hard for most people and the pre-installed SD card will cost you more.
  • An SD card writer. Unless you bought an SD card with the Pi OS already installed on it, you need a slot on one of your computers that you can insert an SD card into and write the Pi OS to your SD card. Many laptops, newer computers, some tablets, and even most smart phones come with a slot for an SD card, although things keep changing and a micro SD card slot may be more typical on the newest devices. You might even be able to find some way to make your smart phone write the Pi OS to a micro SD card and use an adapter to make the micro SD card SD card sized. Otherwise, you can buy a relatively cheap ($20 or less?) SD card reader/writer box you can connect to your computer using USB. Good boxes will support 7 or more different memory card formats and have lots of different slots in them.
  • A video screen with HDMI input. You can use your TV if you want to (I did). The video is only necessary for initial Pi setup. After setup, you can set up methods to remotely control the Pi from your computer.
  • Expert users: It's also possible to avoid connecting video if you create a file called ssh in the boot partition of the SD card. This enables SSH (discussed later) which you can use to set up the Pi remotely after it boots. You will also need to figure out what IP address the Pi was assigned by looking at what devices are connected to your DHCP server.
  • A USB keyboard. Also only necessary during initial setup. A USB mouse is not necessary but may help.
  • A case. Yes, the Pi does not come with a case. A case should run $10 to $20, or you can make your own.

A good general setup guide for the Pi can be found here. I'll be giving similar instructions, but I'm not going to include as many details or screenshots.

Since I wasn't sure if Raspberry Pi would work out or not, I didn't order a case for it. Some people use the box it comes in as its case, but I didn't want to cut holes in that in case I wanted to return it. So I put a twist tie through one of the holes in the Pi and hung it up from the draw string of some blinds. You could also set it on something non-conductive and not prone to static. The pink anti-static coated bags are perfect, but the metallic grey bag the Pi comes in is not ideal because it's slightly conductive. I've seen people holding the Pi in their palm and I've read that it's not easy to damage a fully assembled circuit board like the Pi with static electricity, but I've also read you can do invisible damage with static that causes parts to fail sooner than they otherwise would, so I was as careful as possible. To that end, I recommend at least touching the metal frame of a grounded piece of electronics before handling the Pi and hold it from the edges of its board when possible. Don't touch its electronics or put undue pressure on its connectors.

To get started, download Raspbian latest version from here. This is an image of the full Pi operating system you will use to overwrite the entire contents of the SD card you're using with the Pi.

Unzip the file to create the .img file to write on the SD card. You need to get this image file onto your SD card not by copying it there normally, but by copying each byte of the image directly to the same byte on the card. To do that, you need special software. (These installation instructions)[http://elinux.org/RPi_Easy_SD_Card_Setup] cover how to set the SD card up on any operating system you happen to be using. If you're using Windows, I recommend using @http://sourceforge.net/projects/win32diskimager/files/latest/download. Unzip all files in the Win32DiskImager zip, run Win32DiskImager.exe, click its little blue folder icon and choose the raspbian.img file you downloaded. To the right of the blue folder icon, make absolutely sure you've selected the correct drive letter for the SD card you will be erasing. For added safety, unplug any USB drives or memory cards you don't want to accidentally erase. Click the "Write" button.

Put your completed SD card in the Pi, connect your HDMI video cable, the ethernet cable, and the USB keyboard. Finally, plug in the micro USB power cable. The Pi will boot immediately. There's no on/off switch (unless you buy one).

You should see white text on a black background that scrolls by for awhile. Eventually, a grey box on a blue background should appear:

image:Raspi-config.jpg width="529" height="292"

Type the down arrow key till the red bar highlights expand_rootfs, then press Enter. This will expand the Pi OS to use your entire SD card.

Highlight change_pass, press Enter, then pick a new password to log into the Pi. You can leave it set to the default password of //raspberry//, but if anyone breaks into your network they could use the Pi as a platform for causing a lot of trouble if you leave the default password in place.

Highlight ssh and enable the SSH server. SSH is what you will use to log into the Pi remotely and upload files.

HIghlight boot_behaviour and tell it to boot to desktop which will give you a graphical user interface (GUI) next time you boot. Keep in mind that running the GUi uses more power and memory and CPU. With my 850ma power supply and just a keyboard I had a lot of trouble typing when the GUI was running (the Pi wouldn't see keys being pressed, and then it would see a key press but not a release, so the key would get repeated a dozen times), but without the GUI the keyboard worked fine. I was using a fancy Dell keyboard with extra lighted buttons and a built-in USB hub and USB ports on its back, so it probably used a lot more power than a standard keyboard. Either way, I found it worthwhile to leave the GUI running so I could leave MH files open and not lose my place as I edit them off and on, adding new features and fixes.

Press the Tab key until Finished is highlighted in red, then press Enter.

It may ask if you want to reboot at this point. Tell it No. It should then leave you at a command prompt.

At this point you must decide how to set a static (non-changing) IP address for your Pi such that you can connect to it from a computer, laptop, smartphone, etc. @http://www.neil-black.co.uk/raspberry-pi-beginners-guide has a section called //Installing VNC on the Raspberry Pi for Remote Access// which you should follow, starting from where it says to type ipconfig. Alternately, if you're familiar with setting up a "static DHCP lease" on your router, you can type ifconfig and note the MAC address of your Pi in the section labeled as "eth0", then tell your router to always give the same DHCP address to that MAC address. Either way, you should follow the guide from where it says to type sudo apt-get install tightvncserver in order to install the software necessary to look at your Pi's GUI desktop from another computer.

Once you've got tightvncserver installed, type sudo reboot

The Pi should boot to its GUI desktop, showing a big raspberry on a white background. At this point, you should be able to connect to the Pi and see that desktop by running any VNC client on another computer or smart phone/tablet. If you can't get VNC connected and you don't have a USB mouse or can't get one to work with your power supply, hold the Windows key and then press the R key. Much like in Windows, this brings up a box you can use to run a command. Type lxterminal in the box and press Enter. Now you have a command prompt you can use to type commands like ifconfig to verify the IP address of your Pi.

If you don't want to use VNC or you can't get it working, you can SSH to your Pi machine to at least get a command prompt. Log in as pi with the password you set (raspberry by default). On Windows, I recommend downloading @http://www.putty.org/ as an SSH client. On Unix and Mac, type ssh [email protected] from a command prompt, replacing 192.168.x.x with the actual IP address of your Pi.

Once you get VNC or SSH connected, unplug the USB keyboard and mouse so they don't draw power.

Using TightVNC client to connect to the Pi from Windows, I found it kept disabling the clipboard in my other programs, especially when I copied and pasted to virtual Ubuntu machines running in VirtualBox. In fact, something about TightVNC seemed to cause VirtualBox machines to stall when hibernating or unhibernating, and one time it even affected my whole computer, preventing me from shutting down. I stopped using TightVNC and haven't had the problem again so far, so watch out for that. I was thinking of trying TigerVNC but decided it was safest to use the Remote Desktop Viewer that comes with Ubuntu from within an Ubuntu VirtualBox machine I always have up for virus-free web browsing.

The tightvncserver on the Pi actually doesn't support clipboard sharing by default. To get it working, you must run sudo apt-get install autocutsel and then run autocutsel from a command prompt on the Pi. autocutsel must be run as the same user that tightvncserver is running as or you'll get an error "Client is not authorized to connect to server", so if tightvncserver is running as root, then run sudo autocutsel instead of autocutsel. I only leave autocutsel running for as long as I need to transfer clipboard contents back and forth to the Pi because leaving it running can cause the clipboard to fail in other applications when using Remote Desktop Viewer. I have also crashed lxterminal twice trying to copy about 100,000 lines of its buffer with autocutsel running. Without autocutsel, the copy succeeds. Note that I did not have autocutsel running when TightVNC was causing all its problems.

At this point, you can use the Midori web browser you'll see in the upper left corner of the Pi GUI to download MH. Follow instructions in the @misterhouse/Insteon wiki for initial MH setup. I encountered absolutely no errors running the standard MH with Insteon support enabled. All the Perl frameworks and modules it needs come pre-installed on the Pi's OS.

If you already have MH set up on another machine, you will need a way to transfer those files to your Pi. I used @http://sourceforge.net/projects/winscp/ on Windows but if you're running Unix or Mac, you should have the scp command already built in - Google how to use it with the Pi. With WinSCP, make sure to choose "SCP" from the pulldown menu instead of "SFTP". Use pi as the user name and whatever password you set (raspberry by default).

One problem with running MH on an SD card is that you can only write data to an SD card some finite number of times before parts of the SD card deteriorate and become unwritable. Older or cheaper cards may only be writable 10,000 times in each memory cell, but 100,000 writes seems to be average. In newer cards, the controller in the card itself should spread writes out evenly across the card and detect when cells are going bad, remapping to a newer cell, usually without corrupting data. The big problem is that writing even one byte to a cell that's already written requires erasing a whole block of cells and then writing the whole block with the changed byte. Block size depends on the card, but you can see your block size with cat /sys/block/mmcblk0/device/preferred_erase_size In my 16 gig card the block size is 4mb, which means the whole card has only 4000 blocks and if each write causes an erase, that's 400 million writes before the card goes bad. If there is one write per second, the card will fail in 12.68 years. Realistically, the OS or the card should cache writes and group them together, reducing the frequency of writes. MH itself will tend to generate some writes about once per minute as it saves objects, and other running processes will also generate some writes as they perform logging, so the actual number of writes should be far less than once per second. Still, since I don't know if I'm using a card that supports 100,000 writes per cell or only 10,000, I've disabled as many writes as possible to the SD card. Here's what I did after installing MisterHouse to /home/pi/MisterHouse:

  • You can skip this section if you want. I'm guessing a good SD card will last decades under normal MH usage, but also remember that older SD cards were designed for things like cameras that don't write very frequently. Whether you reduce MH writes or not, you should at least back up your MH configuration periodically to avoid losing your custom scripts and setup.
  • Disable MH logging: ** Edit /home/pi/MisterHouse/misterhouse/bin/mh using a command-line editor like nano or vi, or the GUI editor called Leafpad you can find by clicking the lower left corner of the desktop and looking in the Accessoriescategory. ** Search for sub print_log. ** Below sub print_log, find a line that reads **if ($logfile) {**​ ** Add return; right above the if ($logfile) { line.
  • Disable MH web server logging: ** Edit /home/pi/MisterHouse/local/mh.private.ini ** Add this to the bottom of the file:no_log = http_local
  • Save objects once a day instead of once a minute: ** Edit /home/pi/MisterHouse/misterhouse/bin/mh ** Find this line: &object_states_save if $New_Minute and !($Time_Start_time or $Time_Stop_time); # Skip if in accelerated mode ** Change $New_Minute to $New_Day. This prevents writing MH data to your SD card every minute. This may cause problems if MH crashes but otherwise I don't think it's necessary to write the on/off state of all your devices unless you have some special devices that require extra care. In an Insteon environment, the startup scan should get device states when MH starts anyway, so with an Insteon setup or any setup where devices can be queried for state I'm not sure if saving state is at all necessary (I could be wrong, but I haven't seen problems).
  • Disable nightly update of MisterHouse docs: ** Visit the MH web page at http://:8080 ** Click MrHouse Home ** Click Setup MrHouse on left. ** Click Edit Triggers ** In the trigger with Name "update the documentation", change Type to "Disabled".
  • Things I haven't bothered to do yet: ** Disable tightvncserver logging

I found that the Leafpad text editor was far too simplistic for editing MH code. It doesn't even have a way to search upward for matches instead of downward. So I installed geany using sudo apt-get install geany Note that geany will use more memory and run slower than Leafpad but even with geany and MH running for six days my Pi model B is only at 35% CPU and 120mb free memory.

I'm starting to suspect that LXTerminal leaks memory because the longer I leave it running, the less memory I have, and closing it often frees a lot of memory.

==How to start MisterHouse automatically when the Pi boots==

  • Create a directory called /home/pi/.config/autostart
  • Create a file called /home/pi/.config/autostart/mh.desktop
  • Edit mh.desktop to contain the following contents: ** [Desktop Entry] ** Type=Application ** Exec=lxterminal --command 'bash -c "sudo /home/pi/MisterHouse/mhl; exec bash"'
  • The Exec line above is more complicated than I would like but it seems to be the only way to get MH to start in an lxterminal window that doesn't close when MH is quit or terminated with ctrl-C. This is accomplished by running 'exec bash' as a second command after 'mhl' exits. If you don't want the lxterminal window to remain open if mhl exits, you can use

Exec=lxterminal --command 'sudo /home/pi/MisterHouse/mhl' instead.

  • Run sudo reboot from a terminal to restart the Pi.
  • If MH doesn't start after reboot, check the contents of the /home/pi/.xsession-errors file for clues.

==Run Houselinc using PLM connected to Raspberry Pi==

HouseLinc is Windows-only software made by SmartHome. It used to cost money but they made it free sometime in 2012. It can be used to do a few things that MH can't do, like change the brightness of the LED on newer Insteon devices or control every setting on an Insteon Thermostat or other new/less common devices for which MH doesn't have complete support. You could unplug your PLM from the Pi and plug it in to your computer before you start HouseLinc, but the process described below will let HouseLinc use your PLM as if it were a "Hub".

  • Install socat by running apt-get install socat
  • Stop MisterHouse.
  • sudo socat tcp-l:9761,reuseaddr,fork file:/dev/ttyUSB0,nonblock,waitlock=/var/run/ttyUSB0.lock ** Replace ttyUSB0 with ttyUSB1 if your PLM ends up connected to USB1.
  • Edit mh.private.iniand add this line: ** debug=insteon:4 ** Comment out any other debug= lines by adding # to the front of the line.
  • Start MH and look for this: ** 04/28/2013 12:13:40 AM [Insteon_PLM] DEBUG4: Milliseconds 792.62

PLM Command: (0260) plm_info PLM Device ID: 12:34:56 Device Category: 03:15 Firmware: 9b PLM Response: (06) ACK

  • Note the Device Category and Firmware values.
  • Stop MisterHouse.
  • Unfortunately, HouseLinc will refuse to use a PLM over the network if it doesn't report itself as a network PLM, so we have to trick HouseLinc into thinking your PLM is actually a "Hub" (SmartHome's latest network PLM as of 2013).
  • Open in a text editor: C:\Users\Public\SmartLabs\HouseLinc\Devices.xml or Devices_Beta.xml, whichever one exists in the directory. ** Find your PLM in the file. If your Device Category was 03:15, search for category="0x03" subcategory="0x15". In my case, the entry looks like this: ***

PowerLinc USB Modem (Dual-Band) [2413U] ** Change subcategory to "0x37" (the category for a Hub). ** Find this section: *** <device displayName="Hub" category="0x03" subcategory="0x37" productKey="0x000000" flags="0x0008"> Hub ** Change subcategory to whatever the subcategory of your PLM was. In my case, that's 0x15. ** Now HouseLinc will think your PLM is a Hub and a Hub is your PLM.

  • Run HouseLinc
  • The first time you run it, it will most likely say "No computer interface found". ** Click Let me manually configure my computer interface ** Click Next ** Choose Hub (just "Hub", not "Hub, US" or any of the similar options). ** Type the IP address of your Pi in the box that appears. ** It should say the device was found. Click Next. ** It should say activation was successful. If it says "Ooops" then you most likely didn't edit your Devices.xml file correctly, or maybe you edited it while HouseLinc was running.
  • If HouseLinc asks if you want to run a background synchronization or any kind of synchronization, answer no. Synchronizing will modify the ALDB on your insteon devices according to what HouseLinc thinks should be there, usually creating duplicate records or deleting records you created with MH.

==Expert Users and MisterHouse Developers==

One other completely optional thing you can do is get PLMTerminal.pl working on the Pi. PLMTerminal.pl is useful for sending raw Insteon commands to your network through your PLM and looking at the raw responses. This is probably something only a MH developer would need to do, but here's how to do it in case anyone needs it:

  • Run sudo cpan from a command prompt.
  • Answer yes to autoconfig and setting up mirrors.
  • At the cpan1> prompt, type install Term::ReadKey
  • When it's done installing, type quit
  • cd /home/pi/MisterHouse/misterhouse/lib/Insteon
  • ./PLMTerminal /dev/ttyUSB0

If you want to add support for a new Insteon device but you can't find its commands documented, try using HouseLinc to control the device. Set HouseLinc logging level to "Trace" and look at C:\Users\Public\SmartLabs\HouseLinc\Logs\HouseLinc.log to see what commands are being sent/received. If the log isn't working you can also run a network packet sniffer like Wireshark if you're connecting to the PLM over the network.

That's it. Enjoy your $2/year, 2 watt MisterHouse server!

Clone this wiki locally