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
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.