python-miio icon indicating copy to clipboard operation
python-miio copied to clipboard

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

Open sonicmingit opened this issue 4 years ago • 57 comments

Device information:

  • Name(s) of the device: Mi Smart Power Plug 2 (Wi-Fi and Bluetooth Gateway)

  • Link: https://www.mi.com/buy/detail?product_id=12777

  • Model: chuangmi.plug.212a01

  • Hardware version: esp32

  • Firmware version: 2.1.0_0017

sonicmingit avatar Oct 27 '20 09:10 sonicmingit

# https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:outlet:0000A002:chuangmi-212a01:1

{
   "type" : "urn:miot-spec-v2:device:outlet:0000A002:chuangmi-212a01:1",
   "services" : [
      {
         "description" : "Device Information",
         "properties" : [
            {
               "iid" : 1,
               "type" : "urn:miot-spec-v2:property:manufacturer:00000001:chuangmi-212a01:1",
               "access" : [
                  "read"
               ],
               "format" : "string",
               "description" : "Device Manufacturer"
            },
            {
               "description" : "Device Model",
               "iid" : 2,
               "type" : "urn:miot-spec-v2:property:model:00000002:chuangmi-212a01:1",
               "access" : [
                  "read"
               ],
               "format" : "string"
            },
            {
               "description" : "Device Serial Number",
               "type" : "urn:miot-spec-v2:property:serial-number:00000003:chuangmi-212a01:1",
               "format" : "string",
               "access" : [
                  "read"
               ],
               "iid" : 3
            },
            {
               "description" : "Current Firmware Version",
               "iid" : 4,
               "access" : [
                  "read"
               ],
               "format" : "string",
               "type" : "urn:miot-spec-v2:property:firmware-revision:00000005:chuangmi-212a01:1"
            }
         ],
         "type" : "urn:miot-spec-v2:service:device-information:00007801:chuangmi-212a01:1",
         "iid" : 1
      },
      {
         "description" : "Switch",
         "iid" : 2,
         "type" : "urn:miot-spec-v2:service:switch:0000780C:chuangmi-212a01:1",
         "properties" : [
            {
               "iid" : 1,
               "type" : "urn:miot-spec-v2:property:on:00000006:chuangmi-212a01:1",
               "format" : "bool",
               "access" : [
                  "read",
                  "write",
                  "notify"
               ],
               "description" : "Switch Status"
            },
            {
               "format" : "uint8",
               "value-range" : [
                  0,
                  255,
                  1
               ],
               "description" : "Temperature",
               "type" : "urn:miot-spec-v2:property:temperature:00000020:chuangmi-212a01:1",
               "access" : [
                  "read",
                  "notify"
               ],
               "iid" : 6,
               "unit" : "celsius"
            },
            {
               "description" : "Working Time",
               "type" : "urn:miot-spec-v2:property:working-time:00000079:chuangmi-212a01:1",
               "access" : [
                  "read",
                  "notify"
               ],
               "unit" : "minutes",
               "iid" : 7,
               "format" : "uint32",
               "value-range" : [
                  0,
                  300,
                  1
               ]
            }
         ]
      },
      {
         "description" : "Indicator Light",
         "iid" : 3,
         "properties" : [
            {
               "iid" : 1,
               "format" : "bool",
               "access" : [
                  "read",
                  "write",
                  "notify"
               ],
               "type" : "urn:miot-spec-v2:property:on:00000006:chuangmi-212a01:1",
               "description" : "Switch Status"
            }
         ],
         "type" : "urn:miot-spec-v2:service:indicator-light:00007803:chuangmi-212a01:1"
      },
      {
         "description" : "Power Consumption",
         "type" : "urn:miot-spec-v2:service:power-consumption:0000780E:chuangmi-212a01:1",
         "properties" : [
            {
               "description" : "Power Consumption",
               "iid" : 1,
               "unit" : "none",
               "access" : [
                  "read",
                  "notify"
               ],
               "type" : "urn:miot-spec-v2:property:power-consumption:0000002F:chuangmi-212a01:1",
               "value-range" : [
                  0,
                  65535000,
                  1
               ],
               "format" : "uint32"
            },
            {
               "type" : "urn:miot-spec-v2:property:electric-current:00000030:chuangmi-212a01:1",
               "access" : [
                  "read",
                  "notify"
               ],
               "format" : "uint16",
               "value-range" : [
                  0,
                  65535,
                  1
               ],
               "iid" : 2,
               "description" : "Electric Current"
            },
            {
               "iid" : 3,
               "value-range" : [
                  0,
                  65535,
                  1
               ],
               "format" : "uint16",
               "access" : [
                  "read",
                  "notify"
               ],
               "type" : "urn:miot-spec-v2:property:voltage:00000031:chuangmi-212a01:1",
               "description" : "Voltage"
            },
            {
               "description" : "Electric Power",
               "access" : [
                  "read",
                  "notify"
               ],
               "type" : "urn:miot-spec-v2:property:electric-power:00000066:chuangmi-212a01:1",
               "unit" : "watt",
               "iid" : 6,
               "format" : "uint32",
               "value-range" : [
                  0,
                  6553500,
                  1
               ]
            }
         ],
         "iid" : 5
      },
      {
         "iid" : 4,
         "type" : "urn:chuangmi-spec:service:imilab-timer:00007801:chuangmi-212a01:1",
         "properties" : [
            {
               "value-range" : [
                  0,
                  86500,
                  1
               ],
               "format" : "uint32",
               "description" : "on-duration",
               "iid" : 1,
               "unit" : "seconds",
               "access" : [
                  "read",
                  "notify",
                  "write"
               ],
               "type" : "urn:chuangmi-spec:property:on-duration:00000001:chuangmi-212a01:1"
            },
            {
               "value-range" : [
                  0,
                  86500,
                  1
               ],
               "format" : "uint32",
               "description" : "off-duration",
               "unit" : "seconds",
               "iid" : 2,
               "access" : [
                  "read",
                  "notify",
                  "write"
               ],
               "type" : "urn:chuangmi-spec:property:off-duration:00000002:chuangmi-212a01:1"
            },
            {
               "format" : "uint32",
               "value-range" : [
                  0,
                  86500,
                  1
               ],
               "description" : "countdown",
               "type" : "urn:chuangmi-spec:property:countdown:00000003:chuangmi-212a01:1",
               "access" : [
                  "read",
                  "notify",
                  "write"
               ],
               "unit" : "seconds",
               "iid" : 3
            },
            {
               "description" : "task-switch",
               "iid" : 4,
               "unit" : "none",
               "type" : "urn:chuangmi-spec:property:task-switch:00000004:chuangmi-212a01:1",
               "access" : [
                  "read",
                  "notify",
                  "write"
               ],
               "format" : "bool"
            },
            {
               "format" : "bool",
               "unit" : "none",
               "iid" : 5,
               "type" : "urn:chuangmi-spec:property:countdown-info:00000005:chuangmi-212a01:1",
               "access" : [
                  "read",
                  "notify"
               ],
               "description" : "countdown-info"
            },
            {
               "description" : "switch-toggle",
               "type" : "urn:chuangmi-spec:property:switch-toggle:00000006:chuangmi-212a01:1",
               "access" : [
                  "write"
               ],
               "iid" : 6,
               "unit" : "none",
               "format" : "bool"
            }
         ],
         "description" : "imilab-timer"
      },
      {
         "events" : [
            {
               "description" : "event",
               "arguments" : [
                  1
               ],
               "type" : "urn:chuangmi-spec:event:event:00005001:chuangmi-212a01:1",
               "iid" : 1
            }
         ],
         "iid" : 6,
         "properties" : [
            {
               "format" : "bool",
               "description" : "switch-event",
               "iid" : 1,
               "unit" : "none",
               "access" : [
                  "notify"
               ],
               "type" : "urn:chuangmi-spec:property:switch-event:00000001:chuangmi-212a01:1"
            }
         ],
         "type" : "urn:chuangmi-spec:service:relay-event:00007802:chuangmi-212a01:1",
         "description" : "relay-event"
      }
   ],
   "description" : "Outlet"
}

syssi avatar Oct 30 '20 16:10 syssi

It looks like the device doesn't expose the bluetooth gateway via miot.

         "description" : "Device Information",
               "description" : "Device Manufacturer",
               "description" : "Device Model",
               "description" : "Device Serial Number",
               "description" : "Current Firmware Version"
               "description" : "Switch Status",
               "description" : "Temperature",
               "description" : "Working Time",
         "description" : "Switch"
               "description" : "Switch Status",
         "description" : "Indicator Light"
         "description" : "Power Consumption",
               "description" : "Power Consumption",
               "description" : "Electric Current"
               "description" : "Voltage",
               "description" : "Electric Power"
               "description" : "on-duration",
               "description" : "off-duration",
               "description" : "countdown",
               "description" : "task-switch",
               "description" : "countdown-info",
               "description" : "switch-toggle",
         "description" : "imilab-timer",
               "description" : "event"
               "description" : "switch-event",
         "description" : "relay-event"
   "description" : "Outlet"

syssi avatar Oct 30 '20 16:10 syssi

ble gateway is never exposed. it just pass data to cloud from ble sensors in range.

rezmus avatar Nov 02 '20 08:11 rezmus

@syssi Can the socket switch status and power be obtained like the previous version?

lovelylain avatar Nov 03 '20 09:11 lovelylain

Should be possible, yes.

syssi avatar Nov 03 '20 09:11 syssi

{
    # Source https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:outlet:0000A002:chuangmi-212a01:1
    "power": {"siid": 2, "piid": 1},
    "temperature": {"siid": 2, "piid": 6},
    "working_time": {"siid": 2, "piid": 7},
    "led": {"siid": 3, "piid": 1},
    "power_consumption": {"siid": 5, "piid": 1},
    "current": {"siid": 5, "piid": 2},
    "voltage": {"siid": 5, "piid": 3},
    "power": {"siid": 5, "piid": 6},
    "on_duration": {"siid": 4, "piid": 1},
    "off_duration": {"siid": 4, "piid": 2},
    "countdown": {"siid": 4, "piid": 3},
    "task_switch": {"siid": 4, "piid": 4},
    "countdown_info": {"siid": 4, "piid": 5},
    "switch_toggle" {"siid": 4, "piid": 6},    
},

syssi avatar Nov 04 '20 07:11 syssi

Hi, @syssi I tried to support this device. but it come out some error, what I do is add the type of 212a01 to the chuangmi_plug and discovery, it does't work. please help me

ziqiDev avatar Nov 23 '20 14:11 ziqiDev

@ziqiDev The device isn't supported right now.

syssi avatar Nov 29 '20 08:11 syssi

any progress now?

loblab avatar Dec 17 '20 11:12 loblab

Also waiting for a solution.

Slejpnir avatar Dec 17 '20 12:12 Slejpnir

waiting for the solution

zhangtianchao avatar Dec 19 '20 11:12 zhangtianchao

hope it can be supported soon..!

Jaewook-Jung avatar Dec 23 '20 09:12 Jaewook-Jung

hope it can be supported soon..!

yzb1000 avatar Dec 28 '20 23:12 yzb1000

Is there any progress?

Tam-0130 avatar Dec 29 '20 07:12 Tam-0130

This is one of my new year's wishes :-)

wenlibin02 avatar Dec 31 '20 14:12 wenlibin02

求解决

abuxliu avatar Jan 09 '21 16:01 abuxliu

Same!!!! Please help us!

Unsupported device found! Please create an issue at https://github.com/rytilahti/python-miio/issues and provide the following data: chuangmi.plug.212a01

MystiqueWind avatar Jan 12 '21 03:01 MystiqueWind

It can be accessed at this format:

get the state of the switch

{"id":65028,"method":"get_properties","params":[{"did":"xxx","siid": 2, "piid": 1}]}

turn on the switch

{"id":65029,"method":"set_properties","params":[{"did":"xxx","siid": 2, "piid": 1,"value":true}]} 

i tested with chuangmi.plug.212a01 and it works!

verification video attached: https://www.youtube.com/watch?v=-XNrR7BpW5c

ms300 avatar Jan 12 '21 16:01 ms300

Does it work on the current release?

Slejpnir avatar Jan 12 '21 17:01 Slejpnir

Dear @ms300

{"id":65028,"method":"get_properties","params":[{"did":"xxx","siid": 2, "piid": 1}]} {"id":65029,"method":"set_properties","params":[{"did":"xxx","siid": 2, "piid": 1,"value":true}]}

How do I use this to control my plugs (This code is not similar to the ones I have come across in configurations of Home assistant or automations of Domoticz)? Could you provide a quick guide or some tips on what to learn to apply your code and make my sockets work?

MystiqueWind avatar Jan 12 '21 23:01 MystiqueWind

Dear @ms300

{"id":65028,"method":"get_properties","params":[{"did":"xxx","siid": 2, "piid": 1}]} {"id":65029,"method":"set_properties","params":[{"did":"xxx","siid": 2, "piid": 1,"value":true}]}

How do I use this to control my plugs (This code is not similar to the ones I have come across in configurations of Home assistant or automations of Domoticz)? Could you provide a quick guide or some tips on what to learn to apply your code and make my sockets work?

Dear @ms300, you are so cool! Thank you!!!! You saved me time, money and made my morning happy !!!! After a bit of googling, I was able to figure out how to use the codes you sent !!!!

I will leave a small instruction for those who are new to this topic:

  1. Install python-miio on your Raspberry Pi!
  2. To get property value - send command: miiocli -d device --ip YOUR_DEVICE_IP --token YOUR_DEVICE_TOKEN raw_command get_properties "[{'did': 'MYDID', 'siid': 2, 'piid': 1 }]"
  3. To set property value (switch on!) - send command: miiocli -d device --ip YOUR_DEVICE_IP --token YOUR_DEVICE_TOKEN raw_command set_properties "[{'did': 'MYDID', 'siid': 2, 'piid': 1, 'value':True}]" (notice, that True must be written with big T)
  4. https://github.com/rytilahti/python-miio/issues/901 Follow this link to find instructions that will help you understand this deeper.

MystiqueWind avatar Jan 13 '21 01:01 MystiqueWind

sensor:
  - platform: xiaomi_miio_raw
    name: smart_plug
    host: 192.168.x.x
    token: xxxxxxxxxx
    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')/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

lovelylain avatar Jan 13 '21 09:01 lovelylain

Wow! This is working without any change of the custom component?

syssi avatar Jan 13 '21 09:01 syssi

@lovelylain Thanks for the yaml. did is supposed to be the device ID of the plug not the name of the properties.

ms300 avatar Jan 13 '21 12:01 ms300

小米miot知识讲解及设备接入【6日更新支持cover、加速响应】 - 『HomeAssistant』综合讨论区 - 『瀚思彼岸』» 智能家居技术论坛 - Powered by Discuz!: https://bbs.hassbian.com/thread-11749-1-1.html

ha0y/xiaomi_miot_raw: https://github.com/ha0y/xiaomi_miot_raw

zj1123581321 avatar Jan 13 '21 15:01 zj1123581321

小米miot知识讲解及设备接入【6日更新支持cover、加速响应】 - 『HomeAssistant』综合讨论区 - 『瀚思彼岸』» 智能家居技术论坛 - Powered by Discuz!: https://bbs.hassbian.com/thread-11749-1-1.html

ha0y/xiaomi_miot_raw: https://github.com/ha0y/xiaomi_miot_raw

居然真的可以,之前还在瀚思彼岸看到这个帖子,都没注意. 非常感谢.

sonicmingit avatar Jan 13 '21 16:01 sonicmingit

小米miot知识讲解及设备接入【6日更新支持cover、加速响应】 - 『HomeAssistant』综合讨论区 - 『瀚思彼岸』» 智能家居技术论坛 - Powered by Discuz!: https://bbs.hassbian.com/thread-11749-1-1.html

ha0y/xiaomi_miot_raw: https://github.com/ha0y/xiaomi_miot_raw

Thank you very much. It works

switch:
  - platform: xiaomi_miot_raw
    name: smart_ble_plug 
    host: !secret smart_ble_plug_host
    token: !secret smart_ble_plug_token
    mapping:
      switch_status:
        siid: 2
        piid: 1
      temperature:
        siid: 2
        piid: 6
      power:
        siid: 5
        piid: 6
    params:
      switch_status:
        power_on: True
        power_off: False
image

Tam-0130 avatar Jan 14 '21 02:01 Tam-0130

小米miot知识讲解及设备接入【6日更新支持cover、加速响应】 - 『HomeAssistant』综合讨论区 - 『瀚思彼岸』» 智能家居技术论坛 - Powered by Discuz!: https://bbs.hassbian.com/thread-11749-1-1.html

ha0y/xiaomi_miot_raw: https://github.com/ha0y/xiaomi_miot_raw

这个太棒了,感觉可以写一个HomeBridge的大一统插件了

ms300 avatar Jan 14 '21 03:01 ms300

@ms300 @MystiqueWind @lovelylain great, thanks

zhangtianchao avatar Jan 14 '21 06:01 zhangtianchao

@syssi no, must modify code. I just submitted a pull request to your repo. https://github.com/syssi/xiaomi_raw/pull/11/commits @ms300 did must exist, but it will not be checked for this plug, so I use it as the property name. For devices that will check the did, you can set it like this "{'name': 'power', 'did': 'xxxx', 'piid': 1, 'siid': 2}" https://github.com/syssi/xiaomi_raw/pull/11/commits/4b155d094787c93f3cb2e7ae66709f9b4c8bcbd7#diff-b1cb0a6decbd6619adb0a70516e3300a7ba9504d8d904ad77b0e729ef88782a1R189

lovelylain avatar Jan 14 '21 14:01 lovelylain

Thank you very much. It really works. chuangmi.plug.212a01

BopoH1978 avatar Feb 01 '21 18:02 BopoH1978

sensor:
  - platform: xiaomi_miio_raw
    name: smart_plug
    host: 192.168.x.x
    token: xxxxxxxxxx
    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')/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

Hello, I am new to this topic and was very happy to get my chuangmi.plug.212a01 up and running in home assistant using this code. My question is how I can set up multiple Sockets at once in this configuration. Best regards, David

DavidBoettger avatar Feb 06 '21 15:02 DavidBoettger

Hello,

Thanks a lot to make it working. Is there any plan to support it officially in Home Assistant without a custom component?

juanrferia avatar Feb 09 '21 16:02 juanrferia

@DavidBoettger add mutiple xiaomi_miio_raw config under 'sensor' and mutiple switch config under 'switches', do not forget to modify name.

lovelylain avatar Feb 15 '21 22:02 lovelylain

@DavidBoettger add mutiple xiaomi_miio_raw config under 'sensor' and mutiple switch config under 'switches', do not forget to modify name.

Thanks for your answer. I tried it like this, but now I have two switches that both control my paper lamp. The power output is also just the one of the paper lamp. sensor:

  • platform: xiaomi_miio_raw name: Paper Lamp host: 192.168.50.80 token: 141061fd4g3b0547bc8f225cede1477e 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: paper_lamp_power: unique_id: smart_plug_power unit_of_measurement: W value_template: "{{ state_attr('sensor.smart_plug', 'electric_power')/100 }}" availability_template: "{{ not is_state('sensor.smart_plug', 'unavailable') }}" icon_template: "mdi:flash"

  • platform: xiaomi_miio_raw name: Heating Solutions host: 192.168.50.210 token: 71135aab337c8205e934acedf74806d7 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: heating_solutions_power: unique_id: heating_solutions_power unit_of_measurement: W value_template: "{{ state_attr('sensor.smart_plug', 'electric_power')/100 }}" availability_template: "{{ not is_state('sensor.smart_plug', 'unavailable') }}" icon_template: "mdi:flash"

switch:

  • platform: template switches: paper_lamp_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

  • platform: template switches: heating_solutions_switch: unique_id: heating_solutions_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

image

DavidBoettger avatar Feb 24 '21 13:02 DavidBoettger

I think the problem is happening, because both switches plugs are referring to sensor.smart_plug. Any idea how to change that? Am I missing something? Best regards, David

DavidBoettger avatar Feb 24 '21 23:02 DavidBoettger

@DavidBoettger

sensor:
  - platform: xiaomi_miio_raw
    name: Paper Lamp
    host: 192.168.50.80
    token: 141061fd4g3b0547bc8f225cede1477e
    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: xiaomi_miio_raw
    name: Heating Solutions
    host: 192.168.50.210
    token: 71135aab337c8205e934acedf74806d7
    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:
      paper_lamp_power:
        unique_id: paper_lamp_power
        unit_of_measurement: W
        value_template: "{{ state_attr('sensor.paper_lamp', 'electric_power')/100 }}"
        availability_template: "{{ not is_state('sensor.paper_lamp', 'unavailable') }}"
        icon_template: "mdi:flash"
      heating_solutions_power:
        unique_id: heating_solutions_power
        unit_of_measurement: W
        value_template: "{{ state_attr('sensor.heating_solutions', 'electric_power')/100 }}"
        availability_template: "{{ not is_state('sensor.heating_solutions', 'unavailable') }}"
        icon_template: "mdi:flash"

switch:
  - platform: template
    switches:
      paper_lamp_switch:
        unique_id: paper_lamp_switch
        value_template: "{{ state_attr('sensor.paper_lamp', 'power') }}"
        availability_template: "{{ not is_state('sensor.paper_lamp', 'unavailable') }}"
        turn_on:
          service: xiaomi_miio_raw.sensor_raw_command
          data:
            entity_id: sensor.paper_lamp
            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.paper_lamp
            method: set_properties
            params:
              - did: power
                siid: 2
                piid: 1
                value: false
      heating_solutions_switch:
        unique_id: heating_solutions_switch
        value_template: "{{ state_attr('sensor.heating_solutions', 'power') }}"
        availability_template: "{{ not is_state('sensor.heating_solutions', 'unavailable') }}"
        turn_on:
          service: xiaomi_miio_raw.sensor_raw_command
          data:
            entity_id: sensor.heating_solutions
            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.heating_solutions
            method: set_properties
            params:
              - did: power
                siid: 2
                piid: 1
                value: false

lovelylain avatar Feb 25 '21 02:02 lovelylain

https://github.com/al-one/hass-xiaomi-miot

This component is also supported well without yaml.

https://github.com/al-one/hass-xiaomi-miot/issues/12#issuecomment-770413743

al-one avatar Feb 25 '21 05:02 al-one

@DavidBoettger

sensor:
  - platform: xiaomi_miio_raw
    name: Paper Lamp
    host: 192.168.50.80
    token: 141061fd4g3b0547bc8f225cede1477e
    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: xiaomi_miio_raw
    name: Heating Solutions
    host: 192.168.50.210
    token: 71135aab337c8205e934acedf74806d7
    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:
      paper_lamp_power:
        unique_id: paper_lamp_power
        unit_of_measurement: W
        value_template: "{{ state_attr('sensor.paper_lamp', 'electric_power')/100 }}"
        availability_template: "{{ not is_state('sensor.paper_lamp', 'unavailable') }}"
        icon_template: "mdi:flash"
      heating_solutions_power:
        unique_id: heating_solutions_power
        unit_of_measurement: W
        value_template: "{{ state_attr('sensor.heating_solutions', 'electric_power')/100 }}"
        availability_template: "{{ not is_state('sensor.heating_solutions', 'unavailable') }}"
        icon_template: "mdi:flash"

switch:
  - platform: template
    switches:
      paper_lamp_switch:
        unique_id: paper_lamp_switch
        value_template: "{{ state_attr('sensor.paper_lamp', 'power') }}"
        availability_template: "{{ not is_state('sensor.paper_lamp', 'unavailable') }}"
        turn_on:
          service: xiaomi_miio_raw.sensor_raw_command
          data:
            entity_id: sensor.paper_lamp
            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.paper_lamp
            method: set_properties
            params:
              - did: power
                siid: 2
                piid: 1
                value: false
      heating_solutions_switch:
        unique_id: heating_solutions_switch
        value_template: "{{ state_attr('sensor.heating_solutions', 'power') }}"
        availability_template: "{{ not is_state('sensor.heating_solutions', 'unavailable') }}"
        turn_on:
          service: xiaomi_miio_raw.sensor_raw_command
          data:
            entity_id: sensor.heating_solutions
            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.heating_solutions
            method: set_properties
            params:
              - did: power
                siid: 2
                piid: 1
                value: false

Hello, I tried this code, but this time only the heating_solutions switch and sensor works and my paper_lamp is listed as unknown and not available. I hope you can find a solution, David

DavidBoettger avatar Feb 25 '21 09:02 DavidBoettger

image @DavidBoettger The entity_id must match.

lovelylain avatar Feb 25 '21 11:02 lovelylain

Hello, I don't know where to ask, it looks most of the questions are here. So I post my question here.

I need to get the total power consumption report of the device, but when I try to get the value 'power_consumption', it always yield the number 100. even a new device.

here fllows my settings:

sensor:
  - platform: xiaomi_miio_raw
    name: WorkStation
    host: 10.0.0.*
    token: t_o_k_e_n
    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_pusage_1:
        unique_id: smart_plug_pusage_1
        unit_of_measurement: Wh
        value_template: "{{ state_attr('sensor.WorkStation', 'power_consumption') }}"
        availability_template: "{{ not is_state('sensor.WorkStation', 'unavailable') }}"
        icon_template: "mdi:flash"

Any advisement would be appreciated.

Takunsyo avatar Feb 25 '21 12:02 Takunsyo

Hello. What is still pending for closing it? It would be great if the official miio integration in Home Assistant supports this device. Thanks!

juanrferia avatar May 12 '21 21:05 juanrferia

still does not work on the latest version!

ssarioglu avatar May 15 '21 07:05 ssarioglu

This device should have been supported months ago. @ssarioglu @a1ekseev If you use it in Home Assistant, you may try https://github.com/ha0y/xiaomi_miot_raw

ha0y avatar May 15 '21 16:05 ha0y

I cant use my devices let me check thanks

ssarioglu avatar May 15 '21 20:05 ssarioglu

This device should have been supported months ago. @ssarioglu @a1ekseev If you use it in Home Assistant, you may try https://github.com/ha0y/xiaomi_miot_raw

Out of the box, it only works through the cloud. But in this way it gives an error:

[custom_components.xiaomi_miot] Got MiioException while fetching the state for Power Plug Switch: {'code': -32602, 'message': 'need siid'}

Firmware version: 2.1.0_0025

a1ekseev avatar May 16 '21 10:05 a1ekseev

@a1ekseev You used the wrong integration. Use xiaomi_miot_raw, not xiaomi_miot. I am using the former and it works perfectly, without cloud.

ha0y avatar May 16 '21 10:05 ha0y

@a1ekseev You used the wrong integration. Use xiaomi_miot_raw, not xiaomi_miot. I am using the former and it works perfectly, without cloud.

Thanks, I'll give it a try. It's just that @al-one above said that support has been added.

a1ekseev avatar May 16 '21 10:05 a1ekseev

@a1ekseev Yes it used to be supported by that integration, but maybe the support was broken by an update. May the author fix it soon.

ha0y avatar May 16 '21 10:05 ha0y

I'm not aware of any issue (of the xiaomi_raw integration). I would be happy about some input.

syssi avatar May 16 '21 10:05 syssi

There is no issue with xiaomi_raw. It works well on this device. It is just python-miio that haven't supported it yet.

ha0y avatar May 16 '21 10:05 ha0y

waiting for adding this function into python-miio

chenzhihua1 avatar Jun 24 '21 06:06 chenzhihua1

I'm trying to access this plug in the API but without any luck.

from miio import ChuangmiPlug
plug = ChuangmiPlug("192.168.1.xxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxx")
plug.on()

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

Any ideas?

BTW, the raw requests from the console work fine, but I would like to use them in python

so-steve avatar Jul 09 '21 08:07 so-steve

亲爱的@ms300

{"id":65028,"method":"get_properties","params":[{"did":"xxx","siid": 2, "piid": 1}]} {"id":65029, "method":"set_properties","params":[{"did":"xxx","siid": 2, "piid": 1,"value":true}]}

我如何使用它来控制我的插头(此代码与我在家庭助手或 Domoticz 的自动化配置中遇到的代码不同)?你能提供一个快速指南或一些关于学习如何应用你的代码并使我的套接字工作的提示吗?

亲爱的@ms300,你太酷了!谢谢!!!!你为我节省了时间和金钱,让我的早晨快乐!!!!经过一番谷歌搜索,我能够弄清楚如何使用您发送的代码!!!!

我会给那些不熟悉这个话题的人留下一个小说明:

  1. 在你的树莓派上安装 python-miio!
  2. 获取属性值 - 发送命令: miiocli -d device --ip YOUR_DEVICE_IP --token YOUR_DEVICE_TOKEN raw_command get_properties "[{'did': 'MYDID', 'siid': 2, 'piid': 1 }]"
  3. 设置属性值(打开!) - 发送命令:(miiocli -d device --ip YOUR_DEVICE_IP --token YOUR_DEVICE_TOKEN raw_command set_properties "[{'did': 'MYDID', 'siid': 2, 'piid': 1, 'value':True}]"注意,True 必须用大 T 写)
  4. 如何与 MIOT 设备通信的指南 -> 插件? #901按照此链接查找可帮助您更深入理解这一点的说明。

hello,i got some troubles when i run it,the result shows error:code:-9999, user act timeout, i dont know how to solve it

liangxrbiu avatar Sep 29 '21 04:09 liangxrbiu

I'm trying to access this plug in the API but without any luck.

from miio import ChuangmiPlug
plug = ChuangmiPlug("192.168.1.xxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxx")
plug.on()

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

Any ideas?

BTW, the raw requests from the console work fine, but I would like to use them in python

metoo,have you solved this problem?

liangxrbiu avatar Sep 29 '21 04:09 liangxrbiu

I'm trying to access this plug in the API but without any luck.

from miio import ChuangmiPlug
plug = ChuangmiPlug("192.168.1.xxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxx")
plug.on()

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

Any ideas? BTW, the raw requests from the console work fine, but I would like to use them in python

metoo,have you solved this problem?

Maybe you guys can try this code:

from miio.device import Device

plug = Device("DEVICE_IP", "DEVICE_TOKEN")
print(plug.send("set_properties", [{'did': 'MYDID', 'siid': 2, 'piid': 1, 'value':True}]))

RenzoTsai avatar Feb 07 '22 14:02 RenzoTsai

我正在尝试在 API 中访问此插件,但没有任何运气。

from miio import ChuangmiPlug
plug = ChuangmiPlug("192.168.1.xxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxx")
plug.on()

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

有任何想法吗? 顺便说一句,来自控制台的原始请求工作正常,但我想在 python 中使用它们

metoo,你解决了这个问题吗?

也许你们可以试试这个代码:

from miio.device import Device

plug = Device("DEVICE_IP", "DEVICE_TOKEN")
print(plug.send("set_properties", [{'did': 'MYDID', 'siid': 2, 'piid': 1, 'value':True}]))

thank u for ur reply,i'v already solve this

liangxrbiu avatar Feb 08 '22 01:02 liangxrbiu