niceboygithub / AqaraGateway

Aqara Gateway/Hub integration for Home Assistant
508 stars 66 forks source link

Can't add HUB M1S #29

Closed mifrith closed 2 years ago

mifrith commented 3 years ago

Installed via HACS. I did everything according to the instructions. Without flashing the hub and with it. When I try to add an integration, I enter ip, password and token. The indicator is spinning, then the inscription "Canceled" and nothing happens. The logs are also empty.

niceboygithub commented 3 years ago

Did you change password? If you did not change the password in telnet, please do not input the password.

mifrith commented 3 years ago

Tried without password and with password. The result is the same.

niceboygithub commented 3 years ago
  1. Make sure your M1S is in Mi Home mode.
  2. Get the token
  3. Use way 2 or way 3 in https://gist.github.com/zvldz/1bd6b21539f84339c218f9427e022709
  4. After enable telnet, use putty to login telnet
mifrith commented 3 years ago
  1. M1S is in Mi Home mode
  2. Token received
  3. Hub telnet is on
  4. Putty connection via telnet goes smoothly Doesn't connect, the same message "Aborted"
mifrith commented 3 years ago

Maybe there is a way to log all actions during connection?

In the logs on the hub itself, during an attempt to add an integration, only one message is added: auth.info login [2235]: root login on 'ttyp2'

niceboygithub commented 3 years ago

What is your result in your step 4?

Can you make sure that your HA and M1S are in same domain (like 192.168.1.x)?

mifrith commented 3 years ago

I log in to the hub via putty with the admin and without a password. Yes HA and hub are in the same domain.

niceboygithub commented 3 years ago

Can you input the following command in putty then get the results?

getprop ro.sys.model
mifrith commented 3 years ago

Yes, of course, here's the output: lumi.gateway.aeu01

niceboygithub commented 3 years ago

Not test eu version before. If you can help to test, it will be great!

https://github.com/niceboygithub/AqaraGateway/blob/2261ec8316aec7af4155127cf052d1955a99cf31/custom_components/aqara_gateway/core/utils.py#L31

change the model to aeu01

mifrith commented 3 years ago

It helped, connected the first time.

niceboygithub commented 3 years ago

As README, this plugin is supported M1S CN now. If you can verify on M1S EU, I can add it to support list.

mifrith commented 3 years ago

OK, I can help with these. Tell me what to do?

niceboygithub commented 3 years ago

Use M1S EU in Mi home mode. Add your zigbee devices and see them if work as normal

chaplyk commented 3 years ago

I have uncommented line 35 'lumi.gateway.aeu01': ["Aqara", "Gateway M1S", "HM1S-G01"], and installed integration. HA works OK with my Aqara sensors added in Mi Home.

However, I have a Aqara N100 lock which cannot be added in Mi Home (Zigbee version supports Aqara Home app only). Since there is no custom firmware for EU version in your repo, can you suggest how I can switch from Mi Home mode to Aqara? (soft reset on device disables telnetd)

niceboygithub commented 3 years ago

I have uncommented line 35 'lumi.gateway.aeu01': ["Aqara", "Gateway M1S", "HM1S-G01"], and installed integration. HA works OK with my Aqara sensors added in Mi Home.

However, I have a Aqara N100 lock which cannot be added in Mi Home (Zigbee version supports Aqara Home app only). Since there is no custom firmware for EU version in your repo, can you suggest how I can switch from Mi Home mode to Aqara? (soft reset on device disables telnetd)

I have an idea. but I did not verity it yet. You can have a try While M1S switch to Aqara Home, M1S do not do reboot. So there is a chance to write "post_init.sh". With "post_init.sh", it can enable telnet.

  1. telnet to M1S
  2. run script like the following code
    
    #!/bin/sh

CUSTOM_POST_INIT=/data/scripts/post_init.sh watching_post_init() { if [ ! -x ${CUSTOM_POST_INIT} ]; then mkdir -p /data/scripts/ echo -e '#!/bin/sh\r\n\r\nfw_manager.sh -r\r\necho enable > /sys/class/tty/tty/enable\r\ntelnetd' > ${CUSTOM_POST_INIT} chmod a+x ${CUSTOM_POST_INIT} fi }

main() { while [ 1 ]; do sleep 1; watching_post_init; done }

main


3. switch to Aqara Home mode (press 10 times of button and 2 times of button)
4. verity: telnet to M1S and and check the "post_init.sh" is exist.
chaplyk commented 3 years ago

You are a magician.

I have launched the code above (sent main() to background) and reset the hub to Aqara mode. After reset all data was gone but telnet remained opened (even old session remained online). I have then recreated post_init.sh and installed mosquito using a snippet from README.md.

The only problem is that /data/miio folder is now gone which contained the file with the token. However, somehow integration automatically discovered the hub and added it without token. I have verified that sensors work in HA as expected.

niceboygithub commented 3 years ago

You are a magician.

I have launched the code above (sent main() to background) and reset the hub to Aqara mode. After reset all data was gone but telnet remained opened (even old session remained online). I have then recreated post_init.sh and installed mosquito using a snippet from README.md.

The only problem is that /data/miio folder is now gone which contained the file with the token. However, somehow integration automatically discovered the hub and added it without token. I have verified that sensors work in HA as expected.

miio token is useless in Aqara home mode. You can ignore it in Aqara Home mode.

It is great that this component is helped to you.

shift-del1 commented 3 years ago

I would like to test the solution with M1S EU, but have no experience with Linux. Can any of you please create something similar on the readme page for manual telnet etc. I can copy into telnet and run? My goal would be:

  1. put M1S EU into Mi Home mode
  2. add it to the integration to gain access to telnet
  3. run specific commands to retain telnet (this is where I need your help)
  4. switch to Aqara Home mode
  5. have Aqara Home and Home Assistant access parallel Thank you.
chaplyk commented 3 years ago

@shift-del1 once EU hub is added to your Mi account:

Obtain info about gateway: bash <(curl -L https://github.com/PiotrMachowski/Xiaomi-cloud-tokens-extractor/raw/master/run.sh)

Enable telnet: pip3 install python-miio 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"}' _Replace and with info received from the first command. Nothing else has to be changed._

Telnet to hub using username admin: telnet <gateway_ip>

Create a script with any name (f.e. enable_telnet.sh) and paste the following code (can use vi to create script):

#!/bin/sh

CUSTOM_POST_INIT=/data/scripts/post_init.sh
watching_post_init() {
    if [ ! -x ${CUSTOM_POST_INIT} ]; then
        mkdir -p /data/scripts/
        echo -e '#!/bin/sh\r\n\r\nfw_manager.sh -r\r\necho enable > /sys/class/tty/tty/enable\r\ntelnetd' > ${CUSTOM_POST_INIT}
        chmod a+x ${CUSTOM_POST_INIT}
    fi
}

main() {
    while [ 1 ]; do sleep 1; watching_post_init; done
}

main

Then run the script: sh enable_telnet.sh

With a script running switch hub to Aqara mode (press 10 + 2 times on hub) and add it to Aqara Home app. Telnet connection should remain active. Stop the script with Ctrl+C.

Perform steps from readme to enable integration:

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

reboot
shift-del1 commented 3 years ago

Thank you chaplyk, I really appreciate your detailed description. Currently I'm away from the hub, but once I get home, I will give it a try. Some part was already done (like token retrieval and telnet enabled), but your instructions are vital for the complete success 😊

shift-del1 commented 3 years ago

Hello chaplyk,

Everything went fine until the last step, where I should have enable the integration (so telnet was runing after switched to Aqara home app). I copied the script with the embedded button in the top right corner and pasted in the telnet window, device rebooted and not able to start up anymore. Any idea what could go wrong (I guess the post_init.sh) and how to fix it? No action after holding the button for 10s or pressing it 10 times. Thanks in advance.

binakot commented 2 years ago

The same situation.

I just bought Aqara Hub M1S EU / HM1S-G01 / lumi.gateway.aeu01.

On the first run I switched from Aqara Home app to MiHome app via 10-times button press for reset and 2-times press after reset to switch in MiHome mode. After I connect hub to MiHome patched by Vevs in region China Mainland. And I update firmware to the latest 3.1.5_0020. Everything works like a charm.

Than I collect device token by next commands (values are faked):

$ bash <(curl -L https://github.com/PiotrMachowski/Xiaomi-cloud-tokens-extractor/raw/master/run.sh)

NAME: Aqara Hub M1S
ID: 123456
IP: 192.168.0.123
TOKEN: qwe123
MODEL: lumi.gateway.aeu01

After I enable telnet with commands:

$ sudo pip3 install python-miio 
$ miiocli device --ip 192.168.0.123 --token qwe123 raw_command set_ip_info '{"ssid":"\"\"","pswd":"123123 ; passwd -d admin ; echo enable > /sys/class/tty/tty/enable; telnetd"}'
$ telnet 192.168.0.123 
> login: admin

Aqara-Hub-M1S-9512 login: admin
RLX Linux version 3.0
         _           _  _
        | |         | ||_|                 
   _  _ | | _  _    | | _ ____  _   _  _  _ 
  | |/ || |\ \/ /   | || |  _ \| | | |\ \/ /
  | |_/ | |/    \   | || | | | | |_| |/    \
  |_|   |_|\_/\_/   |_||_|_| |_|\____|\_/\_/

For further information check:
http://processor.realtek.com/

BusyBox v1.22.1 (2021-09-01 19:43:53 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.
#

I tried Flash M1S Custom firmware method but it is not supported for EU hubs:

$ 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
m1s_update.sh revision: 2
type: lumi.gateway.aeu01, model: AH_M1S
This is not supported M1S and exit!

Via telnet I applied Not Flash Custom firmware method:

$ 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

$ reboot

After reboot MiHome works with Aqara Hub M1S and device is still available via telnet.

But I got Aborted message in Home Assistant on every try to integrate Aqara Hub...

image

image

binakot commented 2 years ago

Trying to uncomment row like here: https://github.com/niceboygithub/AqaraGateway/issues/29#issuecomment-889136414

'lumi.gateway.aeu01': ["Aqara", "Gateway M1S", "HM1S-G01"],
binakot commented 2 years ago

And it works ;)

image

kizimenko commented 2 years ago

You are a magician.

I have launched the code above (sent main() to background) and reset the hub to Aqara mode. After reset all data was gone but telnet remained opened (even old session remained online). I have then recreated post_init.sh and installed mosquito using a snippet from README.md.

The only problem is that /data/miio folder is now gone which contained the file with the token. However, somehow integration automatically discovered the hub and added it without token. I have verified that sensors work in HA as expected.

What you have in HA from zigbee n100? can u add some pictures?

kalbfuss commented 2 years ago

Trying to uncomment row like here: #29 (comment)

'lumi.gateway.aeu01': ["Aqara", "Gateway M1S", "HM1S-G01"],

I have the same model (aeu01) and can confirm that connecting to the gateway works after uncommenting the beforementioned line. Will now start to test and report back any issues/successes.

lonsdaleite commented 2 years ago

I can also confirm that lumi.gateway.aeu01 works without any issues after modifying 3 rows in utils.py.

sorryusernameisalreadytaken commented 2 years ago

I have uncommented line 35 'lumi.gateway.aeu01': ["Aqara", "Gateway M1S", "HM1S-G01"], and installed integration. HA works OK with my Aqara sensors added in Mi Home. However, I have a Aqara N100 lock which cannot be added in Mi Home (Zigbee version supports Aqara Home app only). Since there is no custom firmware for EU version in your repo, can you suggest how I can switch from Mi Home mode to Aqara? (soft reset on device disables telnetd)

I have an idea. but I did not verity it yet. You can have a try While M1S switch to Aqara Home, M1S do not do reboot. So there is a chance to write "post_init.sh". With "post_init.sh", it can enable telnet.

  1. telnet to M1S
  2. run script like the following code
#!/bin/sh

CUSTOM_POST_INIT=/data/scripts/post_init.sh
watching_post_init() {
    if [ ! -x ${CUSTOM_POST_INIT} ]; then
        mkdir -p /data/scripts/
        echo -e '#!/bin/sh\r\n\r\nfw_manager.sh -r\r\necho enable > /sys/class/tty/tty/enable\r\ntelnetd' > ${CUSTOM_POST_INIT}
        chmod a+x ${CUSTOM_POST_INIT}
    fi
}

main() {
    while [ 1 ]; do sleep 1; watching_post_init; done
}

main
  1. switch to Aqara Home mode (press 10 times of button and 2 times of button)
  2. verity: telnet to M1S and and check the "post_init.sh" is exist.

I try this now 2 times. What a process :D

what I would like to achieve:

I managed to get telnet to survive the change from xioami-mode to aqara-mode but when I followed the instructions "Not Flash modified firmware method (NOT for G2H, E1 hub, G3)" telnet did not survive the reboot.

At the second attempt, I tried to skip the reboot to have a tethered hack, but the device simply hung up after I following the instructions "Not Flash modified firmware method (NOT for G2H, E1 hub, G3)".

EDIT: I did a third try. In the moment when the init script it freezed. Here is the output:

fw_manager.sh revision: 2
pre-revision: 0
remove /data/lumi_fw
hostname: Aqara-Hub-M1S-3584
type: lumi.gateway.aeu01, model: AH_M1S
Platform: aiot
run aiot.
a:0, r:0
Failed to read serial number
kai-zer-ru commented 6 months ago

https://dzen.ru/a/Zg5nNBHnsk6exK_f

DrHooligun commented 4 months ago

hi guys, need help i have m1s eu lumi.gateway.aeu01 i clear telnet password by gw_global_tool.ttl via usb2ttl adapter and when i try use flash custom firmware method i see error

m1s_update.sh revision: 2 type: lumi.gateway.aeu01, model: AH_M1S This is not supported M1S and exit!

ty for your attention