Home Assistant Tutorial: Integrate Xiaomi home automation easily!

Today we will add to our server Home Assistant an essential integration, the Xiaomi kit smart home. This kit is certainly the first item obtained by most of us who want to start in the connected home. This small kit comprising many sensors miniature and visually appealing will be even more interesting once it is added to our Home Assistant instance.

As we have seen previously, it will therefore be possible to bring up the sensors in the application Alexa in order to integrate them into our routines. Complexify your routines? No worries, you will have to create the scenario from Home Assistant. One thing is certain, anything is possible!

Choose the integration according to the gateway you have:

Warning. The Xiaomi kit Smart Home with Chinese plug is intended for the Chinese market. The devices are not CE or FCC certified. You are responsible for the use of Xiaomi devices. The LesAlexiens.fr site cannot be held responsible for any accident, injury or damage to equipment. In addition, Chinese servers are not in compliance with the GDPR.
Mijia Europe Gateway (DGNWG05LM) is not currently working on Home Assistant.

Integration of Xiaomi gateways

Compatible gateways:

Local mode ("developer") and recovery of the usage token

To use this integration, we need to activate LAN mode as well as retrieve the key for adding your key to Home Assistant.

From an Android device:

  1. Install the app Xiaomi Home on your Android device (if you haven't already)
  2. Set your region to Mainland China (Settings> Regional settings)
  3. Sign into your account Xiaomi from the app
  4. Select your gateway then click on the 3 dots at the top right of the screen
  5. Click several times on the version number at the bottom of the screen
  6. Two more options are now available (If not, try all the steps again)
  7. Choose the premiere new option then click on the first button to activate local mode
  8. Note the password (This will be essential during the integration)
  9. Make sure to press the OK button to save your changes
  10. Choose the second option appeared and note the IP address that appears after "local IP"
  11. Make this fixed IP in your internet box / router (see "Fixed IP address" part of the DuckDNS tutorial)

Several gateways in your possession? Repeat the above operations for each gateway. 🙂

From an iOS device:

  1. Install the app Xiaomi Home on your iOS device (if you haven't already)
  2. Set your region to Mainland China (Settings> Regional settings)
  3. Sign into your account Xiaomi from the app
  4. Select your gateway then click on the 3 dots at the top right of the screen
  5. Click several times under the About menu in the blank part
  6. Three more options are now available (If not, try all steps again)
  7. Choose the second new option then click on the first button to activate local mode
  8. Note the password (This will be essential during the integration)
  9. Make sure to press the OK button to save your changes
  10. Choose the troisième option appeared and note the IP address that appears after "local IP"
  11. Make this fixed IP in your internet box / router (see "Fixed IP address" part of the DuckDNS tutorial)
Several gateways in your possession? Repeat the above operations for each gateway. 🙂

Adding your gateway in Home Assistant

Before continuing please check that you have successfully completed the following three steps:

  • Enabled local / LAN mode from the Xiaomi Home app
  • Copy the password (key) from your gateway from the Xiaomi Home app
    • Set the IP address from your gateway from your router or internet box

Integration of a single gateway

From the add-on file editor, go to the file configuration.yaml to add the code below:

Home Assistant configuration.yaml xiaomi gateway
Home Assistant configuration.yaml - Xiaomi gateway
xiaomi_aqara: discovery_retry: 5 gateways: - key: your_gateway_password

Integration of multiple gateways

If you have several gateways (not HomeKit compatible), you just have to go to the file configuration.yaml from the add-on file editor to add the code below:

Home Assistant configuration.yaml multiple xiaomi gateway
Home Assistant configuration.yaml multiple xiaomi gateway
xiaomi_aqara: gateways: - mac: gateway_mac_address_1 key: your_password_password_1 - mac: gateway_mac_address_2 key: your_password_password_2

Automation example

Although the automations are simpler from the user interface (configurations> automations) I offer the example in the format YAML in order to copy it easily.

- alias: IF long press THEN sound of dog barking trigger: platform: event event_type: xiaomi_aqara.click event_data: entity_id: binary_sensor.mon_bouton_rond click_type: long_click_press action: service: xiaomi_aqara.play_ringtone_tone_tone_tone_tone_tone_tone_tone_tone_tone_tone_tone_ 8 ringi_tone_tone_tone_tone_ 8 - alias: Stop the sound immediately when pressing a single trigger: platform: event event_type: xiaomi_aqara.click event_data: entity_id: binary_sensor.mon_bouton_rond click_type: single action: service: xiaomi_aqara.stop_ringtone data: gw_mac: address_son_macelle_the_joy

This scenario is not intended to be integrated, it shows several services such as playing a sound from the gateway, using a button associated with it ..

Indeed, this example plays the sound of a dog barking when the button is held down and stops the sound when the button is pressed.

This example only works with the round button of the 1st generation.

Integration of Homekit compatible Xiaomi / Aqara gateways

Compatible gateways:

Updated: August 12, 2022 7:38 a.m.

Adding your gateway in Home Assistant

When installing your Home Assistant server, it certainly detected your hub / gateway via HomeKit. Then just click on "Configure" to automatically add your gateway to Home Assistant.
Your gateway did not appear automatically? No worries, we will proceed with its integration. 🙂

Integration via HomeKit accessory

To integrate it, nothing could be simpler, you just have to go to the tab "Configuration" then select "Integrations" :

configure a home assistant integration
configure a home assistant integration

Then you just have to select « HomeKit accessory« . Home Assistant will start scanning your wifi in order to detect your gateway.

homekit qr code

The famous HomeKit code you will be asked. This is located on the box or directly under the catwalk.

Remember to put the dashes like the example above.

Here is! Your gateway and all of its paired devices are available from your Home Assistant instance. Do not hesitate to restart your server if your Xiaomi devices do not appear.

 

Xiaomi devices available in Home Assistant

One of the advantages of this integration via HomeKit is that it automatically creates the alarm system in order to arm and disarm the security of your home.

 

You can also check from the page "Configuration" in the tab "Devices" the list of your devices including the newly installed Xiaomi.

 

Congratulation! You can now create automations with your Xiaomi and Aqara devices! 🙂
Several feathers of enthusiastsAlexa to concoct articles with 4 or more hands ... Collaborative writing to address the most specialized or transversal subjects, the best home automation and connected home plans on the web, and much more ...