rytilahti / python-miio

Python library & console tool for controlling Xiaomi smart appliances
https://python-miio.readthedocs.io
GNU General Public License v3.0
3.8k stars 565 forks source link

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

Closed sonicmingit closed 1 year ago

sonicmingit commented 4 years ago

Device information:

syssi commented 4 years ago
# 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 commented 4 years ago

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 commented 4 years ago

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

lovelylain commented 4 years ago

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

syssi commented 4 years ago

Should be possible, yes.

syssi commented 4 years ago
{
    # 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 commented 4 years ago

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 commented 3 years ago

@ziqiDev The device isn't supported right now.

loblab commented 3 years ago

any progress now?

Slejpnir commented 3 years ago

Also waiting for a solution.

zhangtianchao commented 3 years ago

waiting for the solution

Jaewook-Jung commented 3 years ago

hope it can be supported soon..!

yzb1000 commented 3 years ago

hope it can be supported soon..!

Tam-0130 commented 3 years ago

Is there any progress?

wenlibin02 commented 3 years ago

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

abuxliu commented 3 years ago

求解决

MystiqueWind commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Does it work on the current release?

MystiqueWind commented 3 years ago

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 commented 3 years ago

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.
lovelylain commented 3 years ago
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 commented 3 years ago

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

ms300 commented 3 years ago

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

zj1123581321 commented 3 years ago

小米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 commented 3 years ago

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

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

Tam-0130 commented 3 years ago

小米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
ms300 commented 3 years ago

小米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的大一统插件了

zhangtianchao commented 3 years ago

@ms300 @MystiqueWind @lovelylain great, thanks

lovelylain commented 3 years ago

@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

BopoH1978 commented 3 years ago

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

DavidBoettger commented 3 years ago
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

juanrferia commented 3 years ago

Hello,

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

lovelylain commented 3 years ago

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

DavidBoettger commented 3 years ago

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

switch:

image

DavidBoettger commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

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

DavidBoettger commented 3 years ago

@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 commented 3 years ago

image @DavidBoettger The entity_id must match.

Takunsyo commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

still does not work on the latest version!

ha0y commented 3 years ago

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 commented 3 years ago

I cant use my devices let me check thanks

a1ekseev commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

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