Skip to main content

How to integrate AVM smart devices into HomeKit by using openHAB

After some evaluating openHAB (Vers. 2.2.0) on my NAS I wanted to do it right and started with this (German) article to use openHABian together with a Raspberry Pi.My primary goal was to integrate my AVM smart home devices to control them with HomeKit.

To get started I used the following items:
  • Raspberry PI
  • SD Card 16 GB
And the following software (I used a Mac, so you might need to replace some tools if you use another OS):
  • Download the latest openHABian image here. This is a dedicated linux distribution to provide an openHAB server.
  • Download SD Formatter here. Needed to format your SD card.
  • Download Etcher here. Needed to install the openHABian image on the SD card.

Installation openHABian

  • Insert the SD card
  • Connect the Raspberry Pi via LAN with your network
  • Plugin the Raspberry Pi
  • Wait about 45 minutes until all updates were installed
  • When everything went well you should be able to connect to http://openhabianpi:8080
  • Connect via ssh: ssh openhabian@openhabianpi (standard password: openhabian)
  • Open the config: sudo openhabian-config
  • Run 01 "Update"
  • Run 02 "Upgrade System"

Configuration openHAB

Configure AVM Things

First of all you need to connect the Fritz!Box, therefore you should get a notification in the inbox in PAPER UI:
You just need a Fritz!Box user. I created a dedicated one which only has the permission "Smart Home". HTTPS is only available when you MyFRITZ! Service for remote access. When the Fritz!Box is connected all other connected smart devices become visible:

Configure HomeKit Add-on

You can keep all the defaults, but you need to add the IP for the interface. In my case this is just the same IP as the Raspberry Pi has, my PI just has one network interface.

If you do not add the IP here your device will be listed in the Home app but paring will always fail, as described here.

Create HomeKit Items

To use your items with HomeKit you need to create so called "accessories" as described here. As follows a little sample:

Switch HK_Livingroom_Light "Light Livingroom" <light> (gLightLivingroom) [ "Lighting" ] { channel ="avmfritz:FRITZ_DECT_200:10_51_2_165:667777888999:outlet" }

Number HK_Livingroom_Temperatur "Temperature Livingroom" (gTemperatureLivingroom) [ "CurrentTemperature" ] { channel ="avmfritz:FRITZ_DECT_200:10_51_2_165:667777888999:temperature" }

To copy the items I use the following command:
scp /Users/philipp/Desktop/HK.items openhabian@openhabianpi:/etc/openhab2/items/HK.items

Start openHAB service manually

Type in the following command to start the service manually:

sudo systemctl start openhab2

Start openHAB within terminal session

1. openhab-cli stop
2. openhab-cli clean-cache
3. openhab-cli start

This will start the service and also the Karaf console. When you close your SSH session the service will also go down.

To just open the Karaf console for your existing instance use:
openhab-cli console

Start openHAB service automatically after reboot

sudo systemctl enable openhab2
sudo shutdown -r now
sudo systemctl status openhab2

Use the script above to enable automatic start after reboot and to test it.

Permission Fix

For some reason the permission was messed up and I had to fix it with sudo openhabian-config. 

Trace & Debug issues

To trace issues with the HomeKit integration I enabled trace for it by submitting this command within the Karaf console:

log:set TRACE com.beowulfe.hap

To change it back I used

log:set DEFAULT com.beowulfe.hap

HomeKit Pairing

I paired my openHAB with the iOS Home app.
  1. Open the app 
  2. Add new device
  3. Choose "Code is missing or cannot scan" below
  4. Here the openHAB instance should be listed
  5. Select it and type in the code you defined in openHAB's HomeKit add-on configuration.
  6. Pairing should be successful now.

Reset HomeKit Pairing

  1. ssh -p 8101 openhab@localhost (not needed with openHABian anymore)
  2. smarthome:homekit allowUnauthenticated true
  3. smarthome:homekit clearPairings

Add SSH Key

To create and upload my SSH key I used a Mac. So you might need to adapt your script to do it with another operation system.
  1. Create SSH key: ssh-keygen -t rsa
  2. Copy public key to the Raspberry Pi: ssh-copy-id openhabian@openhabianpi
  3. Type in the passphrase so you do not need to type it in again: ssh-add
On a Mac you can create a bookmark. Therefore you need the following commands:

1. To create the needed config file: nano ~/.ssh/config
2. To create the bookmark you need the following lines:

Host openhab
User openhabian
Port 22
HostName openhabianpi
IdentityFile ~/.ssh/id_rsa

3. with ctrl + x you leave nano and you will be asked to save the file
4. Then you can open the terminal with ssh openhab without typing in a password
5. With passwd I changed my password for the user openhabian to get rid of the default password

Add Fritz!Box certificate (Update 2020-04-25)

  1. scp /Users/myuser/Downloads/boxcert.cer openhabian@openhab:./fritz.crt
  2. sudo find / -name jre
  3. cd /opt/jdk/zulu8.40.0.178-ca-jdk1.8.0_222-linux_aarch32hf/jre/bin
  4. sudo ./keytool -importcert -alias fritzbox -keystore /usr/lib/jvm/zulu-8-amd64/jre/lib/security/cacerts -file ./fritz.crt
Then it is possible to configure your Fritz!Box with https:

Popular posts from this blog

How to get started with Windows Server AppFabric easily

In my opinion it is really hard to get started with Windows Server AppFabric. There is good material, but it is shuffled around in different sources. A good intro can you find here: this all-in-one intro by Scott Hanslmann  this caching intro by Wade Wegener  Additional helpful resources are Microsoft's Introduction Part 1 and Microsoft's Introduction Part 2 by Jon Flanders  Pluralsight's Hosting Fundamentals   Pluralsight's Caching Introduction   Microsoft's Caching Documentation   Good books are Microsoft Windows Server AppFabric Cookbook   and Pro Windows Server: AppFabric Please also watch out for software updates, currently there is CU 4 . To keep yourself updated subscribe to Distributed Services News Feed . Updated my list on 11.03.2014 with one more Download the Windows Server AppFabric Samples

How to fix Windows Server AppFabric Dashboard on Windows Server 2012 / Windows 8

Windows Server AppFabric is a great enhancement for IIS and its caching capabilities are great for .NET applications. But currently there is a very annoying bug regarding its monitoring UI, so called “Dashboard”. Especially for me as a non WF guy (I am actually just working with WCF) it was really hard to figure it out. Hence, many thanks to Gianluca from Distributed Services at Microsoft! Windows Server AppFabric Dashboard does not work on Windows Server 2012 / Windows 8. You will receive this error message "Unable to cast object of type 'System.Management.Automation.PSCustomObject' to type 'Microsoft.ApplicationServer.Management.Data.GroupByInfo'." This error will cause that you cannot see any request statistics neither WF nor for WCF: The reason is, I quote Microsoft here: "[...] the root cause is a powershell script embedded in AF code that returns different results when ran on Windows 2012. This script is about statistics for Idle & per...

How to move iTunes library to NAS folder

This is nothing new, but to free up some space on my MacBook I decided to move my iTunes library to a network drive on my NAS. I got some inspiration from this old German video. I tried to collect all relevant information for doing so. I did it by following this steps  I closed iTunes I mounted a network drive with AFP I copied my iTunes library folder to a folder on the network drive (it is important to keep the folder name "iTunes"!) I opened iTunes while pressing the "alt" key. Now you can create a library or choose one from another location I set the new iTunes folder I deleted the local iTunes library My iTunes settings look like this now, iTunes took over the selected folder: Keep in mind the following You cannot open the iTunes library with two accounts at the same time. When you choose to set "Keep iTunes Media folder organized" iTunes will set your folder structure for artists an albums and also the file pattern for your s...