i2Echo / mi_iot_token

A xiaomi iot token extractor.
MIT License
3 stars 1 forks source link

Token usage suggestion #5

Closed guyluz11 closed 8 months ago

guyluz11 commented 1 year ago

I would love to be able to control mi IoT devices from dart code so that I will be able to control them using cbj (open source platform to control different smart home vendors).

Did you find a way to control your devices from the dart code? I know about miio package but don't know how to pass the token from here or if it is even the same token that is needed.

Are the token works for LAN or is it for the remote Xiaomi servers (maybe it is the same).

i2Echo commented 1 year ago

Yes, you can control the devices after authentication. It is the same as the API that gets the list of devices, but with different paths:

Note: that different model devices have different props or actions. You can get some of them by referring to the MIOT spec. Here are some references:

Hope that is helpful.

guyluz11 commented 1 year ago

Yes, you can control the devices after authentication. It is the same as the API that gets the list of devices, but with different paths:

* getDevicelist: /home/device_list

* getProps: /miotspec/prop/get

* setProps: /miotspec/prop/set

* action: /miotspec/action

Note: that different model devices have different props or actions. You can get some of them by referring to the MIOT spec. Here are some references:

* [Official miot spec](https://home.miot-spec.com/)

* [Official doc](https://iot.mi.com/new/doc/accesses/direct-access/other-platform-access/control-api#%E5%9F%BA%E7%A1%80%E6%A6%82%E5%BF%B5)

* [A metadata fetcher ](https://www.merdok.org/miotspec/)

* [A homebridge plugin for miot](https://github.com/merdok/homebridge-miot)

Hope that is helpful.

Cool, Can we put those functions as part of the package?

i2Echo commented 1 year ago

Sure, please feel free to make a PR.

i2Echo commented 1 year ago

I have updated it to version 1.0.0, which now supports control of more devices through the Miiot cloud. Additionally, the API has been replaced by MiCloud. Therefore, You must update your code to use this package. v1.0.0

guyluz11 commented 1 year ago

Very cool man, Thanks for the hard work it's being appreciated.

I will probably test it next weekend integrate it into the Smart Home system 😄

i2Echo commented 1 year ago

I have tested the package with my Mi Cloud and it works for my Mi IoT devices. However, if you want to control your devices, you need to find the device specification form at https://home.miot-spec.com/. Furthermore, we can planning to add more device specifications to a device support library for this project.

guyluz11 commented 1 year ago

Does this package support all Xiaomi smart device vendors?

They have: Xiaomi Yeelink Xiaomi Miio Xiaomi ‏Yeelight

guyluz11 commented 1 year ago

I am going throw the code and I think we can improve it a little bit. First of all we need documentation of each field in the device class, I am not sure what is for example did and showMode vars.

Furthermore, we can planning to add more device specifications to a device support library for this project.

I would love to, it can make the process easier, please add one so that I will have the concept of how you would like to implement it. We can differentiate between devices using the model field (I was expecting a number but this is ok too).

i2Echo commented 1 year ago

Does this package support all Xiaomi smart device vendors?

They have: Xiaomi Yeelink Xiaomi Miio Xiaomi ‏Yeelight

I'm not sure(have't test), but it will work properly if the device is compatible with the MIOT protocol and link the micloud.

I don't know the meanings of some of these fields. I debugged these methods by looking at some device parameters and official documentation, as I haven't found a detailed and user-friendly official documentation.

I created a wiki to compile some information I had collected. wiki

i2Echo commented 1 year ago

I would love to, it can make the process easier, please add one so that I will have the concept of how you would like to implement it.

I don't think it's easy because there are many devices with significant differences, and there isn't a detailed instruction manual. I don't know the meaning of many fields.

guyluz11 commented 1 year ago

Does this package support all Xiaomi smart device vendors? They have: Xiaomi Yeelink Xiaomi Miio Xiaomi ‏Yeelight

I'm not sure(have't test), but it will work properly if the device is compatible with the MIOT protocol and link the micloud.

I don't know the meanings of some of these fields. I debugged these methods by looking at some device parameters and official documentation, as I haven't found a detailed and user-friendly official documentation.

I created a wiki to compile some information I had collected. wiki

The wiki is beautiful, and it should also be documented in the code with 3 /

For example:

/// IID (Instance ID): Instance ID is expressed as a /// natural number, and it is incremented from 1 at /// each level in devices and homes. String iid;

guyluz11 commented 1 year ago

By the way I would love to chat with you in discord, we can communicate better. If you want I am on the smart home cbj discord

Discord

guyluz11 commented 1 year ago

Testing getDevices and I am getting weird results.

In the Mi Home app I have only (1) Bulb type: Mi Smart LED Bulb Essential (White and Color) But the result from the method is my Xiaomi router at home without the bulb.

i2Echo commented 1 year ago

I can see the router on the list of results, which appears to be normal. However, as you mentioned there is no bulb, I am unable to determine if there is an issue or not. Could you please provide more details such as the device model( I find the model is [yeelink.light.color5](https://home.miot-spec.com/spec/yeelink.light.color5) , is that? ), a screenshot of the MiHome app, or any additional information that you can share?

guyluz11 commented 1 year ago

I can see the router on the list of results,

But it does not appear in the official app on the same account. I made sure that it is the same account as on the app by account id

Screenshot_20230407_125350_Mi Home 20230407_125541

i2Echo commented 1 year ago

I have no idea. Here is a screenshot of my MiHome app. ed51fa27b5e7331edb41976dccd4077

guyluz11 commented 1 year ago

I'm thinking my bulb is not yeelink.light.color5 Maybe it is not supported 🥲