Skip to main content

How to use FHEM with Home Assistant

2 min read

I have started several years ago using FHEM to automate some of my devices. Last year though, I discovered Home Assistant. It fits much better my technology stack as it's written in Python instead of Perl, so I started to migrate to it.

As always I'm running against some walls. It was impossible to get my IR-bridge (which switches on the amp) running in Home Assistant, so I needed a way to use the existing FHEM within Home Assistant.

First I opened a new FHEMWEB port (bind only on localhost) with csrfToken check switched off:


define WEBapi FHEMWEB 8086 global
attr WEBapi csrfToken none
attr WEBapi allowFrom

Now it's possible to add shell commands to Home Assistant, it could look like this:


  fhem_shutdown_all: /usr/bin/wget -q 
  fhem_start_first: /usr/bin/wget -q

As I use homeatic I need to wire everything together in scripts.yaml:

# Use scripts with homeatic keypress as there is no delay
    - service: light.turn_off
      entity_id: light.living_room
    - service: shell_command.fhem_shutdown_all

And here I bind the turn_all_off to my Homematic Switch:

- alias: "Alle Geraete Aus"
    platform: event
    event_type: homematic.keypress
       name: WohnzimmerSchalter
       channel: 1
       param: PRESS_SHORT
     - service: script.turn_on
       entity_id: script.turn_all_off

This is my second post of my home automation series, I hope it helps someone :)