python-miio
python-miio copied to clipboard
Add Mi Smart Power Plug 2 (chuangmi.plug.212a01) support
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
# 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"
}
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"
ble gateway is never exposed. it just pass data to cloud from ble sensors in range.
@syssi Can the socket switch status and power be obtained like the previous version?
Should be possible, yes.
{
# 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},
},
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 The device isn't supported right now.
any progress now?
Also waiting for a solution.
waiting for the solution
hope it can be supported soon..!
hope it can be supported soon..!
Is there any progress?
This is one of my new year's wishes :-)
求解决
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
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
Does it work on the current release?
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
{"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:
- Install python-miio on your Raspberry Pi!
- 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 }]"
- 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) - https://github.com/rytilahti/python-miio/issues/901 Follow this link to find instructions that will help you understand this deeper.
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
Wow! This is working without any change of the custom component?
@lovelylain Thanks for the yaml. did is supposed to be the device ID of the plug not the name of the properties.
小米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
小米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
居然真的可以,之前还在瀚思彼岸看到这个帖子,都没注意. 非常感谢.
小米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

小米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 @MystiqueWind @lovelylain great, thanks
@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
Thank you very much. It really works. chuangmi.plug.212a01
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
Hello,
Thanks a lot to make it working. Is there any plan to support it officially in Home Assistant without a custom component?
@DavidBoettger add mutiple xiaomi_miio_raw config under 'sensor' and mutiple switch config under 'switches', do not forget to modify name.
@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
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
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
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
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 The entity_id must match.
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.
Hello. What is still pending for closing it? It would be great if the official miio integration in Home Assistant supports this device. Thanks!
still does not work on the latest version!
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
I cant use my devices let me check thanks
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 You used the wrong integration. Use xiaomi_miot_raw, not xiaomi_miot. I am using the former and it works perfectly, without cloud.
@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 Yes it used to be supported by that integration, but maybe the support was broken by an update. May the author fix it soon.
I'm not aware of any issue (of the xiaomi_raw
integration). I would be happy about some input.
There is no issue with xiaomi_raw
. It works well on this device. It is just python-miio
that haven't supported it yet.
waiting for adding this function into python-miio
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
亲爱的@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,你太酷了!谢谢!!!!你为我节省了时间和金钱,让我的早晨快乐!!!!经过一番谷歌搜索,我能够弄清楚如何使用您发送的代码!!!!
我会给那些不熟悉这个话题的人留下一个小说明:
- 在你的树莓派上安装 python-miio!
- 获取属性值 - 发送命令:
miiocli -d device --ip YOUR_DEVICE_IP --token YOUR_DEVICE_TOKEN raw_command get_properties "[{'did': 'MYDID', 'siid': 2, 'piid': 1 }]"
- 设置属性值(打开!) - 发送命令:(
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 写)- 如何与 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
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?
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}]))
我正在尝试在 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