Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sonicmingit opened this issue Oct 27, 2020 · 57 comments · Fixed by #1581
Closed

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

sonicmingit opened this issue Oct 27, 2020 · 57 comments · Fixed by #1581
Assignees

Comments

@sonicmingit
Copy link

Device information:

@syssi syssi added the miot label Oct 27, 2020
@syssi syssi changed the title Unsupported device : Mi Smart Power Plug 2 (chuangmi.plug.212a01) Add Mi Smart Power Plug 2 (chuangmi.plug.212a01) support Oct 28, 2020
@syssi
Copy link
Collaborator

syssi commented Oct 30, 2020

# 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
Copy link
Collaborator

syssi commented Oct 30, 2020

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"

@rezmus
Copy link

rezmus commented Nov 2, 2020

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

@lovelylain
Copy link

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

@syssi
Copy link
Collaborator

syssi commented Nov 3, 2020

Should be possible, yes.

@syssi
Copy link
Collaborator

syssi commented Nov 4, 2020

{
    # 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},    
},

@ziqiDev
Copy link

ziqiDev commented Nov 23, 2020

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

@syssi syssi self-assigned this Nov 29, 2020
@syssi
Copy link
Collaborator

syssi commented Nov 29, 2020

@ziqiDev The device isn't supported right now.

@loblab
Copy link

loblab commented Dec 17, 2020

any progress now?

@Slejpnir
Copy link

Also waiting for a solution.

@zhangtianchao
Copy link

waiting for the solution

@Jaewook-Jung
Copy link

hope it can be supported soon..!

1 similar comment
@yzb1000
Copy link

yzb1000 commented Dec 28, 2020

hope it can be supported soon..!

@Tam-0130
Copy link

Is there any progress?

@wenlibin02
Copy link

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

@abuxliu
Copy link

abuxliu commented Jan 9, 2021

求解决

@MystiqueWind
Copy link

MystiqueWind commented Jan 12, 2021

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

@ms300
Copy link

ms300 commented Jan 12, 2021

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

@Slejpnir
Copy link

Does it work on the current release?

@MystiqueWind
Copy link

MystiqueWind commented Jan 12, 2021

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
Copy link

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. A guide how to communicate with MIOT devices -> Plugin? #901 Follow this link to find instructions that will help you understand this deeper.

@lovelylain
Copy link

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

@syssi
Copy link
Collaborator

syssi commented Jan 13, 2021

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

@ms300
Copy link

ms300 commented Jan 13, 2021

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

@zj1123581321
Copy link

小米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

@lovelylain
Copy link

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

@DavidBoettger
Copy link

@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
Copy link

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

@lovelylain
Copy link

@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

@al-one
Copy link
Contributor

al-one commented Feb 25, 2021

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

This component is also supported well without yaml.

al-one/hass-xiaomi-miot#12 (comment)

@DavidBoettger
Copy link

@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

@lovelylain
Copy link

image
@DavidBoettger The entity_id must match.

@Takunsyo
Copy link

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.

@juanrferia
Copy link

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

@ssarioglu
Copy link

still does not work on the latest version!

@ha0y
Copy link
Contributor

ha0y commented May 15, 2021

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

@ssarioglu
Copy link

I cant use my devices let me check thanks

@a1ekseev
Copy link

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

@ha0y
Copy link
Contributor

ha0y commented May 16, 2021

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

@a1ekseev
Copy link

@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.

@ha0y
Copy link
Contributor

ha0y commented May 16, 2021

@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.

@syssi
Copy link
Collaborator

syssi commented May 16, 2021

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

@ha0y
Copy link
Contributor

ha0y commented May 16, 2021

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

@chenzhihua1
Copy link

waiting for adding this function into python-miio

@so-steve
Copy link

so-steve commented Jul 9, 2021

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

@liangxrbiu
Copy link

亲爱的@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
Copy link

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?

@RenzoTsai
Copy link

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}]))

@liangxrbiu
Copy link

我正在尝试在 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.