Skip to content
ggodart edited this page Jan 23, 2021 · 13 revisions

Installing MisterHouse on a Raspberry Pi

This page will describe how to set up a Raspberry Pi mini computer to run MisterHouse including the Insteon PLM.

Index

About the Raspberry Pi

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. There are now 4 generations of Raspberry Pi from the Model A to the Pi 4, the original Raspberry Pi (Model A) had 256mb memory and one USB port and sold for less than $25, for todays like up, please see The Raspberry Pi Web site. Pis have GPIO pins that can be used for advanced projects. We have seen MisterHouse running on all models of Pi, except the Pi Zero which may be a little underpowered (can anyone confirm/deny this?)

MIsterHouse 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 Pi 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 or a wifi USB dongle if you Pi doesn't have built in WiFi (newer models do). 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.

Step 1, Getting the Pi to boot

There is a number of ways to get you Pi to boot from your chosen media with excellent guides on the internet and in these pages, they mostly rely on booting form Micro Sd card, then migrating to a USB disk later;

These assume you have your Pi connected to a screen via HDMI and a USB keyboard and mouse.

Step 2, Configure the Operating System

Next you need to make changes to enable remote log in by SSH, static IP address etc. Note that if you used the Pi Imager, some of these steps may have already been done during the initial boot.

raspi-config

Open a terminal window on the Pi and run sudo raspi-config and set the following;

  • change the pi password from raspberry
  • set timezone and locale,
  • set hostname
  • enable GPIO access(if needed) You will need to reboot for these to take effect. Next (if you skipped this during the initial boot up) you need to make sure your Pi has the latest updates. Open a ternila window and run;
sudo -s
apt-get update
apt-get upgrade

If you need to change the password again, use the passwd

Boot from USB

If you want to boot from a USB device, the mechanism is different for different models of Pi, see here for details.

Static IP address

Edit /etc/dhcpcd.conf' (e.g. sudo nano /etc/dhcpcd.conf` to add the following at the end

/*
interface eth0
static ip_address=192.168.100.66
static routers=192.168.100.1
static domain_name_servers=192.168.100.1

In this example my ip address is 192.168.100.66 etc.. You need to sudo reboot for these to take effect To check if the IP address is correct

ifconfig -a

Some installs did not include nslookup, if this command fails, you need to sudo apt-get install dnsutils

set up the hardware watchdog

See here for how to set up the hardware watchdog.

Final checks;

  • check the hostname (this will allow you to ssh hostname.local instead of remembering the IP address) by entering hostname, if its wrong, change it using sudo raspi-config
  • check the date and time is correct by typing date, some installs had errors see here for advice.

Step 3, MisterHouse installation

Follow instructions in the wiki for initial MisterHouse setup. I encountered absolutely no errors running the standard MisterHouse with Insteon support enabled. All the Perl frameworks and modules it needs come pre-installed on the Pi's OS.

If you already have MisterHouse set up on another machine, you will need a way to transfer those files to your Pi. I used 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 MisterHouse 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. MisterHouse 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