/AqaraGateway

Aqara Gateway/Hub integration for Home Assistant

Primary LanguagePython

Aqara Gateway/Hub (G2H, M1S CN, P3 CN, M2 CN, H1 CN, E1 CN, G3 CN, G2H Pro) integration for Home Assistant

Control Zigbee devices from Home Assistant with Aqara Gateway (KTBL12LM, ZHWG15LM, ZHWG12LM, ZNSXJ12LM, ZNSXJ12LM, ZNSXJ13LM, ZNSXJ15LM). Gateway support Zigbee 3.

This integration was based on the development of @AlexxIT, Thanks Alex.

ATTENTION: The component only works on modified firmware (M2) or the gateway which was enabled telnet.

For Gateway M2 and Switch H1 Hub, to flash modified firmware to M2, please use AqaraGateway.exe to flash customize firmware. Need to open the case of gateway and wired out the UART of M2 or H1.

For Gateway M1S CN, AirCondition P3 CN, Hub E1 CN, please switch to Mi Home mode, and get the token.

Installation

you can install component with HACS, custom repo: HACS > Integrations > 3 dots (upper top corner) > Custom repositories > URL: niceboygithub/AqaraGateway > Category: Integration

Or Download and copy custom_components/aqara_gateway folder to custom_components folder in your HomeAssistant config folder

Configuration

  1. ⚙️ Configuration > 🧩 Integrations > ➕ Add Integration > 🔍 Search Aqara Gateway

    Or click (HA v2021.3.0+): add

    1. If the integration didn't show up in the list please REFRESH the page
    2. If the integration is still not in the list, you need to clear the browser cache.
  2. Enter Gateway IP address.

  3. If you applied a password of telnet in gateway, please enter the password. Otherwise, ignore this field.

  4. Enter the xiaomi token of gateway if it is the first time to add integration. Otherwise, ignore this field.

  5. Click Send button, then wait this integration is configured completely.

  6. Done

More detail instructions from @InsaneWookie

Manually Enable Telnet

You can use custom open telnet command way 2 or way 3 to enable telnet in Mija Home mode, then flash modification firmwares to M1S, P3, E1, if you want use them in Aqara Home. No need to open the case of gateway.

After telnet to gateway via putty, there are two methods (Flash or Not) to enable telnet and public mqtt.

Not Flash Custom firmware method (NOT for G2H, E1 hub, G3)

mkdir /data/bin
cd /data/bin
wget -O /data/bin/curl "http://master.dl.sourceforge.net/project/mgl03/bin/curl?viasf=1"; chmod +x /data/bin/curl
/data/bin/curl -s -k -L -o /data/bin/mosquitto https://raw.githubusercontent.com/niceboygithub/AqaraM1SM2fw/main/binutils/mosquitto; chmod a+x /data/bin/mosquitto

mkdir /data/scripts
cd /data/scripts
/data/bin/curl -s -k -L -o /data/scripts/post_init.sh https://raw.githubusercontent.com/niceboygithub/AqaraM1SM2fw/main/binutils/post_init.sh
chmod +x /data/scripts/post_init.sh

Then restart gateway by reboot command.

Not Flash Custom firmware method (for G2H)

mkdir /data/bin
cd /data/bin
wget -O /tmp/curl "http://master.dl.sourceforge.net/project/aqarahub/binutils/curl?viasf=1"; chmod +x /tmp/curl
/tmp/curl -s -k -L -o /data/bin/mosquitto https://raw.githubusercontent.com/niceboygithub/AqaraCameraHubfw/main/binutils/mosquitto; chmod a+x /data/bin/mosquitto

Not Flash Custom firmware method (for G2H)

mkdir /data/bin
cd /data/bin
wget -O /tmp/curl "http://master.dl.sourceforge.net/project/aqarahub/binutils/curl?viasf=1"; chmod +x /tmp/curl
/tmp/curl -s -k -L -o /data/bin/mosquitto https://raw.githubusercontent.com/niceboygithub/AqaraCameraHubfw/main/binutils/mosquitto_g2hpro; chmod a+x /data/bin/mosquitto

Not Flash Custom firmware method (for E1 hub, G3)

mkdir /data/bin
cd /data/bin
wget -O /tmp/curl "http://master.dl.sourceforge.net/project/aqarahub/binutils/curl?viasf=1"; chmod +x /tmp/curl
/tmp/curl -s -k -L -o /data/bin/mosquitto https://raw.githubusercontent.com/niceboygithub/AqaraCameraHubfw/main/binutils/mosquitto_e1; chmod a+x /data/bin/mosquitto

Flash M1S Custom firmware method

cd /tmp && wget -O /tmp/curl "http://master.dl.sourceforge.net/project/mgl03/bin/curl?viasf=1" && chmod a+x /tmp/curl
/tmp/curl -s -k -L -o /tmp/m1s_update.sh https://raw.githubusercontent.com/niceboygithub/AqaraM1SM2fw/main/modified/M1S/m1s_update.sh
chmod a+x /tmp/m1s_update.sh && /tmp/m1s_update.sh

If there is no any error generated, then restart gateway by reboot command.

Flash M2 Custom firmware method

cd /tmp && wget -O /tmp/curl "http://master.dl.sourceforge.net/project/mgl03/bin/curl?viasf=1" && chmod a+x /tmp/curl
/tmp/curl -s -k -L -o /tmp/m2_update.sh https://raw.githubusercontent.com/niceboygithub/AqaraM1SM2fw/main/modified/M2/m2_update.sh
chmod a+x /tmp/m2_update.sh && /tmp/m2_update.sh

If there is no any error generated, then restart gateway by reboot command.

Flash P3 Custom firmware method

cd /tmp && wget -O /tmp/curl "http://master.dl.sourceforge.net/project/mgl03/bin/curl?viasf=1" && chmod a+x /tmp/curl
/tmp/curl -s -k -L -o /tmp/p3_update.sh https://raw.githubusercontent.com/niceboygithub/AqaraM1SM2fw/main/modified/P3/p3_update.sh
chmod a+x /tmp/p3_update.sh && /tmp/p3_update.sh

If there is no any error generated, then restart gateway by reboot command.

Flash H1 Custom firmware method

cd /tmp && wget -O /tmp/curl "http://master.dl.sourceforge.net/project/mgl03/bin/curl?viasf=1" && chmod a+x /tmp/curl
/tmp/curl -s -k -L -o /tmp/h1_update.sh https://raw.githubusercontent.com/niceboygithub/AqaraM1SM2fw/main/modified/H1/h1_update.sh
chmod a+x /tmp/h1_update.sh && /tmp/h1_update.sh

If there is no any error generated, then restart gateway by reboot command.

Not Flash E1 Custom firmware method

Suggest to use another expert's method, pleae move to his github to see hot to do it. He provides a way that avoid any risk on flashing firmwares.

If there is no any error generated, then restart gateway by reboot command.

Note: It updates firmware only if the checksum of the downloaded file is correct.

For G2H

There is a way to enable telnetd.

For G3

There is a way to enable telnetd from #Wh1terat. After enabled telnet, you need use putty to telnet . Then enter the following commands.

chmod a+w /data/scripts/post_init.sh
echo -e "#!/bin/sh\n\nasetprop sys.camera_ptz_moving true\nfw_manager.sh -r\nfw_manager.sh -t -k" > /data/scripts/post_init.sh
chattr +i post_init.sh

How to check this component is working properly.

Go to Configuration->Info->system_health

Aqara Presence Detector FP1

Movements sensor

In the left and right monitoring mode, only report 2, 3, 4, 5, 6, 7;
In the non-directional monitoring mode, only report 0, 1, 6, 7; 0: enter 1: leave 2: left in 3: right out 4 : Right in 5: Left out 6: Approaching 7: Far away

Attention: The component is under active development.

Buy Me A Coffee