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

Have you ever reconsidered your personal iPhone security policy?

Why should I reconsider my iPhone security policy? I have my iPhone four digit pass code and Find my iPhone feature feature is activated. So how should abuse be possible? What could a thief be doing with my stolen iPhone? Well, possibly quite a lot. At least the bold print bullets in this article should be mandatory for everyone. Of course this is no guarantee for invulnerability but it will improve your security. After watching this video you should consider the following actions: Change your Apple ID rescue mail address and do not add this mail account to your iPhone. Consider to use a proper and usable password policy for your Apple ID like this or this (German article) . Consider a complex pass code for your iPhone. As you can see in the video four digit pass codes can be hacked in no time on iPhone 4. For newer iPhone a leak is not yet known but it is properly there. Definitely do not use these pass codes . Alternative to point three: activate delete iPhone after 10 wrong...

Two annoying issues in Visual Studio regarding XSDs and WCF should be fixed immediately

In my daily work I am always stumbling on two annoying features in Visual Studio, and I think it could be improved easily. Here is what I am complaining about. WCF Test Client WCF Test Client might be a nice tiny tool for small WCF tests, especially when you are testing smaller scenarios or when you are starting to learn how to implement web services with .NET. But it can be very annoying when you are working on more advanced stuff and your are testing with your local IIS. WCF Test Client always(!) starts automatically when you press F5 for debugging and your opened .svc.cs file has the focus: When I have configured local IIS is the target for debugging, then I expect my application will start with local IIS and not with WCF Test Client. Always. Here is my first urgent request: Please give me an option to disable WCF Test Client completely! Update 03.03.2014: Workaround for WCF Test Client Issue Select project file -> Right click -> Properties -> Web -> Sele...