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
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.
-
Linux Foundation Adopts OMI to Foster Ethical LLMs
The Open Model Initiative hopes to create community LLMs that rival proprietary models but avoid restrictive licensing that limits usage.
-
Ubuntu 24.10 to Include the Latest Linux Kernel
Ubuntu users have grown accustomed to their favorite distribution shipping with a kernel that's not quite as up-to-date as other distros but that changes with 24.10.
-
Plasma Desktop 6.1.4 Release Includes Improvements and Bug Fixes
The latest release from the KDE team improves the KWin window and composite managers and plenty of fixes.
-
Manjaro Team Tests Immutable Version of its Arch-Based Distribution
If you're a fan of immutable operating systems, you'll be thrilled to know that the Manjaro team is working on an immutable spin that is now available for testing.