FHEM – Setup, practical use, and alternative interfaces

At Your Service

Article from Issue 230/2020
Author(s):

If you want to equip your home with smart technology, you will need to deal with a variety of providers and what are often incompatible standards. FHEM is a free integration platform that houses the building blocks under one roof and offers visually appealing interfaces.

FHEM [1] is an open source server for home automation. Your FHEM system can control Internet of Things (IoT) devices, such as lamps, thermostats, shutters, audio equipment, and all the other gadgets that populate a smart home. You can interact with FHEM through a smartphone front end or even over the web.

FHEM supports several different home automation protocols and has a number of different interfaces for the user to interact with directly or through a script. The modular architecture currently includes more than 430 modules.

The quality of an open platform depends on the commitment and skills of the community backing it. That commitment is evident in the case of FHEM. The FHEM Forum, the official contact point for enthusiasts, now has more than 20,000 members.

Although the number of available software modules was quite small just a few years ago, experienced users can now turn to countless modules to integrate not only Homematic (the classic wireless standard), but also widely used standards in the smart home sphere, such as Zigbee (used by Philips Hue and Ikea Trådfri, among others) or Z-Wave. Cable-based standards such as OneWire, DMX, or the KNX professional standard are also supported.

Using the official Tesla API, you can even read out your electric vehicle's status values, such as the current battery charge level. As soon as the battery is fully charged, FHEM can then trigger speech output to say, via a Sonos speaker, "Your Tesla is ready to go."

Setting Up

FHEM is based on the Perl programming language and is therefore genuinely lightweight when it comes to hardware requirements. In the early days, FHEM would even run on a FRITZ!Box router until the vendor, AVM Software, put a stop to this – officially for security reasons.

The popular, single-board Raspberry Pi is a worthy successor with more than sufficient resources. On a basic system, FHEM can be installed with just a few commands at the console. Start by importing the required repository key and adding the repository (Listing 1, lines 1 and 2).

Listing 1

Installing FHEM

01 $ wget -qO - http://debian.fhem.de/archive.key | apt-key add -
02 $ echo "deb http://debian.fhem.de/nightly/ /" >> /etc/apt/sources.list
03 $ apt-get update
04 $ apt-get install fhem

Then update the package sources and install FHEM (lines 3 and 4). Depending on the configuration, you may need to run the commands with sudo to have the necessary system permissions. Occasionally, the repository does not work properly, in which case, you will need to manually install Perl and FHEM [2].

First Steps

Once the installation is complete, you can access the FHEM web interface on port 8083 by typing http://<RaspPi_IP_address>:8083 in a web browser. The FHEM interface (Figure 1) uses a simple, unpretentious, and functional design – don't bother looking for graphical components. This simple approach is an advantage for experienced users, but it does raise the bar for newcomers.

Figure 1: The simple FHEM web interface can be reached on the default port 8083.

The central element in the standard interface is the white bar at the top, where the user can enter commands. You can issue commands to configure and manage the system. FHEM even comes with a very useful syntax check that has been available for some time and that the community is constantly improving.

Use the define command to add a new device to the configuration. A command based on the syntax of Listing 2, for example, integrates the popular Harmony Hub, which can control your TV and AV receivers via a built-in infrared transmitter module and a Bluetooth transceiver.

Listing 2

Integrate Harmony Hub

define HarmonyHub harmony <I>User<I>:<I>Password<I> <I>IP_Address<I>

define is followed by the desired FHEM device name (HarmonyHub in Listing 2). In the case of the Harmony Hub, FHEM then requires the login data in the form of user_name:password. Finally, enter the device's IP address and press the Enter key.

The configuration will become second nature after you have added a couple of devices. But be careful: Every configuration change to FHEM has to be confirmed by pressing the Save config button in the web interface. This step adds the new settings to the fhem.cfg file.

As soon as you have successfully integrated the Harmony Hub, you can click on the HarmonyHub FHEM device and view the values that appear in the DeviceOverview window (Figure 2). These values are known as internals and readings in FHEM speak.

Figure 2: The FHEM module used for integrating the Harmony Hub.

The readings are of interest for automation rules, which I will discuss later. In the case of the Harmony Hub, the readings are fairly terse, but interesting nonetheless. For example, the currentActivity reading provides information on the current activity. You can see, for example, whether television mode is enabled or whether the controllable devices are in standby mode.

Conversely, you can send switching commands from FHEM to the Harmony Hub via the set commands, which are also displayed automatically and can be selected via drop-down menus. In this way, you can simulate input from the Harmony Remote.

Getting Started with Automation

The whole thing becomes exciting as soon as you start using the available readings to trigger other devices. The currentActivity reading, which reacts in real time to changes in the Harmony Remote's selected activity, is useful for triggering actions. To enable FHEM to also use this reading for automation purposes later on, you still need an attribute. The FHEM console command from line 1 of Listing 3 enables the Harmony Hub device to actually trigger an activity when changes to the state and currentActivity readings occur.

Listing 3

FHEM console commands

01 attr HarmonyHub event-on-change-reading state,currentActivity
02 define LampSwitchOff notify HarmonyHub.currentActivity:.starting.Apple set Living room lamp off
03 define News at *20:00:00 set HarmonyHub activity Television;; set HarmonyHub command TV Number 1

Some readings can already possess this attribute by default, although this is not always the case. It is best to use a self-assigned attribute value to define which reading is allowed to perform an activity. But beware: Manually defined attribute values override a device's default values.

The FHEM console command from line 2 of Listing 3 can be used to automatically switch off the FHEM Living room lamp device with an off command as soon as the current Harmony Hub activity switches to starting.Apple.

The notify command performs the notification, but you can also use the doif, doelseif, and doelse options to add conditional branching.

If you are wondering about the dots in line 2 of Listing 3: Spaces are always written as dots in order to be interpreted correctly by the Perl engine working in the background.

All events starting up in FHEM can be viewed in the Event monitor in the FHEM user interface.

In addition to notify and doif, there is also the at command, which you can use to start a certain action at a certain time every day. The FHEM console command from line 3 of Listing 3, for example, starts the Harmony Hub Television activity daily at 8 pm. The TV then switches to channel 1.

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

  • PiXtend V2

    The PiXtend board extends the Raspberry Pi with many useful interfaces and functions for new target groups.

  • Freescale Calls Up Second Generation Internet Tablets

    Freescale drums at the Consumer Electronics Show (CES) in Las Vegas. Just as smart, but a bigger display than the Smartphone and costing less than $200 is what the next Internet Generation of 12 to 25-year-olds wants. At least the chipmaker has a fitting idea for it.

  • xsetwacom

    With a little extra effort, on-the-fly adjustment of your graphics tablet on Linux is possible with this command-line tool.

  • Project Harmony Launches Today

    "Project Harmony is like Creative Commons for contributor agreements. We've set out to capture the best practices of free and open source software contributions, across a diverse array of project cultures, communities, and values." said Allison Randal, a community participant in Project Harmony. "The public review process for the Alpha versions of the documents launches today, and runs through May 6th. After a year of hard work by the original ~100 drafting volunteers, we're really looking forward to broader participation in this public review."

  • Controlling a Smart Plug

    You could spend hundreds of dollars on specialized IoT appliances and fixtures, or you could just hack a smart plug and talk to it with your Linux system.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News