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

Clean up AppFabric Dashboard Part 2: Duplicate collection entry in Web.config

In Part one I have already described how to remove phantom apps here on more supplement. These phantom apps could also remain in the AppFabric Monitoring db:

Just delete no longer needed entries in this table.
Duplicate collection entry When you receive this kind of issue, like "[...] Cannot add duplicate collection entry [...]" you have defined the a configuration section twice in two different Web.config files in different places in your file system.

Clear One easy solution is to use a clear statement. Searching for the inherited element There is a post in Microsoft's documentation which is explaining how to do it. Visual Studio in debug mode When you are working with Visual Studio in debug mode, which means you are just pressing F5 to run it on your local IIS instead of publishing it to a web server, you should keep in mind that e.g. your obj folder might contain more copies of your Web.config file. This could lead into this duplicate collection issue as well.

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 iTunesI mounted a network drive with AFPI 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 folderI deleted the local iTunes library My iTunes settings look like this now, iTunes took over the selected folder: Keep in mind the followingYou 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 songs. You have to think about th…