Skip to content

Instantly share code, notes, and snippets.

@InsaneWookie
Last active August 26, 2024 10:37
Show Gist options
  • Save InsaneWookie/1221cd6267745ea3c16f6a2a83ba3a44 to your computer and use it in GitHub Desktop.
Save InsaneWookie/1221cd6267745ea3c16f6a2a83ba3a44 to your computer and use it in GitHub Desktop.
Configure Aqara M1S Gateway for Home Assistant

Connect to Gateway

  1. Download the Xiaomi app https://play.google.com/store/apps/details?id=com.xiaomi.smarthome
  2. Create an account
  3. Add the M1S Gateway in the app (hold button on M1S for 10 seconds to enter discovery mode)

Extract key

  1. Folow the instuctions here: https://github.com/PiotrMachowski/Xiaomi-cloud-tokens-extractor
  2. Copy the output

You should get an output something like the following

Devices found for server "cn":
---------
NAME: Aqara Hub M1S
ID: 12345678
IP: <gateway_ip>
TOKEN: <gateway_token>
MODEL: lumi.gateway.acn01
---------

Install the python-miio library https://github.com/rytilahti/python-miio

  1. Install library pip3 install python-miio
  2. Run the following to verify install miiocli device --ip <gateway_ip> --token <gateway_token> info

Should ouput something like

Model: lumi.gateway.acn01
Hardware version: Linux
Firmware version: 3.1.3_0011

Enable telnet

  1. Run the following command to enable telent (more details here: https://gist.github.com/zvldz/1bd6b21539f84339c218f9427e022709)
  2. miiocli device --ip <gateway_id> --token <gateway_token> raw_command set_ip_info '{"ssid":"\"\"","pswd":"123123 ; passwd -d admin ; echo enable > /sys/class/tty/tty/enable; telnetd"}'

Update M1S to work with Home Assistant

  1. Login to Gateway with telnet <gateway_ip>
  2. Run the following commands from https://github.com/niceboygithub/AqaraGateway
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
  1. Reboot M1S with reboot

Install HACS

  1. Follow install instructions from https://hacs.xyz/docs/installation/prerequisites

Install niceboygithub/AqaraGateway Integration

  1. Navigate to HACS > Integrations
  2. Three dots top right > Custom repositories
  3. Add

This may take a while, and there is a posibility you will run into GitHub rate limits

Add AqaraGateway Integration

  1. Configuration > Integrations
  2. Add Integration button
  3. Seach for Aqara Gateway
  4. Add
    • Host: <gateway_ip>
    • Password:
    • Access Token: <gateway_token>
    • Model: Aqara Gateway M1S
  5. If everything went well you should see home assistant add some new devices
@kai-zer-ru
Copy link

Hi, I tried to soft method by pressing 5 times, pause, 2 times, pause…. But it only activates the arm/ disarm the hub (trying pressing both quick and slow…) So sad

I tried activating telnet this way about 20 times before I wrote the article. you need to press it with short taps. and it is in the MiHome mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment