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 :)

My road to a privacy voice assistant

Mycroft as voice assistantSince ages I have worked sporadicly on my home automation system. My first and biggest motivation was   to get ONE button to start the music system and play my music. Meanwhile I got a bigger plan: TELLING the system to play music.

And it should not be a kitchen radio with a lousy speaker.  I got the button-press-music working, and it does a lot:

  • Switches on the power plug from the amp
  • Switches on the amp with a IR-bridge
  • It sends a WOL packet to the mediasystem (Kodi)
  • It chooses a album from my media collection and sends a API call to Kodi to start playing

Right now it's buried into fhem (my old home automation software) and some custom python scripts. To be honest I don't know how it works anymore :)

So, to get the music played, I now only need to press ONE button :) But my plan is to tell the system "play music", just like Alexa in the tv spots. But of course, Alexa, Spotify and all the other cloud services are not an option as I want my system to be open source and to protect one's privacy.

That is why I've baked the Mycroft Mark II at Kickstarter and I plan to get my home automation setup ready for it! Here is what Mycroft wants to be:

The open answer to Amazon Echo and Google Home. Mycroft brings you the power of voice while maintaining privacy and data independence.

If all goes well Mycroft Mark II will be shipped by the end of the year. To get ready for it I plan to do a series of blog posts about it:

  • Describe the system I use and what i have learned
  • Integration of Kodi as a media center

...