# Adding Zigbee devices to HomeKit
One day, all home automation devices will just talk to each other. That day is not today. Until then, how best to get Zigbee devices to show in HomeKit?

There is a lot to like about Zigbee, especially compared to the older generation of HomeKit: The devices don't consume IP addresses, can't talk to the Internet and can have a lower power profile (so battery power is more viable).

But, I don't want a whole bunch of apps and bridges to manage the devices and have to explain to my family. What I want is everything to show up in HomeKit, which the family know how to use. In this post, I'll explain the route I took.

Essentially, there are four components to the solution:
* Hardware to bridge Zigbee protocol to your device
* [Zigbee2MQTT](https://www.zigbee2mqtt.io) to manage the devices, running on something that can run Node.JS
* A [MQTT](https://mqtt.org) broker to publish control messages. Zigbee2MQTT likes [Mosquitto](https://www.mosquitto.org)
* [HomeBridge](https://homebridge.io) to talk to your Apple devices with the [z2m](https://z2m.dev) plugin

The latter three can all be installed on the same device. You want something that is always available. I used a Raspberry PI. Install instructions for each package can be found on their respective sites.

To bridge Zigbee traffic, I used an [SMLight SLZB-06](https://smlight.tech/product/slzb-06/) because it supports Power over Ethernet and is designed in Ukraine. If you use DHCP, remember to reserve an IP address in your router: Zigbee2MQTT needs to know the IP address of the adapter. The device will generate a configuration for you

![SLZB Config](SLZB.png)

Once you've installed Mosquito and Zigbee2MQTT, edit the configuration for the latter and add the serial section. Your configuration.yaml should end up looking something like this:

{{< highlight bash >}}
homeassistant: false
permit_join: true
mqtt:
  base_topic: zigbee2mqtt
  server: mqtt://localhost
  keepalive: 60
  reject_unauthorized: false
  version: 4
  include_device_information: true
serial:
  port: tcp://192.xxx.yyy.zzz:6638
  baudrate: 115200
  disable_led: false
advanced:
  network_key:
  transmit_power: 20
  log_level: debug
  homeassistant_legacy_entity_attributes: false
  legacy_api: false
  legacy_availability_payload: false
frontend: true
{{< / highlight >}}

This is assuming you've installed Mosquitto on the same device, hence the `mqtt://localhost` line.

Once you've started up Zigbee2MQTT, navigage to the Web UI and start [pairing](https://www.zigbee2mqtt.io/guide/usage/pairing_devices.html) devices. A large range of devices are supported out of the box. If your device isn't, it's pretty easy to develop a converter. Any paired devices will show in the main UI:

![Zigbee2MQTT Screen](Zigbee2MQTT.png)

Click on a device to see the controls and data it exposes:

![Individual Device](device.png)

Once all the devices are configured, install Homebridge, click on the plugins tab and search for zigbee2mqtt. Choose the verified plugin "Homebridge Zigbee2MQTT":

![Plugin](plugin.png)

Click setings and configure the topic and server. Assuming you're running Homebridge, Zigbee2MQTT and Mosquitto on the same device, server will be localhost:

![Config for plugin](server.png)

If everything is talking, you'll see your zigbee devices show up on the accessories tab:

![Device in Homebridge](dining1.png)

Finally, add Homebridge to your Apple Home environment to control devices from your Apple devices:


![Device in Apple Home](appleHome.png)

## Tips

* If you have battery Zigbee devices a couple of powered devices will greatly improve network stability as their radios are higher power and the devices will act as routers. I used Philips Hue bulbs.
* Some Zigbee devices support over-the-air updates. Whether OTA is supported by Zigbee2MQTT varies. For instance [Somfy](http://somfysystems.com) don't publish any details on their blind motors so I haven't been able to figure out how to apply OTA updates to them in the [converter](https://github.com/Koenkk/zigbee-herdsman-converters/blob/master/src/devices/somfy.ts) I wrote.
* You can group devices in Zigbee2MQTT but my experience is grouping seems more reliable in the Apple Home app.
