Installing FHEM on the Raspberry Pi

Lead Image © Daniel Villeneuve, 123RF.com

Up to Date

,

The FHEM home automation software is not yet part of the Raspbian package sources. We show you how to install it manually on a fresh Raspbian system.

FHEM on the Raspberry Pi (Rasp Pi) acts as a control center for the automated home. To control sensors and actions with this open source software, you need suitable hardware. The Rasp Pi 2 and 3 models (RPi2/3) immediately come to mind because of their performance and frugal power consumption. The installation steps presented in this article are based on the precondition that you have already installed a Raspbian "jessie" image [1] on a microSD card of at least 8GB.

To complete any necessary preparatory work, you should connect the Rasp Pi to a power supply and the Internet. If you are working without a display screen, you can verify that the computer has booted by paying attention to the LEDs. During the boot process, all of the lights (orange, green, red) should light up. After a successful start, only the red light will be remain on. If the Rasp Pi does not start properly or if you have a problem, you should install the image again.

Finding the Rasp Pi

Now you need to find the Rasp Pi's IP address for use in the future home control center. Raspbian displays it on the screen shortly before finishing the boot process, but the router web interface is the easiest place to find the address, which the router usually assigns by DHCP, when no display is available (also see the "ARP" box).

ARP

If you are operating a headless Rasp Pi (i.e., a Pi without a monitor), you can use the address resolution protocol (ARP) [2] to track down your Pi.

The program arp-scan typically can be installed from the package sources in larger distributions. The program selects ARP tables stored by the system and delivers a report containing the list of IP addresses active in the network. The list includes the MAC address and the name of the manufacturer for each network chip. This output makes it simple to identify Rasp Pis present on the network:

$ sudo arp-scan -l | grep Raspberry
192.168.111.137 b8:27:eb:e4:e1:30 Raspberry Pi Foundation
192.168.178.250 b8:27:eb:7c:5f:e1 Raspberry Pi Foundation

With a residential gateway device like a FritzBox, you can access the configuration from the URL http://fritz.box. The IP addresses administered by FritzBox can then be found under Home Network | Network | Network Connections (Figure 1). The Rasp Pi usually appears under the name raspberrypi. An alternative solution is to let Adafruit Raspberry Pi Finder [3] (available for Linux, Mac OS  X, and Windows) locate the IP address (Figure 2).

Figure 1: Finding the IP address for a Rasp Pi operated without a monitor via the web front end of your router. In this case, it was a FritzBox.
Figure 2: The Adafruit Raspberry Pi Finder application rummages around for the Rasp Pi and offers a few other functions, as well.

The next step involves controlling the SSH terminal for the Linux system that has been installed on the Raspberry Pi by opening the terminal window and entering the SSH command. If name resolution works on the router, you don't even need the IP address: It suffices to specify the name raspberrypi:

$ ssh pi@<IPAddress>
$ ssh pi@raspberrypi

The default access settings are pi for the username and raspberry for the password.

If you are working from a Mac, you should open the Spotlight search feature (magnifying glass icon at the upper right corner) and enter "Terminal" to select the corresponding match. Windows users have the free PuTTY SSH client [4]. In PuTTY, you enter the IP address for the Rasp Pi under Host Name (or IP address) and click Open (Figure 3). You must accept the as yet unknown SSH key for the Rasp Pi system the first time a connection is established.

Figure 3: The free program PuTTY supplies the SSH client Microsoft left out of the operating system.

You should reset the default password in a terminal by using the passwd command. The program asks for the old password (raspberry) once, then your new password twice. If you have not yet worked with the Rasp Pi, you also should open the configuration tool with the

sudo raspi-config

command and establish the most important settings for the operating system (Figure 4), including setting the language, expanding the data partition to the entire memory card, and setting the time, which is especially important for a Rasp Pi that functions as a control center.

Figure 4: If the Raspbian installation on your Raspberry Pi is fresh, you should complete the configuration before installing FHEM.

Installing FHEM

After you have changed settings in raspi-config, you should restart the Pi, which will close the network connection. Now log in again, update the system, and install the Perl module needed by FHEM while you're at it:

$ sudo apt update
$ sudo apt full-upgrade
$ sudo apt install perl libdevice-serialport-perl libio-socket-ssl-perl libwww-perl libxml-simple-perl

After this you should download FHEM and install it via the Debian package management system (dpkg) used by Raspbian:

$ wget http://fhem.de/fhem-5.7.deb
$ sudo dpkg -i fhem*.deb
$ sudo apt install -f
$ sudo reboot

Just to be safe, you should check the dpkg output for any dependencies that might be missing before issuing the reboot command. (See the "Update Advice" box for more information on installing FHEM.)

Update Advice

A new version of FHEM might be available by the time you read this article, which means the wget link leads nowhere. Therefore, you should check the FHEM homepage [5] and make corrections to the link name and version number if necessary. Because FHEM is installed from source, you need to proceed in the same way when updating an existing FHEM installation.

FHEM starts automatically after installation – without, however, sufficient access rights in the /opt/fhem installation directory. Therefore, you should include pi and fhem in the tty group so they can access the serial interfaces and USB ports. This is done by closing the FHEM service, performing the necessary modifications, and then restarting:

$ sudo service fhem stop
$ sudo chmod -R a+w /opt/fhem
$ sudo usermod -aG tty pi
$ sudo usermod -aG tty fhem
$ sudo service fhem start

FHEM will now automatically start with Raspbian on the Rasp Pi. To control the service, open a web browser on a PC and enter in the address line the IP address for the FHEM Rasp Pi as the URL with the port number 8083 (e.g., http://<IPAddress>:8083). If DHCP name server resolution works correctly, you should also be able to reach the system under http://raspberrypi:8083.

Once the web interface has been called up, it is time to secure the username and password so that only you have access to the system in the future.

Buy Raspberry Pi Geek

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

US / Canada

Get it on Google Play

UK / Australia

Related content