2024年11月24日星期日 下午5:05:09

3.小米智能插座2蓝牙网关版(chuangmi.plug.212a01) 接入homeassistant -by syssi' xiaomi_miio_raw

2 年 前
#10282 引用
小米智能插座2蓝牙网关版chuangmi.plug.212a01 接入homeassistant -by xiaomi_miio_raw

Add Mi Smart Power Plug 2 (chuangmi.plug.212a01) support

https://github.com/rytilahti/python-miio/issues/844#issuecomment-759334409


https://post.smzdm.com/p/az5g23x0/



xiaomi_miio_raw  - 用此插件接入

https://github.com/syssi/xiaomi_raw

Currently I have a smart plug chuangmi.plug.212a01 ..
This is a new product so it only supports miot protocol.

智能插座2采用了一套新的协议。

之前的协议叫miio,新的协议叫miot,两者内部实现变化较大,但在局域网控制这块保持了一定的兼容性,其实对插件做出少量修改就能支持miot协议。

本文介绍如何将米家miot设备接入HA。
https://post.m.smzdm.com/p/az5g23x0/


./custom_components/xiaomi_miio_raw/manifest.json

{
  "domain": "xiaomi_miio_raw",
  "name": "Custom component for Home Assistant to faciliate the reverse engeneering of Xiaomi MiIO devices",
  "version": "2022.12.0.0",
  "iot_class": "local_polling",
  "config_flow": false,
  "documentation": "https://github.com/syssi/xiaomi_raw",
  "issue_tracker": "https://github.com/syssi/xiaomi_raw/issues",
  "requirements": [
    "construct==2.10.56",
    "python-miio>=0.5.12"
  ],
  "dependencies": [],
  "codeowners": [
    "@syssi"
  ]
}

0
2 年 前
#16417 引用
在miio中,可以通过get_prop "['on', 'bright', 'ct']"方法获取开关、亮度、色温等属性,通过set_power、set_bright、set_ct等方法设置开关、亮度、色温属性,属性名和方法名杂乱无章,没有一个统一的地方查询。而miot改用了一套更科学的方法管理设备的属性,通过get_properties获取属性、set_properties方法设置属性。下面以智能插座2为例介绍miot设备接入HA的方法,该方法同样适用于其他米家miot设备。
0
2 年 前
#16418 引用
在configuration.yaml中定义一个支持获取属性和调用服务的sensor。

https://github.com/syssi/xiaomi_raw/issues/6

Now if the configuration like this:(Error)

sensor: 
   - platform: xiaomi_miio_raw
     name: smart_plug
     host: 192.168.0.201
     token: bb441c71ddfXXXXXX038a8f02806e8cc


then the sensor will be unavaliable , and the error in the log is

Error: {'code': -9999, 'message': 'user ack timeout'}


if the configuration like this:

sensor: 
   - platform: xiaomi_miio_raw
     name: smart_plug
     host: 192.168.0.201
     token: bb441c71ddfXXXXXX038a8f02806e8cc
     default_properties: []
     default_properties_getter: get_properties


get_properties by piid and max_properties count for miot devices




0
2 年 前
#16419 引用
https://github.com/syssi/xiaomi_raw


然后用template将功率包装成可直观查看的sensor,并包装出一个可控制电源通断的switch。
0
1 年 前
#20158 引用
https://github.com/syssi/xiaomi_raw/blob/develop/README.md


sensor:
  - platform: xiaomi_miio_raw
    name: Smart Plug
    host: 192.168.30.74
    token: d880f00295a6db218b29a1879eea4663
    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}"
  - platform: template
    sensors:
      smart_plug_power:
        unique_id: smart_plug_power
        unit_of_measurement: W
        value_template: "{{ state_attr('sensor.smart_plug', 'electric_power')|int / 100 }}"
        availability_template: "{{ not is_state('sensor.smart_plug', 'unavailable') }}"
        icon_template: "mdi:flash"

switch:
  - platform: template
    switches:
      smart_plug_switch:
        unique_id: smart_plug_switch
        value_template: "{{ state_attr('sensor.smart_plug', 'power') }}"
        availability_template: "{{ not is_state('sensor.smart_plug', 'unavailable') }}"
        turn_on:
          service: xiaomi_miio_raw.sensor_raw_command
          data:
            entity_id: sensor.smart_plug
            method: set_properties
            params:
              - did: power
                siid: 2
                piid: 1
                value: true
        turn_off:
          service: xiaomi_miio_raw.sensor_raw_command
          data:
            entity_id: sensor.smart_plug
            method: set_properties
            params:
              - did: power
                siid: 2
                piid: 1
                value: false


0
1 年 前
#20238 引用
If your plug has been set up correctly, you should have the xiaomi_miio_raw: sensor_raw_command service available under developer tools -> services.

If it’s there, then you can play the chime with the following script:



http://192.168.2.50:38123/developer-tools/state

search server_plug

output

model: chuangmi.plug.212a01
firmware_version: 2.1.8_0041
hardware_version: esp32
properties:
  - power
  - temperature
  - indicator_light
  - on_duration
  - off_duration
  - countdown
  - task_switch
  - countdown_info
  - power_consumption
  - electric_current
  - voltage
  - electric_power
sensor_property: null
power: true
temperature: 25
indicator_light: false
on_duration: 0
off_duration: 0
countdown: 0
task_switch: false
countdown_info: false
power_consumption: 100
electric_current: 5
voltage: 220
electric_power: 20138
icon: mdi:flask-outline
friendly_name: server_plug
0