aholstenson / miio

Control Mi Home devices, such as Mi Robot Vacuums, Mi Air Purifiers, Mi Smart Home Gateway (Aqara) and more
MIT License
1.86k stars 354 forks source link

Alternative way to support devices on Smart Home Gateway #26

Closed aholstenson closed 7 years ago

aholstenson commented 7 years ago

As reported in #19 several libraries using the Local Developer API of the Aqara gateway can break things. This issue is for tracking an alternative way to implement support for devices on the Smart Home Gateway by combining just the broadcasts from the Local Developer API with miIO-methods for listing and controlling the devices.

Current status is that there is a call: device.call('get_device_prop', [ 'lumi.0', 'device_list' ]) that lists the devices, but I'm not sure how to map that into the type of subdevice yet.

Update: Current type mapping: 0 - Gateway 1 - lumi.switch 2 - lumi.motion 3 - lumi.magnet 4 - ??? 5 - ??? 6 - ??? 7 - lumi.ctrl_neutral2 8 - lumi.cube 9 - lumi.ctrl_neutral1 10 - lumi.sensor_ht 11 - lumi.plug

aholstenson commented 7 years ago

To help with figuring out the mapping you can install the latest miio CLI via npm install -g miio and call the above command on your gateway with: miio --control lumi.gateway.v3 --method get_device_prop --params '["lumi.0","device_list"]'.

This should return a flat array with the devices. Each device seems to have 5 entries:

You can compare that output to the output of miio --discover and see if you can find the type ids of your devices.

The types I know of right now:

1 - lumi.switch 8 - lumi.cube 10 - lumi.sensor_ht

fxdpz commented 7 years ago

FYI:

root@rpb1:pi# miio --control lumi.gateway.v3 --method get_device_prop --params '["lumi.0","device_list"]' INFO Attempting to control lumi.gateway.v3

INFO Got result: [ "lumi.158d00015xxxxx", //Model info: lumi.sensor_ht (sensor) 10, 1, 0, 2, "lumi.158d00015xxxxx", //Model info: lumi.motion (motion) 2, 1, 0, 11, "lumi.158d00014xxxxx", //Model info: lumi.ctrl_neutral1 (power-switch) 9, 1, 18, 1, "lumi.158d00015xxxxx", //Model info: lumi.sensor_ht (sensor) 10, 1, 0, 2 ]

aholstenson commented 7 years ago

@fxdpz Thanks!

sangkooki commented 7 years ago

I installed miio 0.12.0 version. But log is

/var/lib/homebridge $ miio --control lumi.gateway.v3 --method get_device_prop --params '["lumi.0","device_list"]' INFO Attempting to control lumi.gateway.v3

WARNING Could not find device

aholstenson commented 7 years ago

@sankooki My mistake, that command works for the 3rd gen gateway, you might have the one called lumi.gateway.v2 instead. Try adjusting the command to: miio --control lumi.gateway.v2 --method get_device_prop --params '["lumi.0","device_list"]'

If that doesn't work you can run miio --discover to find the address of your device and replace the model name in the command with the address of your gateway.

sangkooki commented 7 years ago

I have a gateway.v3(mijia version). but

Device ID: 52231412 Model info: Unknown Address: 10.0.1.11 // gateway v3 ip Token: 71761b2e28df3afaa4da62eefad5a209 via auto-token Support: Unknown

aholstenson commented 7 years ago

@sankooki Alright, I've been depending on hostname lookup to figure out the model of the device but I realize now that it might fail more often than I would've hoped. I've added a new issue in #27 to implement a fix for that.

Does using --control with the IP work for listing your devices?

sangkooki commented 7 years ago

/var/lib/homebridge $ miio --control 10.0.1.11 --method get_device_prop --params '["lumi.0","device_list"]' INFO Attempting to control 10.0.1.11

INFO Got result: [ "lumi.158d0000efec7e", // switch 1, 1, 0, 10, "lumi.158d0000f6fcda", // motion 2, 1, 0, 10, "lumi.158d0000e75d33", //door 3, 1, 0, 10, "lumi.158d0001104c5a", // zigbee plug 11, 1, 22, 1, "lumi.0", 0, 0, 0, 0 ]

aholstenson commented 7 years ago

@sankooki Thanks! Interesting to see that your gateway lists lumi.0 as a device, I would not have expected that.

The last device, the one with id lumi.158d0001104c5a what kind of device is that? It has an id I haven't seen before.

sangkooki commented 7 years ago

that's zigbee plug.

aholstenson commented 7 years ago

@sankooki Thanks for your help! I've updated the type listing to include it.

sangkooki commented 7 years ago

I'm pleasured.

Gromina commented 7 years ago

I wonder why gateway's model and support are shown as Unknown. The device names itself as "lumi-gateway-v3_miio....." (hostname)

Hope my dump will help you somehow:

`[1] % miio --control 192.168.88.70 --method get_device_prop --params '["lumi.0","device_list"]'
INFO Attempting to control 192.168.88.70

INFO Got result: [ "lumi.158d0000e87e4a", 10, 1, 0, 1, "lumi.158d0001032fdf", 2, 1, 0, 10, "lumi.158d0000f8614b", 3, 1, 0, 10, "lumi.158d0001118dbd", 8, 1, 0, 3 ]`

% miio --discover

`Device ID: 45835427 Model info: Unknown Address: 192.168.88.70 Token: xxxxxxxxxxxxxxxx via auto-token Support: Unknown

Device ID: 158d0000e87e4a Model info: lumi.sensor_ht (sensor) Address: Owned by 45835427 Token: Automatic via parent device Support: At least basic

Device ID: 158d0001032fdf Model info: lumi.motion (motion) Address: Owned by 45835427 Token: Automatic via parent device Support: At least basic

Device ID: 158d0000f8614b Model info: lumi.magnet (magnet) Address: Owned by 45835427 Token: Automatic via parent device Support: At least basic

Device ID: 158d0001118dbd Model info: lumi.cube (controller) Address: Owned by 45835427 Token: Automatic via parent device Support: At least basic`

Gromina commented 7 years ago

Oh, is it the same issue with host lookup? Didn't see that other issue

aholstenson commented 7 years ago

@Gromina Looks like the same issue, going to look into that issue in the next few days and see what I can do about it.

imReker commented 6 years ago

52: lumi.motion.aq2 Aqara light and motion sensor 12: lumi.86sw2 Aqara 86 model duplex button switch

More devices on the way, will update tomorrow or later

pentiumd2015 commented 5 years ago

Hi, i need help. How can i set prop value for subdevice of gateway ? get_device_prop_exp - OK, but how send command to subdevice ?

pipisco commented 4 years ago

Hi, i need help. How can i set prop value for subdevice of gateway ? get_device_prop_exp - OK, but how send command to subdevice ?

Where did you find the options for subdevices? Could you show me?

{"result":{"life":98676,"cfg_time":0,"token":"0d570a3591ce4a5a4e460c903af21b20","mac":"04:CF:8C:A0:F2:A7","fw_ver":"1.4.1_170","hw_ver":"MW300","uid":4166460975,"model":"lumi.gateway.v3","mcu_fw_ver":"0143","wifi_fw_ver":"SD878x-14.76.36.p84-702.1.0-WM","ap":{"rssi":-38,"ssid":"omprslow","bssid":"68:FF:7B:6A:24:2D"},"netif":{"localIp":"192.168.0.103","mask":"255.255.255.0","gw":"192.168.0.1","gw_mac":"68:FF:7B:6A:24:2D"},"mmfree":172304,"ot":"otu","otu_stat":[243,190,1710,139,1471,17],"ott_stat":[10, 0, 21, 218]},"id":1030}

My subdevices

{"result":["lumi.158d00033b117e",11,0,0,1,"lumi.158d000325e853",2,1,0,11,"lumi.158d00031e7d4d",3,1,0,10,"lumi.158d00036ccf70",1,1,0,10],"id":1000}

There is no way to get even status parameters.

'{"id":1000,"method":"get_device_prop_exp","params":[["lumi.158d000325e853","status"]]}'

null resault, like to

{"result":[[]],"id":1000}

Thanks a lot!