Integration of ecosystem devices Xiaomi into the platform Home Assistant opens up enormous possibilities for the user to create complex automation scenarios. Smart socket, whether it's a model Mi Smart Plug or a more advanced version with energy monitoring, it becomes not just a switch but a fully-fledged sensor, transmitting real-time electricity consumption data. The installation process may seem complicated for a beginner, but with proper preparation, it takes no more than 15-20 minutes.
The main difficulty is that the standard protocol Mi Home doesn't support direct local integration without cloud services, which violates the privacy and autonomy of a smart home. That's why we'll use proven local connection methods that ensure instant device response and operation even without internet access. You'll need a stable network. WiFi 2.4 GHz and access to your automation server interface.
In this article, we will take a detailed look at the two main connection methods: through official integration Xiaomi Miio and through third-party add-ons such as Xiaomi Gateway 3We'll cover issues such as obtaining access tokens, setting up static IP addresses, and creating effective automation for energy savings. Following instructions and paying attention to detail are key to successfully setting up your infrastructure.
⚠️ Attention: Make sure your outlet and Home Assistant server are on the same subnet (same IP address range), otherwise local discovery of the device will not be possible.
Preparing equipment and network
Before starting software setup, there are a number of physical steps that are often overlooked but critically important. First, smart devices Xiaomi operate exclusively in the frequency range 2.4 GHzIf your router broadcasts both 2.4 GHz and 5 GHz networks under the same name (Smart Connect feature), you may experience initial pairing issues. In this case, we recommend temporarily separating the networks or creating a guest network exclusively for IoT devices.
Secondly, for stable operation of the integration Miio It is highly recommended to assign a static IP address to the outlet in your router settings. This will prevent the device from receiving a new address after a router reboot, causing Home Assistant to lose connection. Reserve the address using the device's MAC address, which can be found on the sticker on the bottom of the outlet or in the Mi Home app.
- 📡 Make sure your smartphone is connected to a 2.4 GHz WiFi network before starting setup.
- 🔌 Plug the socket into the power supply and wait until the indicator flashes (pairing mode).
- 🌐 Reserve a static IP address for the socket's MAC address in the router interface.
- 📱 Install the official app Mi Home and link the device to your account for initial verification.
An important step is to determine the model of your device, as different socket models use different command protocols. For example, models of the series ZNCZ05CM And SP-M5 may require different parameters in the configuration files. The exact model is usually indicated on the bottom of the device or on the box.
⚠️ Attention: Xiaomi router interfaces and firmware versions are regularly updated, changing menu locations. If you can't find the IP reservation setting, consult your router manufacturer's official documentation.
Obtaining a Mi Cloud access token
The most difficult and important stage of integration is obtaining a unique token devices. The token is an encryption key that allows Home Assistant to send commands directly to the outlet, bypassing cloud servers. XiaomiWithout this key, local control is impossible, since the protocol Miio Uses AES encryption for all transmitted data packets.
There are several methods for extracting a token. The simplest and most modern way is to use integration. Xiaomi Cloud Token Extractor, which only requires entering your Mi Cloud account login and password. An alternative, more complex method involves using a traffic sniffer (e.g., mitmproxy) on a computer connected to the same WiFi network as the outlet, but it requires in-depth knowledge of network protocols.
After entering your account information into the extraction tool, you'll receive a list of all devices linked to your region. Find your outlet in the list by name or MAC address and copy the long string of characters—this is the token you're looking for. Save it in a safe place, as it's valid indefinitely until you reset your device or change your Mi account password.
Device Name: Mi Smart PlugToken: 3a4b5c6d7e8f9g0h1i2j3k4l5m6n7o8p
IP Address: 192.168.1.55
Model: zcu.zcu03.zncz05cm
What to do if the token is not suitable?
If the device isn't added after entering the token, check your account region. The token is only valid for the server (China, Europe, Russia, or the US) to which the device is linked. Try changing the region in the integration settings.
Installing and configuring HACS
To expand the functionality of Home Assistant and install specialized integrations, such as Xiaomi Miio (if it is not built into your version) or Xiaomi Gateway 3, a package manager is required HACS (Home Assistant Community Store). This is an unofficial add-on store created by the community that makes installing custom components much easier.
HACS installation is performed via the terminal or File Editor if you have access to the server's file system. The process involves downloading the repository archive and unzipping it into a folder. custom_componentsAfter restarting the server, a new section will appear in the settings where you can search for and install the necessary plugins.
- 📥 Open the Home Assistant terminal and go to the configuration directory.
- 📂 Create a folder
custom_components, if it is absent. - ⬇️ Download the latest version of HACS from the official GitHub repository.
- 🔄 Restart the server via the menu
Settings → System → Restart.
After successful installation of HACS, go to the section Integrations and click the Add New button. In the search bar, enter "Xiaomi Miio" or the name of the specific plugin you plan to use. Follow the setup wizard's instructions, entering the previously obtained token and the IP address of the socket.
☑️ Pre-installation check for HACS
Adding a device via Miio integration
Official integration Xiaomi Miio is the most stable way to connect sockets. It supports most popular models, including Mi Smart Plug (WiFi) and versions with USB ports. After installing the component via HACS or activating the built-in integration, go to the section Settings → Devices and Services → Add Integration.
In the window that appears, select Xiaomi MiioYou will be prompted to enter the device's IP address and token. If the information is entered correctly, Home Assistant will immediately detect the device and begin querying its status. Unlike cloud-based solutions, the status in the interface will be updated virtually without delay, and the on/off command will be executed instantly.
It is important to note that some models may require manual specification of the device type in the configuration. configuration.yaml, if automatic detection does not work. In this case, you need to add an entry with the parameter model, corresponding to the identifier of your socket (for example, zncz05cm).
| Parameter | Meaning | Description |
|---|---|---|
| platform | xiaomi_miio | Integration platform type |
| host | 192.168.1.XX | Static IP address of the socket |
| token | 32 characters | Device access key |
| name | Living Room Plug | Device name in the system |
⚠️ Attention: When changing the configuration via a YAML file, a full restart of Home Assistant is required, not just a restart of the integration, otherwise the changes will not take effect.
Sensor setup and energy monitoring
One of the main reasons to buy a smart plug is the ability to monitor energy consumption. Models that support this feature (usually labeled "Power" or "Energy") transmit data on current power, voltage, current, and stored energy. In Home Assistant, this data is automatically created as separate sensors.
You can see entities like sensor.living_room_plug_power (current power in Watts) and sensor.living_room_plug_energy (consumption in kWh). This data can be used to plot graphs in Loevlace or Energy Dashboardto analyze how much electricity a connected device consumes at different times of the day.
To ensure data displays correctly in the Home Assistant energy dashboard, ensure that your sensors have the correct units of measurement. The integration typically assigns attributes automatically. unit_of_measurement: W for power and unit_of_measurement: kWh for energy. If this is not the case, you can use template sensors (template) to convert values.
Creating automations and scenarios
Once you've successfully added an outlet to the system, a world of limitless automation possibilities opens up. You're no longer limited to a simple schedule. For example, you can create a scenario that turns off the outlet and heater if the window in the room is open (using a window sensor). Xiaomi).
Another popular scenario is simulating presence. Set the outlet with a lamp to turn on and off at random intervals in the evening, creating the illusion that someone is home. You can also use timers: turn off the charger after two hours to conserve battery life.
To create automation, go to the section Settings → Automation and create a new one. You can select time, the state of another device, or a system event as a trigger. The action will be a service call. switch.turn_on or switch.turn_off for your outlet.
- ⏰ Start the coffee maker 15 minutes before your alarm.
- 💡 Turn on the light in the hallway when the motion sensor is triggered at night.
- 🔌 Turn off unused equipment (TV, monitor) when switching to "Nobody Home" mode.
- 📉 Track peak consumption and turn off powerful devices when the limit is exceeded.
Troubleshooting and FAQ
During operation, various technical difficulties may arise related to updating router firmware or changing security policies. XiaomiUsers often experience connection loss with their device or authorization errors. Most issues can be resolved by checking that the IP address is static and the token is current.
If the outlet stops responding to commands, try rebooting the outlet itself (unplug it for 10 seconds). In rare cases, re-pairing the device in the Mi Home app and obtaining a new token may help, as the old one may have been deactivated by the server when the account password was changed.
Why doesn't Home Assistant see the outlet after rebooting the router?
Most likely, the outlet has received a new IP address, but the integration still uses the old one. Go to the router settings and assign the IP address to the outlet's MAC address (Static Lease / DHCP Reservation). Then, reconfigure the Home Assistant integration with the new address.
Is it possible to control a socket without the Internet?
Yes, when using local Miio integration, control occurs directly over the local network. Internet access is only required for initial setup and token acquisition. Once configured, the outlet will work even if the external network connection is disconnected.
How to reset a Xiaomi outlet to factory settings?
Press and hold the button on the outlet body (if equipped) or use a paperclip to press the hidden reset button for 5-7 seconds until the indicator light starts flashing rapidly. After this, the device will need to be configured again.
Does the integration support multiple sockets?
Yes, you can add an unlimited number of devices. Each device will have its own unique entity (switch, sensor). We recommend giving them descriptive names when adding them to avoid confusion in the device list.
What does the "Unable to discover device" error mean?
This error indicates a network issue. Check that the Home Assistant server and the outlet are on the same subnet (VLAN). Also, make sure your firewall isn't blocking UDP port 54321, which is used by the Miio protocol for discovery.