How to use FHEM with Home Assistant

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:

fhem.cfg:

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

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

configuration.yaml:

shell_command:
fhem_shutdown_all: /usr/bin/wget -q http://127.0.0.1:8086/fhem?cmd.Stop_mediacenter=set%20Stop_mediacenter%20on
fhem_start_first: /usr/bin/wget -q http://127.0.0.1:8086/fhem?cmd.wz_XBMC=set%20wz_XBMC%20on

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

# Use scripts with homeatic keypress as there is no delay
# https://github.com/danielperna84/pyhomematic/issues/106
turn_all_off:
sequence:
- 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"
trigger:
platform: event
event_type: homematic.keypress
event_data:
name: WohnzimmerSchalter
channel: 1
param: PRESS_SHORT
action:
- 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 :)