I understand about NOX and Bluestacks but as they run on the PC and my PC doesn’t have Bluetooth I don’t think it will talk to the hub. I’ll give it another go.
You don’t need bluetooth to connect to the hub. The connection is via wifi. I am not sure if we are talking about the same thing.
Hello all!
Does anybody have a pinout for Xiami Gateway v1 (lumi.gateway.v2) to connect via UART? Solution for v2 (lumi.gateway.v3) unfortunately doesn’t work.
Yes, I found the wi-fi signal, connected to it with the pc but still couldn’t get it to play ball.
I’ve given up trying to get the UK version to connect to HA so it’s going back.
I am now considering getting a ConBee II for the RPi.
Hello All,
For those having troubles retrieving device key/token via Mi Home app…This page describes how to extract Mi Home database from phone’s backup and then extract tokens from each registered device. Please keep in mind those 32 character keys are encrypted and need to be decrypted to 16 characters (command in instruction). FYI, the decrypting command in instructions doesn’t have -out (output) switch at the end. Just add at the end -out file name and you will get your key in there. I have tried this on macOS and it worked like a charm.
https://python-miio.readthedocs.io/en/latest/discovery.html#installation
This information was compiled from the websites below. Where I add some points that I run into problems.
Do this after you connect the gateway to your wifi network, with mi home app. Take note of your IP Adress.
connections check the site in point 1.
ATTENTION: Do this at your responsability and risk. This/You could damaged your device, and I will not be responsable for that!
1 - Solder GND, RX and TX.
2 - Attach GND, RX and TX to UART.
3 - Connect the UART to USB
4 - Configure Putty to serial, with baud 115200, 8 bit, 1 stop bit, parity none, flowcontrol none.
5 - Before Plug Gateway to AC, pay attention that you only have 2 seconds to do the next number.
6 - At the moment that you start to see data from the gateway, press enter.
7 - If you had sucess. You’ll see a prompt from HUSH shell of bootloader. If you don’t you will seen an Input Cmd text. If so repeat from point five.
8 - Enter printenv command.
9 - Find bootargs=… and copy all after bootargs= – for me it was “console=…”.
10 - Open notepad.
11 - In notepad enter text: setenv bootargs ’
12 - next paste copied text.
13 - next enter text: single rw init=/bin/bash’ (whitespace before “single”!).
14 - You’ll end up with a single line like: setenv bootargs ‘console=… single rw init=/bin/bash’.
15 - Copy the line to putty and press enter. No message should show up. If anything shows – you copied smth wrong (watch out for quotes and whitespaces).
16 - Now you’re done for single-user root booting.
17 - Before you enter boot command to boot with new bootargs – prepare that you’ll have around 5s to change the root password. I don’t know why, but my prompt freezes after 5s… You must set password that is at least long for 8 chars and contains alpfanumeric signs. Prepare password in notepad and copy it into clipboard – you’ll just paste it twice fast.
18 - In putty write: boot. Press enter.
19 - Now boot process will start, son it start the boot press enter (like in point 6) and you’ll end up in bash# prompt.
20 - Now you have 5s.
21 - Enter passwd, press enter.
22 - Paste twice password from clipboard.
23 - You’ll end up with “root password changed”.
Success!
Now simply turn off AC, then, turn on AC again.
Wait for boot process to end, it ends when the last line is Input cmd:
24 - write: exit_factory. Then press enter
25 - In login prompt enter root and your password from notepad/clipboard.
26 - after login write: cd /etc/dropbear .Then press enter
27 - write: ls. Then enter
28 - If the folder is empty copy and paste the following command, then press enter: dropbearkey -t dss -f /etc/dropbear/dropbear_rsa_host_key dropbearkey -t rsa -f /etc/dropbear/dropbear_dss_host_key
29 - wait for the ssh key to generate
30 - after, write the command followed by enter: cd /etc
31 - then, write the comand followed by enter: vi rc.local
32 - Be carefull now to not change or delete information not needed, search for this line:/home/root/fac/fac_test
33 - then add before that line:
dropbear -p 22 &
34 - check that you have:
dropbear -p 22 &
/home/root/fac/fac_test
35 - Press Esc, then type “:wq”, without quotes, to write file and exit vi
36 - Reboot, then open another session of putty but this type in ssh fill the IP and then try acess the gateway. the user is root and the pass is the one that you put on point 21. After this point you do the commands in ssh session.
37 - Goto https://github.com/roth-m/miioclient-mqtt/tree/master/miio_client and save the file miio_client to folder on you PC, I will call folderX in drive C
38 - Then copy the file to a folder in you gateway. I did this in windows, by:
38.1 - open comand line
38.2 - and the following comand (Change folderX, YOUR_GATEWAY_IP and FOLDER_IN_GATEWAY, by your data):
scp C:\folderX\miio_client root@YOUR_GATEWAY_IP:/FOLDER_IN_GATEWAY/
39 - After copy, return to putty, go to the folder where youput the file
40 - Change the permissions of the file with the following comand, and enter: chmod a+rwx miio_client
41 - finally write the following command: killall miio_client && /folderX/miio_client
42 - Follown the instructions on https://github.com/cadavre/miio_gateway to associate to your HA
43 - If you disconnect the gateway, after connecting you have to repeat the command in point 41.
Note: this was made with the information from:
- https://community.openhab.org/t/solved-openhab2-xiaomi-mi-gateway-does-not-respond/52963/188
- https://github.com/roth-m/miioclient-mqtt/tree/master/miio_client
This can be improved by running then command in line 41, automatically after startup. If you could do this and then shared I will be thankfull. I already take a lot of time to do this, so it’s your turn now
UPDATE:
I get this done with the following lines. With this at every minute if the default miio_client is active the script executes the command in line 41.
--------------You can stop here, however if you watt that the command in line 41, runs automatically on boot, continue to the following lines----
first repeat 31, 32 and 35, and add, before fact_test:
/etc/init.d/crond start &
43 - In folder X, type: vi miio_script.sh
44 - Copy the following content and Paste in putty:
#!/bin/bash
service=miio_client
is_running=`ps aux | grep -v grep| grep miio_client | awk '{print $11}' | wc -l`
if [ is_running != "0" ] ;
then
echo "$is_running Services are running"
for (( c=1; c<=$is_running; c++ ))
do
whois_running=`ps aux | grep -v grep| grep miio_client | awk '{print $11}' | awk 'NR=='$c`
echo "Service $whois_running is running"
if [ $whois_running = "./miio_client" -o $whois_running = "/lumi/app/miio/miio_client" ];
then
echo "Start new miiio_client"
killall miio_client && /avs/miio_client
else
echo "going analyse another.."
fi
done
else
echo "miio_client isn't running"
exit 1
fi
45 - Replace, in the pasted text, “avs”, by the name of you folderX.
46 - Press Esc, then type:":wq", without quotes, and enter
47 - Type: crontab -e, then enter
48 - add (or copy/paste) the following line:
*/1 * * * * /bin/bash -c ". ~/.bashrc; /avs/miio_script.sh"
49 - Replace, in the pasted text, “avs”, by the name of you folderX
50 - Press Esc, then type:":wq", without quotes, and enter
51 - You are done.
This worked for me today with Mi Control Center EU Version:
Before I started I had my hub already setup with all the sensors and other devices in the house already recognised in MiHome on my mobile.
-
Downloaded Mi Home 5.4.49 from apkmirror. I don’t really trust apk from websites but it was the only option and I installed it on an unused tablet with a disposable google account.
-
Reset the hub to put it in parining mode (yellow light flashing)
-
Logged in with my normal user account and the region set to Europe (tried China first but was never able to find my hub)
-
Discovered the hub and added it. All my devices appeared again in the app, even if the hub was reset.
-
Looked in SmartHome\logs on the tablet and found another folder called plug_DeviceManager. Inside it was a txt files which seems to have tokens for all the Xiaomi devices that were paired to the app (Hub, air filter, roborock etc). I only tried the one for the hub and it worked.
Tokens are in jsons like
{“did”:“264435247”,“token”:“xxxxxxxxxxxxxxxxxxxx”,“longitude”:“0.00000000”,“latitude”:“0.00000000”,“name”:“Mi Control Hub”,… }
so you can identify which token belongs to which device.
What hub you have
EU version ?
Aqara or mi hub ?
Mi Control Hub, EU version.
Looks like I was celebrating too early. The integration only added one device called “Xiaomi Gateway” with one entity “Xiaomi Gateway Alarm” . I cannot see any of the sensors connected to it… Still looking to see if it something can be done to also find the key.
Not sure if I understand the problem, but in my setup all my aqara sensors come up with entity ids that are diff than what I have setup in the app. For instance my Front Door shows up as binary_sensor.door_window_sensor_158d000208e248.
Seems like they still have a problem getting the list of sensors from this specific type of gateway (DGNWG05LM). There is an open discussion on github and if you install the dev version of HA the logs show a specific warning about this issue (https://github.com/rytilahti/python-miio/issues/728)
I hope they will manage to do something about it.
Did you maybe have any success with connection to ha?
I have now changed to openwrt (https://github.com/openlumi/openlumi.github.io). I did this because the i bought an aqara swtich and I was unable to access the device. Since I was already using a diferent firmware it was able to do the change quickly. The openwrt, give’s more options, now I can acess to all zigbee devices, because the firmware uses the zigbee chip with a diferent firmware. So now I can acess to the aqara switch. I can use more function with cube and play webradio in the gateway and finally use tts on the gateway to say alarme messages. With openwrt you can use zigbee2mqtt and instead of one device, you have now each sensor has a device.
it’s O.K. to put openwrt on the gateway, but how it can be integrated under HA in order to use its speaker or maybe the light?
The light apears on mqtt, like the button, from there you can change the color, etc and do some automation from the state of the button. The speaker is integrated as a media player in homeassistant. By default the volume is to low, but you can change’t using ssh session and the command “alsamixer” to increase the volume to maximum, after that you can change the volume in HA. My configuration is:
media_player:
- platform: mpd
name: xiaomigw
host: 192.168.X.XXX
Thanks Alberto for the info, I managed to add the gateway as an MQTT broker in HA, but there is no entity appeared. How can I use the light and the zegbee subdevices in that way? sorry for a basic question. I’m new in the HA world…
update: I found the solution: this needs to be installed on the GW, then the GW and its entities appear under MQTT
Did you install the zigbee2mqtt? If you didn’t please do.
Then, one thing about MQTT broker:
My MQTT broker( MQTT - Home Assistant (home-assistant.io)) is in the homeassistant not on the gateway. And for the light, button and Luminance sensor of the gateway the appear automatically under a device called xiaomi_gateway_yyyyyyyy, where yyyyyyyy is the mac adress of the gateway. But, before, you need to configure the autodiscovery of MQTT. In zigbee2mqtt. To do that:
goto Settings, then MQTT Tab,
configure the broker address, username and password.
Then go to the Advanced Tab and configure the Homeassistant discovery topic.
Finally (I think) go to the Main Tab and check the Homeassistant Integration.
To add devices you simply go to the page o zigbee2mqtt and check that the button on the top righ of the page and see if say Disable Join (all) or Permit Join(all), if it says Permit, press to stay Disable, you should see a pop saying that Zigbee allowing no devices to Join. After that pair the device (if you don’t know how to do it, search in google with: device_name Zigbee2mqtt, that usualy helps. After that you should see the zigbee device and it should apear in the Homeassistant MQTT integration.
Last thing please pay attettion to the installation of MQTT in homeassistant, look how to put the mqtt discovery on!
Hope this help, and sorry for taking to mutch time to awnser.
Thank you very much Alberto for sharing your configuration. Something curious happens to me, I have done everything you say, in Zigbee2MQTT I can detect all the peripherals and they appear in Home Assistant, but the Gateway does not appear, and I cannot control the light, the luminance, or the speaker. However in ZESP32, I do get everything to appear, but I cannot control the color or light intensity of the Gateway. Would you know any option to make the Gateway appear in Zigbee2MQTT ?, I have reinstalled everything 5 times with all the configurations. Communication with Home Assistant works perfectly. Thanks a lot
Please check this link for the gateway button, light and luminance: GitHub - openlumi/lumimqtt: Service to control Xiaomi Gateway with MQTT
For the speaker you must configure a media player, but first open an ssh session, and run command alsamixer to put volume on an level that you can listen:
media_player:
- platform: mpd
name: xiaomigw
host: IP_ADRESS_OF_GATEWAY
you can change “xiaomigw” for the name of your preference in the previous code.