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.

13 Comments

  1. Christoph says:

    I tried all this but there is no port opened for the cam to access via telnet. Is this article outdated?

    • Kaspars says:

      The telnet service is disabled by default. You must create a file named hostname with the contents from the article in the root directory of an SD card which you then insert into the camera, and restart it to enable the telnet and reset the root password.

  2. Curious says:

    What does this exactly?
    Does it enable camera devices to join the Zigbee2MQTT network? Or just exposes connected zigbee devices in home assistant (if so then how it’s different than default homekit integration in home assistant which already does that?)

    • Kaspars says:

      The custom mosquitto broker binary exposes most of the HomeKit devices to Home Assistant over MQTT without impacting the original Apple Home and Aqara app integrations.

  3. Tim says:

    Hi,

    I’m a bit confused.
    “Initially the gateway integration wasn’t recognizing my camera but this was resolved in one of the recent updates.”

    I was able to add the repository and install the aqara gateway.
    I was also able to add the G2H to this service. However, the only thing I can do is ‘sync’…
    I don’t see any of the camera options itself (motion sensor, camera feed, …)

    Is the purpose of this intergation only to use the G2H as a hub ?

    • Kaspars says:

      Yes, correct — the integration enables access to all the connected Zigbee devices over MQTT while keeping the Aqara app and the HomeKit integration working as before. I agree that not having camera exposed in HomeAssistant is confusing and most users are probably looking for this exact feature.

  4. Hugo says:

    Hello,
    I’ve this ZNSXJ12LM connected to door sensors and wall switches WXKG02LM controlled by Mi Home App.
    I want to install Home Assistant locally to not be dependent from the cloud, but normally the ZigBee hub of the camera don’t works with HA.
    Whit this method can I continue to use Mi Home and connect all my ZigBee devices connected to the cameras in HA ? No need a third ZigBee on the house to connect the ZigBee devices ?

  5. Mar kk says:

    Hi, this all works great! Thanks for the posing.
    One thing I don’t really get — in this configuration, can the g2h cam be an actual Zigbee hub to connect to other devices (e.g. Sonoff) thru the Home Assistant? Much appreciated.

    • Kaspars says:

      The HomeKit integration in the Home app or the Aqara app will show only the devices bound to the camera hub. And the camera hub can bind only to any HomeKit or Aqara devices.

  6. Hugo says:

    Apparently for Aqara G2 (ZNSXJ12LM) chinese version this don’t work.
    I reached to open telnet by UART with no problem, and installed the custom Mosquitto but HA don’t let connect it, I’ve always Unknown Error Occurred.
    It’s strange same model ZNSXJ12LM but from chinese version don’t connect, it it so different from WorldWide version?

Leave a Reply