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

Support get_properties by piid and max_properties count for miot devices #6

Open
lovelylain opened this issue Nov 23, 2020 · 10 comments
Assignees
Labels
enhancement New feature or request miot-protocol

Comments

@lovelylain
Copy link
Contributor

Some new devices only support get_properties by piid, and properties count not greater than 10.

$ miiocli device --ip xxx --token yyy raw_command get_properties "[{'did': 'voltage', 'piid': 3, 'siid': 5}, {'did': 'electric_power', 'piid': 6, 'siid': 5}]"
[{'did': 'voltage', 'piid': 3, 'siid': 5, 'value': 220, 'code': 0}, {'did': 'electric_power', 'piid': 6, 'siid': 5, 'value': 0, 'code': 0}]
@syssi syssi self-assigned this Nov 25, 2020
@syssi syssi added enhancement New feature or request miot-protocol labels Nov 25, 2020
@syssi syssi changed the title Request support get_properties by piid and max_properties count Support get_properties by piid and max_properties count for miot devices Nov 25, 2020
@syssi
Copy link
Owner

syssi commented Nov 29, 2020

Could somebody here @lovelylain @w27 provide some testing? I don't own any miot device for tests.

@ha0y
Copy link

ha0y commented Nov 29, 2020

Could somebody here @lovelylain @w27 provide some testing? I don't own any miot device for tests.

Currently I have a smart plug chuangmi.plug.212a01 which was mentioned in #7 .
This is a new product so it only supports miot protocol.

https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:outlet:0000A002:chuangmi-212a01:1
This is the miot specifications for this device, in which has the relationship between siid,piid and their description.

Now if the configuration like this:

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

then the sensor will be unavaliable , and the error in the log is
Error: {'code': -9999, 'message': 'user ack timeout'}

if the configuration like this:

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

then the sensor is avaliable with wifi RSSI as its value,and

firmware_version: 2.1.0_0017 
hardware_version: esp32 

as its attributes, but nothing more.

And as for switch,

   - platform: template 
     switches: 
       smart_plug_switch: 
         unique_id: smart_plug_switch 
         value_template: "{{ False }}" 
         availability_template: "{{ True }}" 
         turn_on: 
           service: xiaomi_miio_raw.sensor_raw_command 
           data: 
             entity_id: sensor.smart_plug 
             method: set_properties 
             params: 
               - did: SwitchStatus 
                 siid: 2 
                 piid: 1 
                 value: true

doesn't work at all. The switch is always unavaliable. The error message is also Error: {'code': -9999, 'message': 'user ack timeout'}.

For the result of miiocli please refer to #7 .

@ha0y
Copy link

ha0y commented Nov 30, 2020

@syssi

@syssi
Copy link
Owner

syssi commented Nov 30, 2020

I didn't change anything right now. I justed asked for support. ;-) I will provide a feature branch implementing the MiotDevice support soon. There will be a configuration option which needs to be enabled to use the MiotDevice class instead the (Miio)Device class.

@ha0y
Copy link

ha0y commented Dec 1, 2020

@syssi Thanks a lot. I would be glad to provide testing.

@mrtiddy
Copy link

mrtiddy commented Dec 26, 2020

Hi All,

Could somebody give me a hint or paste some example code on how to activate a miot module? I have the miio.curtain_youpin module and I am trying it to connect to home assistant. What do I have to change in the code to be able to activate the miot module? Help would be greatly appreciated!

@ptbsare
Copy link

ptbsare commented Dec 29, 2020

Glad to test miot devices here. I have 114 xiaomi devices including some miot devices such as :
Name: 次卧电蚊香
Model: ateai.mosq.dakuo

#!/usr/bin/python3
from miio import miot_device as miot
ip = '192.168.1.12'
token='XXX'
mos_mapping = {
    "status": {
      "siid": 6,
      "piid": 1
    },
    "workmode": {
      "siid": 6,
      "piid": 2
    },
    "schedules": {
      "siid": 6,
      "piid": 3
    },
    "modeparam": {
      "siid": 6,
      "piid": 4
    },
    "liquid": {
      "siid": 5,
      "piid": 1
    },
    "event_button_pressed_on": {
      "siid": 6,
      "eiid": 1
    },
    "event_button_pressed_off": {
      "siid": 6,
      "eiid": 2
    },
    "event_schedule_on": {
      "siid": 6,
      "eiid": 3
    },
    "event_schedule_off": {
      "siid": 6,
      "eiid": 4
    },
    "action_time_clear": {
      "siid": 5,
      "aiid": 1
    }
  };
d = miot.MiotDevice(ip=ip,token=token,mapping=mos_mapping)
#d.get_properties_for_mapping()
d.set_property("status",1)#turn on
#d.set_property("status",0)#turn off

@ptbsare
Copy link

ptbsare commented Dec 29, 2020

hi, I am wondering when will you implement the MiotDevice support? Great job done! : D

@SpeedFire0
Copy link

It looks like this what I am looking for. Please please add support for siid / piid.
Here is my guide how to communicate to MIOT devices using Terminal in Mac. Maybe it will be useful for someone:
rytilahti/python-miio#901 (comment)

@syssi
Copy link
Owner

syssi commented Jan 17, 2021

I've merged @lovelylain pull request. Great work! Thanks for your support and contribution to this custom component. The sensor entity supports the retrieval of miot properties now. Please give it a try. I've added loveylain's example to the README.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request miot-protocol
Projects
None yet
Development

No branches or pull requests

6 participants