python-miio icon indicating copy to clipboard operation
python-miio copied to clipboard

Code request for device control

Open mp075496706 opened this issue 2 years ago • 2 comments

I tried to control the switch of Xiaomi smart socket in Python code by calling commands. Here is my code:

from miio.device import Device  
plug=Device ('192.168. xxx. xxx ',' xxxxxxxxxxxx6b667639745c20 ')  
plug. send ("set_properties", [{'did ':' 123 ',' siid ': 2,' piid ': 1,' value ': True}])

After experiments, it is no problem and can control the opening and closing of the socket. But I want to control the timing switch of the socket. I checked someone else's issue and found that someone mentioned:

-{'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 ':' electrically current ',' piid ': 2,' siid ': 5}
-{'did ':' voltage ',' piid ': 3,' siid ': 5}
-{'did ':' electic_power ',' piid ': 6,' siid ': 5}

I am trying to modify the code above me to match these values, and here is my code:

from miio.device import Device
plug=Device ('192.168. xxx. xxx ',' xxxxxxxxxxxx6b667639745c20 ')
plug. send ("set_properties", [{'did ':' 123 ',' siid ': 4,' piid ': 3,' value ': False}])

But it seems that the code doesn't have much effect. Does anyone know how to write it? Thank you.

mp075496706 avatar Nov 22 '23 01:11 mp075496706

Which model is this? The siid&piid values are model dependent, so the first step would be find out the mapping for your specific model.

You can use miiocli device --ip <ip> --token <token> info to obtain that information. Most of the newer devices are supported by using the genericmiot integration (available only on git master branch for now), you could try miiocli genericmiot --ip <ip> --token <token> status to see if that's the case for your device.

If you really need the raw siid & piid, you can pass --debug flag to the command to see the raw requests and responses. However, it is recommended to use DeviceFactory to construct device instances, and access the wanted functionality using the interfaces documented in the README: https://github.com/rytilahti/python-miio/?tab=readme-ov-file#api-usage

Hope that helps!

rytilahti avatar Nov 22 '23 17:11 rytilahti

Which model is this? The siid&piid values are model dependent, so the first step would be find out the mapping for your specific model.

You can use miiocli device --ip <ip> --token <token> info to obtain that information. Most of the newer devices are supported by using the genericmiot integration (available only on git master branch for now), you could try miiocli genericmiot --ip <ip> --token <token> status to see if that's the case for your device.

If you really need the raw siid & piid, you can pass --debug flag to the command to see the raw requests and responses. However, it is recommended to use DeviceFactory to construct device instances, and access the wanted functionality using the interfaces documented in the README: https://github.com/rytilahti/python-miio/?tab=readme-ov-file#api-usage

Hope that helps!

The Model:chuangmi.plug.212a01

mp075496706 avatar Nov 24 '23 02:11 mp075496706