Use Aqara G2H Zigbee Camera Hub with Home Assistant

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 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
Aqara G2H Zigbee hub sensors exposed in Home Assistant via the AqaraGateway integration.

Getting Access

Turns out 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
All processes running on the camera.

Setup Aqara Gateway

The AqaraGateway project 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 (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) which then talks to the device over telnet to validate the mosquitto binary, to fetch the available Zigbee devices and to establish an MQTT subscription with the broker on the device.
  3. The Aqara Gateway in your Home Assistant maps the MQTT messages to different devices supported by the gateway such as binary sensors and general sensors similar to Zigbee2MQTT.

Initially the gateway integration wasn’t recognizing my camera but this was resolved in one of the recent updates.

Support for new Aqara Zigbee devices requires updates to the AqaraGateway library and it appears that new issues are being opened on GitHub 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 which adds HomeKit support for many of the Tuya Zigbee devices, and can be rooted too.

However, the Zemismart gateway looses the HomeKit support if you replace the Tuya integration with the a ZHA serial gateway 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.

Leave a Reply