FHEM – Setup, practical use, and alternative interfaces
At Your Service
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.
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.
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
(incl. VAT)
Buy Linux Magazine
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.
News
-
First Release Candidate for Linux Kernel 6.14 Now Available
Linus Torvalds has officially released the first release candidate for kernel 6.14 and it includes over 500,000 lines of modified code, making for a small release.
-
System76 Refreshes Meerkat Mini PC
If you're looking for a small form factor PC powered by Linux, System76 has exactly what you need in the Meerkat mini PC.
-
Gnome 48 Alpha Ready for Testing
The latest Gnome desktop alpha is now available with plenty of new features and improvements.
-
Wine 10 Includes Plenty to Excite Users
With its latest release, Wine has the usual crop of bug fixes and improvements, along with some exciting new features.
-
Linux Kernel 6.13 Offers Improvements for AMD/Apple Users
The latest Linux kernel is now available, and it includes plenty of improvements, especially for those who use AMD or Apple-based systems.
-
Gnome 48 Debuts New Audio Player
To date, the audio player found within the Gnome desktop has been meh at best, but with the upcoming release that all changes.
-
Plasma 6.3 Ready for Public Beta Testing
Plasma 6.3 will ship with KDE Gear 24.12.1 and KDE Frameworks 6.10, along with some new and exciting features.
-
Budgie 10.10 Scheduled for Q1 2025 with a Surprising Desktop Update
If Budgie is your desktop environment of choice, 2025 is going to be a great year for you.
-
Firefox 134 Offers Improvements for Linux Version
Fans of Linux and Firefox rejoice, as there's a new version available that includes some handy updates.
-
Serpent OS Arrives with a New Alpha Release
After months of silence, Ikey Doherty has released a new alpha for his Serpent OS.