---
title: Use Aqara G2H Zigbee Camera Hub with Home Assistant
date: 2022-04-17T16:38:36+00:00
modified: 2022-04-25T10:23:46+00:00
image:: https://kaspars.net/wp-content/uploads/2022/04/aqara-hub-g2h-home-assistant.png
permalink: https://kaspars.net/blog/aqara-g2h-homekit
post_type: post
author:
  name: Kaspars
  avatar: https://reverse.kaspars.net/gravatar/avatar/92bfcd3a8c3a21a033a6484d32c25a40b113ec6891f674336081513d5c98ef76?s=96&d=mm&r=g
category:
  - Electronics
  - Home Automation
post_tag:
  - Home Assistant
  - HomeKit
  - Zigbee
---

# Use Aqara G2H Zigbee Camera Hub with Home Assistant

[Aqara G2H](https://kaspars.net/go/aqara-g2h) (`ZNSXJ12LM`) is a really nice Zigbee hub and indoor camera with official HomeKit support. Of course it runs Linux so people [have discovered ways to connect it to Home Assistant](https://github.com/niceboygithub/AqaraGateway) which exposes most of your HomeKit devices to Home Assistant over MQTT without impacting the original Apple Home and Aqara app integrations.

![AqaraGateway Integration in Home Assistant with Aqara Hub G2H](https://kaspars.net/wp-content/uploads/2022/04/aqara-hub-g2h-home-assistant.png?strip=all&quality=90&resize=1857,1153)Aqara G2H Zigbee hub sensors exposed in Home Assistant via the AqaraGateway integration.## Getting Access

[Turns out](https://github.com/mcchas/g2h-camera-mods) you can put a file named `hostname` (without any file extension) in the root of the SD card of the device and it will be executed as a bash script during the boot process. The following contents will set the password for the user `root` to `password` and set the `WITH_TELNET` environment variable to `y` which enables the `telnetd` service for remote access:

```
#!/bin/sh
echo "root:password" | chpasswd
export WITH_TELNET="y"
```

After inserting the SD card and restarting the camera you should be able to connect to it using telnet:

```
telnet camera-hub-g2h.local
```

which opens the telnet prompt:

```
Trying 123.123.123.123...
Connected to camera-hub-g2h.local.
Escape character is '^]'.

Camera-Hub-G2H login: root
Password:
```

and you now have full root access to the filesystem!

![Aqara G2H root access processes](https://kaspars.net/wp-content/uploads/2022/04/processes-aqara-hub-g2h-top-root-access.png?strip=all&quality=90&resize=730,548)All processes running on the camera.

## Setup Aqara Gateway

The [AqaraGateway project](https://github.com/niceboygithub/AqaraGateway) is a set of custom binaries and python scripts that enable access to all the connected Zigbee devices over MQTT while keeping the Aqara app and the HomeKit integration working as before.

It does it in the following way:

1. You replace the `mosquitto` MQTT broker binary on the device [with a custom one](https://github.com/niceboygithub/AqaraGateway/tree/72561429919dcb542e9d2e065a07c38b076ee4e8#not-flash-custom-firmware-method-for-g2h) (which appears to be closed source?) which exposes the MQTT service on a public port on your local network and removes the authentication for the MQTT service.
2. You install the Aqara Gateway Home Assistant integration via [HACS (Home Assistant Community Store)](https://hacs.xyz/) which then talks to the device over `telnet` to [validate the `mosquitto` binary](https://github.com/niceboygithub/AqaraGateway/blob/b13c2cf0f3150fc5ec3230206119aeab68fdeff0/custom_components/aqara_gateway/config_flow.py#L61-L63), to [fetch the available Zigbee devices](https://github.com/niceboygithub/AqaraGateway/blob/72561429919dcb542e9d2e065a07c38b076ee4e8/custom_components/aqara_gateway/core/gateway.py#L175-L217) and [to establish an MQTT subscription with the broker on the device](https://github.com/niceboygithub/AqaraGateway/blob/72561429919dcb542e9d2e065a07c38b076ee4e8/custom_components/aqara_gateway/core/gateway.py#L444-L480).
3. The Aqara Gateway in your Home Assistant [maps the MQTT messages](https://github.com/niceboygithub/AqaraGateway/blob/b13c2cf0f3150fc5ec3230206119aeab68fdeff0/custom_components/aqara_gateway/core/gateway.py#L467-L478) to different devices supported by the gateway such as [binary sensors](https://github.com/niceboygithub/AqaraGateway/blob/f6e06be8f1e96a541eb5bfcc7d91d4689f1fb760/custom_components/aqara_gateway/binary_sensor.py) and [general sensors](https://github.com/niceboygithub/AqaraGateway/blob/f6e06be8f1e96a541eb5bfcc7d91d4689f1fb760/custom_components/aqara_gateway/sensor.py) similar to [Zigbee2MQTT](https://www.zigbee2mqtt.io/).

Initially the gateway integration [wasn’t recognizing my camera](https://github.com/niceboygithub/AqaraGateway/issues/93) but this was resolved in [one of the recent updates](https://github.com/niceboygithub/AqaraGateway/commit/8c81decd56b654cb58359d4a84fab31513adef79).

Support for new Aqara Zigbee devices requires updates to the AqaraGateway library and it appears that [new issues are being opened on GitHub](https://github.com/niceboygithub/AqaraGateway/issues) and they are also addressed.

## Conclusions

Aqara hubs that support Aqara Gateway software are the only option on the market with local, no-cloud and open source API which supports HomeKit and Home Assistant integration *at the same time*. Another alternative is the [Zemismart Zigbee Gateway](https://kaspars.net/blog/zemismart-zigbee-homekit-hub) which adds HomeKit support for many of the Tuya Zigbee devices, and [can be rooted too](https://zigbee.blakadder.com/Lidl_TYGWZ-01.html).

> Here is a teardown of the Zemismart Zigbee hub with HomeKit support. It uses TYZS4 Zigbee   
> module from Tuya and it doesn't actually support WiFi. The internals look very similar to SilverCrest Zigbee Gateway <https://t.co/2w8l7lsQGZ> [pic.twitter.com/hCaw40BNKJ](https://t.co/hCaw40BNKJ)
> 
> — Kaspars (@konstruktors) [February 14, 2022](https://twitter.com/konstruktors/status/1493199750442663946?ref_src=twsrc%5Etfw)



However, the Zemismart gateway looses the HomeKit support if you replace the Tuya integration with the [a ZHA serial gateway](https://paulbanks.org/projects/lidl-zigbee/ha/) supported by Home Assistant because it takes over the UART connection with `/dev/ttyS2` which is used by the Tuya `zigbee_agent` to talk to the [NXP JN5189 Zigbee module](https://www.nxp.com/products/wireless/thread/jn5189-88-t-high-performance-and-ultra-low-power-mcus-for-zigbee-and-thread-with-built-in-nfc-option:JN5189_88_T).