Xiaomi smart socket 2 Bluetooth gateway version access homeassistant


2022.3 Update

Quick access now available with Xiaomi Miot Auto, no complicated configuration is required, see detailshttps://github.com/al-one/hass-xiaomi-miot/blob/master/README_zh.md

Before starting, use the Mijia APP to connect the socket configuration to the Internet

1. Get the device token

The ancestral root method cannot be used. I just found a script on github, which can get the device token very quickly.



downloadtoken_extractor.exe Local Download, run, enter the account password according to the prompts to obtain the device token, copy it for backup

2. Access homeassistant

[Updated on 2021.8.19] Method 1: Use xiaomi-miot (recommended)

1. Download https://github.com/al-one/hass-xiaomi-miot/archive/refs/heads/master.zip, copy the ./custom_components/xiaomi_miot folder to the /config/custom_components directory, and restart homeassistant.

2. Add in homeassistant integration interface Xiaomi Miot Auto, select the local mode, enter the token and IP of the socket, and confirm.

Method 2: Use xiaomi_miio_raw (may fail)

Warehouse Address:https://github.com/syssi/xiaomi_raw

installation method:

Download xiaomi_miio_raw source code Local Download, copy to ./custom_components/, restart homeassistant

Edit configuration.yaml, the configuration is as follows

sensor: - platform: xiaomi_miio_raw name: server_plug # custom name host: # socket IP token: "xxx" # token obtained earlier max_properties: 10 default_properties_getter: get_properties default_properties: - "{'did': 'power' , 'piid': 1, 'siid': 2}" - "{'did': 'temperature', 'piid': 6, 'siid': 2}" - "{'did': 'indicator_light', ' piid': 1, 'siid': 3}" - "{'did': 'on_duration', 'piid': 1, 'siid': 4}" - "{'did': 'off_duration', 'piid' : 2, 'siid': 4}" - "{'did': 'countdown', 'piid': 3, 'siid': 4}" - "{'did': 'task_switch', 'piid': 4 , 'siid': 4}" - "{'did': 'countdown_info', 'piid': 5, 'siid': 4}" - "{'did': 'power_consumption', 'piid': 1, ' siid': 5}" - "{'did': 'electric_current', 'piid': 2, 'siid': 5}" - "{'did': 'voltage', 'piid': 3, 'siid' : 5}" - "{'did': 'electric_power', 'piid': 6, 'siid': 5}"

After restarting, you can find the socket in the developer tools

Among them, parameters such as power need to be further calculated before inserting into the panel(Only the configuration of temperature and power is demonstrated here, other parameters are the same)

sensor: - platform: template sensors: server_plug_power: # custom unique_id: server_plug_power # custom unit_of_measurement: W # unit value_template: "{{ state_attr('sensor.server_plug', 'electric_power') | int / 100 }}" # calculation server_plug_temp: # custom unique_id: server_plug_temp # custom unit_of_measurement: ℃ # unit value_template: "{{ state_attr('sensor.server_plug', 'temperature')}}"

After restarting, you can find the parameters you just added in the panel.

Finally, encapsulate a switch to control the socket switch


Reference link: https://post.smzdm.com/p/az5g23x0/
  1. JohannesYang says:
    Google Chrome Windows 7

Leave a Reply

Your Email address will not be published. The required items are marked with *