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 for Yeelight Candela Light (BLE, Bluetooth Low Energy) #202

Open
kikiwora opened this issue Feb 5, 2022 · 56 comments
Open

Support for Yeelight Candela Light (BLE, Bluetooth Low Energy) #202

kikiwora opened this issue Feb 5, 2022 · 56 comments

Comments

@kikiwora
Copy link

kikiwora commented Feb 5, 2022

Good evening!

As for now, I have only one device that is not connected to HomeKit via this or any other plugin, and that is Yeelight Candela.

This lamp can be controlled via Bluetooth using the Yeelight app, and I know that Homebridge supports Bluetooth devices, since I did successfully connect Hygrothermograph via BLE using Homebridge Mi Hygrothermograph plugin.

But for this lamp, no supported plugin has been found for Homebridge, however, the plugin for Homey Pro exists.

I wonder if someone possibly could implement support for this device in the scope of Homebridge MIOT plugin.
It would be awesome. I'm sure that there're lots of people who bought this lamp and would like to use it via HomeKit

@merdok
Copy link
Owner

merdok commented Feb 5, 2022

I know that some bluetooth devices also support the miot protocol, so in theory it should be possible. On the other hand i have absolutely no experience with bluetooth so it would require a lot of investigation for me, and i would also need a miot capable bluetooth device. The point is, i am not sure if investing time in that makes sense, since most of the bluetooth devices are battery based where frequent polling would just kill the battery so special handling would be needed...

@Vannixxo
Copy link

Vannixxo commented Feb 6, 2022

It would be amazing! I’m waiting for yeelight candela control since 2018

@kikiwora
Copy link
Author

kikiwora commented Feb 6, 2022

@merdok I understand your concern, in any case, it's up to you to decide.

But I must say that these devices can be connected to Xiaomi Bluetooth Gateway, for obvious reasons, to poll climate data, so the battery life should not be an issue. I may be wrong here, but isn't the BLE protocol made specifically to save power and thus replaces polling with the broadcast?

Candela light, for example, in my case is always connected via USB, since I use it as a daily night lamp or ambiance lamp when watching movies, and compared to the BLE energy consumption, the LED consumption is significantly higher, so even with frequent polling, the difference should be negligible.

And you always may place a warning, so users will know that connecting such devices will reduce their longevity a bit, so that will be a choice to make.

@merdok
Copy link
Owner

merdok commented Feb 6, 2022

Let see, maybe at some point i will have a look it...

@Vannixxo
Copy link

Vannixxo commented Feb 6, 2022

Thanks so much!

@Jonan1252
Copy link

I have a couple of lemesh.light.wy0c02 BLE Mesh Light running on the Xiaomi IoT Module-MHCB07P. These are very popular in china and no supported plugin has been found for Homebridge. Hope to see it available.

@merdok
Copy link
Owner

merdok commented Apr 16, 2022

Well this is currently not my priority due to my goal to improve and stabilize the current wifi devices as much as possible so it might take a while till i can have a look at that (and because of the lack of such bluetooth devices).
I mean if someone has knowledge about that and wants to help implementing such functionality, then it would be great if they could implement the protocol class for managing the connection to the bluetooth devices which would definitely help here.

@uswong
Copy link

uswong commented Jun 13, 2022

There are increasing number of Xiaomi smart devices using Bluetooth. I have 4 units of Xiaomi Smart Power Trip 2 (5 outlet), model qmi.plug.psv3. They connects to Xiaomi Gateway 3 with Bluetooth Mesh. Although Xiaomi Gateway 3 is dubbed as Homekit compatible but devices connected to Bluetooth Mesh do not appear on HomeKit. I also have two units of Xiaomi wall switch ZNKG02HL work only with Bluetooth Mesh.

It would be really wonderful if this plugin could be expanded to manage the connection to the Bluetooth devices.

@merdok
Copy link
Owner

merdok commented Jun 13, 2022

Still missing such a device to even have a look what the device is sending and if it would be possible to map that to the miot protocol...

@uswong
Copy link

uswong commented Jun 13, 2022

Below is the Json file of qmi.plug.psv3:

{"type":"urn:miot-spec-v2:device:outlet:0000A002:qmi-psv3:1:0000C816","description":"Single Control Outlet","services":[{"iid":1,"type":"urn:miot-spec-v2:service:device-information:00007801:qmi-psv3:1:0000C816","description":"","properties":[{"iid":1,"type":"urn:miot-spec-v2:property:manufacturer:00000001:qmi-psv3:1:0000C816","description":"Device Manufacturer","format":"string","access":["read"]},{"iid":2,"type":"urn:miot-spec-v2:property:model:00000002:qmi-psv3:1:0000C816","description":"Device Model","format":"string","access":["read"]},{"iid":3,"type":"urn:miot-spec-v2:property:serial-number:00000003:qmi-psv3:1:0000C816","description":"Device Serial Number","format":"string","access":["read"]},{"iid":4,"type":"urn:miot-spec-v2:property:firmware-revision:00000005:qmi-psv3:1:0000C816","description":"Current Firmware Version","format":"string","access":["read"]}]},{"iid":2,"type":"urn:miot-spec-v2:service:switch:0000780C:qmi-psv3:1:0000C816","description":"Switch","properties":[{"iid":1,"type":"urn:miot-spec-v2:property:on:00000006:qmi-psv3:1:0000C816","description":"Switch Status","format":"bool","access":["read","write","notify"]},{"iid":2,"type":"urn:miot-spec-v2:property:mode:00000008:qmi-psv3:1","description":"Mode","format":"int8","access":["read","write","notify"],"value-range":[0,1,1]},{"iid":3,"type":"urn:miot-spec-v2:property:temperature:00000020:qmi-psv3:1","description":"Temperature","format":"float","access":["read","notify"],"unit":"celsius","value-range":[-30,125,0.1]},{"iid":4,"type":"urn:miot-spec-v2:property:working-time:00000079:qmi-psv3:1","description":"Working Time","format":"uint32","access":["read","notify"],"unit":"minutes","value-range":[0,1440,1]}],"actions":[{"iid":1,"type":"urn:miot-spec-v2:action:toggle:00002811:qmi-psv3:1","description":"Toggle","in":[],"out":[]}]},{"iid":3,"type":"urn:miot-spec-v2:service:power-consumption:0000780E:qmi-psv3:1","description":"Power Consumption","properties":[{"iid":1,"type":"urn:miot-spec-v2:property:power-consumption:0000002F:qmi-psv3:1","description":"Power Consumption","format":"float","access":["read","notify"],"value-range":[0,20000000,0.01]},{"iid":2,"type":"urn:miot-spec-v2:property:electric-power:00000066:qmi-psv3:1","description":"Electric Power","format":"float","access":["read","notify"],"unit":"watt","value-range":[0,10000,0.0001]},{"iid":3,"type":"urn:miot-spec-v2:property:voltage:00000031:qmi-psv3:1","description":"Voltage","format":"uint32","access":["read","notify"],"value-range":[0,500000,1]},{"iid":4,"type":"urn:miot-spec-v2:property:electric-current:00000030:qmi-psv3:1","description":"Electric Current","format":"uint32","access":["read","notify"],"value-range":[0,100000,1]}]},{"iid":4,"type":"urn:qmi-spec:service:relay-count-down:00007801:qmi-psv3:1","description":"relay-count-down","properties":[{"iid":1,"type":"urn:qmi-spec:property:count-down-time:00000001:qmi-psv3:1","description":"count-down-time","format":"int32","access":["read","notify","write"],"unit":"seconds","value-range":[1,86400,1]},{"iid":2,"type":"urn:qmi-spec:property:remain-time:00000002:qmi-psv3:1","description":"remain-time","format":"int32","access":["read","notify"],"unit":"seconds","value-range":[0,86400,1]},{"iid":3,"type":"urn:qmi-spec:property:enable-count-down:00000003:qmi-psv3:1","description":"enable-count-down","format":"bool","access":["read","notify","write"]}]},{"iid":5,"type":"urn:qmi-spec:service:relay-loop-task:00007802:qmi-psv3:1","description":"relay-loop-task","properties":[{"iid":1,"type":"urn:qmi-spec:property:open-time:00000001:qmi-psv3:1","description":"open-time","format":"int32","access":["read","notify","write"],"unit":"seconds","value-range":[0,86400,1]},{"iid":2,"type":"urn:qmi-spec:property:close-time:00000002:qmi-psv3:1","description":"close-time","format":"int32","access":["read","notify","write"],"unit":"seconds","value-range":[0,86400,1]},{"iid":3,"type":"urn:qmi-spec:property:enable:00000003:qmi-psv3:1","description":"enable","format":"bool","access":["read","notify","write"]}]},{"iid":6,"type":"urn:qmi-spec:service:system:00007803:qmi-psv3:1","description":"system","properties":[{"iid":1,"type":"urn:qmi-spec:property:enable-led:00000001:qmi-psv3:1","description":"enable-led","format":"bool","access":["read","notify","write"]},{"iid":2,"type":"urn:qmi-spec:property:enable-buzzer:00000002:qmi-psv3:1","description":"enable-buzzer","format":"bool","access":["read","notify","write"]},{"iid":3,"type":"urn:qmi-spec:property:status:00000003:qmi-psv3:1","description":"status","format":"uint8","access":[],"value-list":[{"value":0,"description":"Normal"},{"value":1,"description":"Protected-OverCurrent"},{"value":2,"description":"Protected-OverTemperature"},{"value":4,"description":"Alarm-OverCurrent"},{"value":8,"description":"Alarm-OverTemperature"}]},{"iid":4,"type":"urn:qmi-spec:property:keep-relay:00000004:qmi-psv3:1","description":"keep-relay","format":"bool","access":["read","notify","write"]},{"iid":5,"type":"urn:qmi-spec:property:update-power:00000005:qmi-psv3:1","description":"update-power","format":"bool","access":["read","notify","write"]}],"events":[{"iid":1,"type":"urn:qmi-spec:event:alarm:00005001:qmi-psv3:1","description":"alarm","arguments":[3]}]},{"iid":7,"type":"urn:qmi-spec:service:calibration:00007804:qmi-psv3:1","description":"calibration"},{"iid":8,"type":"urn:qmi-spec:service:test-simulation:00007805:qmi-psv3:1","description":"test-simulation","properties":[{"iid":1,"type":"urn:qmi-spec:property:temperature:00000001:qmi-psv3:1","description":"temperature","format":"int8","access":["read","notify","write"],"unit":"celsius","value-range":[-100,100,1]},{"iid":2,"type":"urn:qmi-spec:property:current:00000002:qmi-psv3:1","description":"current","format":"int8","access":["read","notify","write"],"value-range":[0,100,1]}]}]}
~

Hope this helps.

@merdok
Copy link
Owner

merdok commented Jun 13, 2022

This is the spec which is publicly available... I need actual device communication logs...

@Avamander
Copy link

I'd add the BLE Alarm clocks to the list, the default app can't even automatically update DST through the hub... archaic stuff, a replacement would be lovely.

That aside, a Bluetooth HCI dump of certain actions would help?

@merdok
Copy link
Owner

merdok commented Nov 5, 2022

I mean sure, you can provide one.

@xmmwc
Copy link

xmmwc commented Dec 1, 2022

I found a way to add BLE devices and control it through mi cloud.
use cli print all mi cloud devices list without filter. you can get model name, token and did.but localip is empty.
then generate device js file with miot plugin(with require mi cloud checked). and move it to homebridge-miot/lib/modules/***/device/

set device config like this:

{
    "name":  "XXX",
    "ip": "0.0.0.0",
    "token": "<device token>",
    "deviceId": "<device id>",
    "model": "<device model>",
    ....
}

and reload homebridge.

@merdok
Copy link
Owner

merdok commented Dec 1, 2022

Yeah, I guess the recent changes where I removed the dependency for an ip to be required even when a device is set to a micloud only allows to make it work.
Also please note that it is now also possible to control Bluetooth devices which are connected to your bridge.

@Jonan1252
Copy link

I found a way to add BLE devices and control it through mi cloud. use cli print all mi cloud devices list without filter. you can get model name, token and did.but localip is empty. then generate device js file with miot plugin(with require mi cloud checked). and move it to homebridge-miot/lib/modules/***/device/

set device config like this:

{
    "name":  "XXX",
    "ip": "0.0.0.0",
    "token": "<device token>",
    "deviceId": "<device id>",
    "model": "<device model>",
    ....
}

and reload homebridge.

May i know what did you use as the ip?

@merdok
Copy link
Owner

merdok commented Dec 1, 2022

ip can be anything when using micloud, with a local connection you need to specify your bridge ip.

@Jonan1252
Copy link

ip can be anything when using micloud, with a local connection you need to specify your bridge ip.

i got it working with micloud, however i am not able to control the BLE lights on a local connection with the homebridge ip.

@merdok
Copy link
Owner

merdok commented Dec 1, 2022

Not homebridge ip, but your xiaomi mi HUB ip where all your devices are connected.

@Vannixxo
Copy link

Vannixxo commented Dec 1, 2022

So it isn't possible to control it without a xiaomi hub?

@merdok
Copy link
Owner

merdok commented Dec 1, 2022

No, without a hub not yet. That would require to implement the whole xiaomi Bluetooth miot protocol...

@xmmwc
Copy link

xmmwc commented Dec 2, 2022

@merdok why don't you consider generate device class js file automatically when first run and cache it.

@merdok
Copy link
Owner

merdok commented Dec 2, 2022

It is being already done. But for it to work the plugin needs the model information, so for Bluetooth mesh devices you need to manually specify the correct model in the config.json.

@pedromcortereal
Copy link

I found a way to add BLE devices and control it through mi cloud. use cli print all mi cloud devices list without filter. you can get model name, token and did.but localip is empty. then generate device js file with miot plugin(with require mi cloud checked). and move it to homebridge-miot/lib/modules/***/device/

set device config like this:

{
    "name":  "XXX",
    "ip": "0.0.0.0",
    "token": "<device token>",
    "deviceId": "<device id>",
    "model": "<device model>",
    ....
}

and reload homebridge.

hello

I followed your steps to add the Xiaomi Door and Windows Sensor 2 (isa.magnet.dw2hl) but I can only see the battery level of the sensor on homebridge, the other properties do not show up. Check the homebrigde log below.

[12/15/2022, 7:42:29 PM] [miot] [Door sensor] Initializing device services
[12/15/2022, 7:42:29 PM] [miot] [Door sensor] Device services: [
"magnet-sensor",
"battery"
]
[12/15/2022, 7:42:29 PM] [miot] [Door sensor] Initializing device properties
[12/15/2022, 7:42:29 PM] [miot] [Door sensor] Device properties: [
"magnet-sensor:illumination",
"magnet-sensor:contact-state",
"battery:battery-level"
]
[12/15/2022, 7:42:29 PM] [miot] [Door sensor] Initializing device actions
[12/15/2022, 7:42:29 PM] [miot] [Door sensor] Device not supported! Using a generic device with limited properties! Consider requesting device support!
[12/15/2022, 7:42:29 PM] [miot] [Door sensor] Initializing accessory!
[12/15/2022, 7:42:29 PM] [miot] [Door sensor] Accessory successfully initialized!
[12/15/2022, 7:42:29 PM] [miot] [Door sensor] Registering 1 accessories!
[12/15/2022, 7:42:29 PM] [miot] [Door sensor] Everything looks good! Initiating property polling!
[12/15/2022, 7:42:29 PM] [miot] [Door sensor] Log in to MiCloud!
[12/15/2022, 7:42:30 PM] [miot] [Door sensor] Successfully connected to MiCloud! Setting up miot device from MiCloud connection!
[12/15/2022, 7:42:30 PM] [miot] [Door sensor] Connected to device: isa.magnet.dw2hl
[12/15/2022, 7:42:30 PM] [miot] [Door sensor] Doing initial property fetch.
[12/15/2022, 7:42:30 PM] [miot] [Door sensor] Starting property polling.

can you help me with this?

@merdok
Copy link
Owner

merdok commented Dec 18, 2022

That is already good news that you got it to work! Unfortunately as you noticed, contact sensors are not supported yet but that should not be a big issue for me to add them. I will try to add them in the next update. For now you could use the propertyMonitor to get a trigger when the sensor is triggered.

@pedromcortereal
Copy link

That is already good news that you got it to work! Unfortunately as you noticed, contact sensors are not supported yet but that should not be a big issue for me to add them. I will try to add them in the next update. For now you could use the propertyMonitor to get a trigger when the sensor is triggered.

Thanks for the tip @merdok ! Setting the propertyMonitor I was able o get a trigger when the contact sensor is triggered. It has a 5 to 10 sec delay between when i close/open the door and the property state alters on homebridge. I guess that this delay is due to the reading's being done through Mi Cloud and not locally through the Xiaomi Smart Home Hub. Correct?

It's being interpreted by homebridge as a light sensor, and the states changes for 0 to 1 LUX according to the door is opened or closed.

@merdok
Copy link
Owner

merdok commented Dec 19, 2022

Glad that you got it working!
The delay is because of the property polling, the state only updates periodically by the specified polling interval.

@pedromcortereal
Copy link

Thanks again!! I reduced the interval to 1 sec and it's working almost instantaneously!

Is there any way I can change how Homebridge "views" the device, and change it from a light sensor to a door sensor (ex.: change the icon, the units and device type)

@merdok
Copy link
Owner

merdok commented Dec 19, 2022

@pedromcortereal You have to observe if 1 sec will not cause any issues for you.
The view of the device will be different as soon as i release the next update.

@ahmadnazirafiq
Copy link

Hi, i’ve been reading this thread and I can’t figure out how to add Xiaomi Door and Windows Sensor 2 (isa.magnet.dw2hl). Not a tech-savvy, but I do have this sensor connected to BLE hubs.

@merdok
Copy link
Owner

merdok commented Mar 5, 2023

@ahmadnazirafiq you can check in this discussion as somebody else was asking that a couple of days ago: #442

@ahmadnazirafiq
Copy link

Thank you! Managed to finally exposed three BLE-based contact sensors to HomeKit for the first time!

@ahmadnazirafiq
Copy link

That is already good news that you got it to work! Unfortunately as you noticed, contact sensors are not supported yet but that should not be a big issue for me to add them. I will try to add them in the next update. For now you could use the propertyMonitor to get a trigger when the sensor is triggered.

Thanks for the tip @merdok ! Setting the propertyMonitor I was able o get a trigger when the contact sensor is triggered. It has a 5 to 10 sec delay between when i close/open the door and the property state alters on homebridge. I guess that this delay is due to the reading's being done through Mi Cloud and not locally through the Xiaomi Smart Home Hub. Correct?

It's being interpreted by homebridge as a light sensor, and the states changes for 0 to 1 LUX according to the door is opened or closed.

What did you put in the propertyMonitor for it to distinguish open/closed condition, @pedromcortereal? I just realized it didn't react at all when I open/close the contact sensor.

@denisgabriel5
Copy link

denisgabriel5 commented Jul 19, 2023

Hi @merdok! Do you think you could help us a little bit regarding how to set the property monitor and how to change the view in Hombridge? It is currently seen as a light sensor (I guess). Thanks!

Edit: I tried all kind of combinations, but none of them got it to work. I will post my configuration and some screenshots from my Home app.

{
            "devices": [
                {
                    "name": "Door Sensor",
                    "ip": "censored",
                    "token": "censored",
                    "deviceId": "blt.4.1d07onrhkgg02",
                    "model": "isa.magnet.dw2hl",
                    "pollingInterval": 5,
                    "deepDebugLog": false,
                    "customAccessory": false,
                    "onlyMainService": true,
                    "buzzerControl": false,
                    "ledControl": false,
                    "childLockControl": false,
                    "modeControl": false,
                    "suppressAutoServiceCreation": [
                        "temperature",
                        "relativeHumidity",
                        "illumination"
                    ],
                    "propertyMonitor": [
                        {
                            "property": "magnet-sensor:contact-state",
                            "name": "Door Sensor"
                        },
                        {
                            "property": "battery:battery-level",
                            "valueOperator": "less"
                        },
                        {
                            "property": "magnet-sensor:illumination",
                            "valueOperator": "equal"
                        }
                    ]
                }
            ],
            "platform": "miot"
        }

IMG_2149
IMG_2150
IMG_2148

@merdok
Copy link
Owner

merdok commented Jul 19, 2023

You are missing the value which you expect. Setting a valueOperator to less or equal does not make sense as you did not specify what value should be taken to compare too.
Also if the Door Sensor is a numeric value then you have to specify what value is the triggered state.

@denisgabriel5
Copy link

{
                    "name": "Door Sensor",
                    "deviceId": "blt.4.1d07onrhkgg02",
                    "model": "isa.magnet.dw2hl",
                    "pollingInterval": 1,
                    "deepDebugLog": false,
                    "customAccessory": false,
                    "onlyMainService": true,
                    "buzzerControl": false,
                    "ledControl": false,
                    "childLockControl": false,
                    "modeControl": false,
                    "suppressAutoServiceCreation": [
                        "temperature",
                        "relativeHumidity",
                        "illumination"
                    ],
                    "propertyMonitor": [
                        {
                            "property": "magnet-sensor:contact-state",
                            "name": "Door Sensor",
                            "value": "1",
                            "valueOperator": "equal"
                        }
                    ]
                },

Still not working. Tried with value set to 0 as well and still no luck.

@merdok
Copy link
Owner

merdok commented Jul 20, 2023

The value type is probably not a string, also I see above that the door sensor is a contact sensor so it seems that it is fine, isn’t it?

@denisgabriel5
Copy link

denisgabriel5 commented Jul 20, 2023

When I use the interface from the Plugin tab, it writes the value between apostrophes. Also, it doesn’t work because it will always say it’s closed (it appears in the Home app, but it doesn’t do anything).

The value type for this property is bool.

@merdok
Copy link
Owner

merdok commented Jul 20, 2023

Yeah the ui unfortunately has always the type set to strong so you need to edit those values manually in the config.
But did you validate that the property actually changes? Like with the miot cli commands?

@denisgabriel5
Copy link

So, I tried with 0, 1, "0", "1", false, true, "false" and "true" and none of them works.

Regarding the CLI I tried the following:

root@denis-server:/var/lib/homebridge $ miot cloud device-info "blt.4.1d07onrhkgg02"
 INFO  Getting info for device with id blt.4.1d07onrhkgg02 from country cn...
 SUCCESS  Got device info from MiCloud
{
  "did": "blt.4.1d07onrhkgg02",
  "token": "censored",
  "longitude": "0.0",
  "latitude": "0.0",
  "name": "Door Sensor",
  "pid": "6",
  "localip": "<censored>",
  "mac": "<censored>",
  "ssid": "",
  "bssid": "",
  "parent_id": "",
  "parent_model": "",
  "show_mode": 1,
  "model": "isa.magnet.dw2hl",
  "adminFlag": 1,
  "shareFlag": 0,
  "permitLevel": 16,
  "isOnline": false,
  "desc": "",
  "extra": {
    "isSetPincode": 0,
    "pincodeType": 0,
    "fw_version": "2.1.0_0059",
    "needVerifyCode": 0,
    "isPasswordEncrypt": 0
  },
  "uid": 6471108181,
  "pd_id": 2443,
  "password": "",
  "p2p_id": "",
  "rssi": 0,
  "family_id": 0,
  "reset_flag": 0
}
root@denis-server:/var/lib/homebridge $ miot test <censored> --token censored
 INFO  Connecting to device at <censored>
Could not connect to device, handshake timeout
 ERROR  Could not connect to the device at <censored>! Make sure the ip and token are correct!

@merdok
Copy link
Owner

merdok commented Jul 20, 2023

When it is a bool, then value should be either true or false.

miot test is for testing the local connection.
You have to send the command to retrieve the property over mi cloud as it seems that you have that set up.

@denisgabriel5
Copy link

You mean like this?

root@denis-server:/var/lib/homebridge $ miot cloud get-props 2.1            
 INFO  Executing get_properties command over MiCloud country cn with params 2.1 - timeout: 10000
(MiCloud) No result in response from MiCloud! Message: data type not valid
 SUCCESS  Response from MiCloud -> null
root@denis-server:/var/lib/homebridge $ miot cloud get-props 2.2
 INFO  Executing get_properties command over MiCloud country cn with params 2.2 - timeout: 10000
(MiCloud) No result in response from MiCloud! Message: data type not valid
 SUCCESS  Response from MiCloud -> null
root@denis-server:/var/lib/homebridge $ miot cloud get-props 3.1
 INFO  Executing get_properties command over MiCloud country cn with params 3.1 - timeout: 10000
(MiCloud) No result in response from MiCloud! Message: data type not valid
 SUCCESS  Response from MiCloud -> null

@merdok
Copy link
Owner

merdok commented Jul 20, 2023

No, it has to be a raw parameter string.
Have a look at the robot cleaner docs, there is an example for miot send get_properties but the param string should be similar for the cloud command.

@denisgabriel5
Copy link

By the way, I grabbed this debug log:

[7/20/2023, 12:04:05 PM] [miot] [Door Sensor] Preparing property poll!
[7/20/2023, 12:04:05 PM] [miot] [Door Sensor] Splitting properties into chunks. Number of chunks: 1. Chunk size: 14
[7/20/2023, 12:04:05 PM] [miot] [Door Sensor] Chunks:  [
 [
  "magnet-sensor:illumination",
  "magnet-sensor:contact-state",
  "battery:battery-level"
 ]
]
[7/20/2023, 12:04:05 PM] [miot] [Door Sensor] (MiCloud) Encrypted request https://api.io.mi.com/app/miotspec/prop/get - {"params":[{"did":"blt.4.1d07onrhkgg02","siid":2,"piid":1},{"did":"blt.4.1d07onrhkgg02","siid":2,"piid":2},{"did":"blt.4.1d07onrhkgg02","siid":3,"piid":1}]}
[7/20/2023, 12:04:05 PM] [miot] [Door Sensor] Successfully updated property chunk! RAW: [{"did":"blt.4.1d07onrhkgg02","iid":"0.2.1","siid":2,"piid":1,"code":-704010000,"exe_time":0},{"did":"blt.4.1d07onrhkgg02","iid":"0.2.2","siid":2,"piid":2,"code":-704010000,"exe_time":0},{"did":"blt.4.1d07onrhkgg02","iid":"0.3.1","siid":3,"piid":1,"code":-704010000,"exe_time":0}]
[7/20/2023, 12:04:05 PM] [miot] [Door Sensor] Error while parsing response from device for property magnet-sensor:illumination. Response: {"did":"blt.4.1d07onrhkgg02","iid":"0.2.1","siid":2,"piid":1,"code":-704010000,"exe_time":0}
[7/20/2023, 12:04:05 PM] [miot] [Door Sensor] Error while parsing response from device for property magnet-sensor:contact-state. Response: {"did":"blt.4.1d07onrhkgg02","iid":"0.2.2","siid":2,"piid":2,"code":-704010000,"exe_time":0}
[7/20/2023, 12:04:05 PM] [miot] [Door Sensor] Error while parsing response from device for property battery:battery-level. Response: {"did":"blt.4.1d07onrhkgg02","iid":"0.3.1","siid":3,"piid":1,"code":-704010000,"exe_time":0}
[7/20/2023, 12:04:05 PM] [miot] [Door Sensor] Device properties updated: 
[
  "magnet-sensor:illumination: 0 | (not synced)",
  "magnet-sensor:contact-state: false | (not synced)",
  "battery:battery-level: 0 | (not synced)"
]

@merdok
Copy link
Owner

merdok commented Jul 20, 2023

Yeah, there is an error during property sync, that would explain why you do not see the sensor update.
I do not know what that error code means, it comes from the server, not sure why… maybe the device cannot be reached?

@denisgabriel5
Copy link

I found this and from the translation (Bluetooth device cloud error - 704010000 Unknown, the plug-in is powerless.) of the first reply it seems that my battery is dead (which is weird because in the Mi Home app it works).

@merdok
Copy link
Owner

merdok commented Jul 20, 2023

I also noticed that in the cloud device info from above the sensor is not online.
Instead of a cloud connection you could also try to do a direct connection over the gateway and check if that helps.

@denisgabriel5
Copy link

Any idea how to do that?

@merdok
Copy link
Owner

merdok commented Jul 20, 2023

The ip and token needs to be from your gateway, the deviceid and model needs to from the device connected to the gateway which you want to control.

@denisgabriel5
Copy link

Tried it. It doesn't work.

@merdok
Copy link
Owner

merdok commented Jul 20, 2023

What does the debug log say in that case? Did you tried to do a test connection using the miot cli?

@denisgabriel5
Copy link

denisgabriel5 commented Jul 20, 2023

Devices

┌─────────┬────────────────────────────────┬─────────────────────────┬────────────────────────────────────┬────────────────┬───────────────────────┬─────────┐
│ (index) │              name              │          model          │               token                │    localip     │          did          │ country │
├─────────┼────────────────────────────────┼─────────────────────────┼────────────────────────────────────┼────────────────┼───────────────────────┼─────────┤
│    0    │           'Gateway'            │  'lumi.gateway.mgl03'   │ '464f49646e666f464254686a774e7632' │   '5.5.5.55'   │      '374615801'      │  'cn'   │
│    1    │         'Door Sensor'          │   'isa.magnet.dw2hl'    │     '2afc4db1bc730234761d0ec5'     │  '<censored>'  │ 'blt.4.1d07onrhkgg02' │  'cn'   │
└─────────┴────────────────────────────────┴─────────────────────────┴────────────────────────────────────┴────────────────┴───────────────────────┴─────────┘

Config

{
                    "name": "Door Sensor",
                    "ip": "5.5.5.55",
                    "token": "464f49646e666f464254686a774e7632",
                    "deviceId": "blt.4.1d07onrhkgg02",
                    "model": "isa.magnet.dw2hl",
                    "pollingInterval": 1,
                    "deepDebugLog": true,
                    "customAccessory": false,
                    "onlyMainService": false,
                    "buzzerControl": false,
                    "ledControl": false,
                    "childLockControl": false,
                    "modeControl": false,
                    "suppressAutoServiceCreation": [
                        "temperature",
                        "relativeHumidity",
                        "illumination"
                    ]
                }

miot cli

miot test 5.5.5.55 -d -t 464f49646e666f464254686a774e7632
 INFO  Connecting to device at 5.5.5.55
(Protocol) Call 5.5.5.55: miIO.info - {"retries":3,"timeout":5000} - {}
(Protocol) Start handshake 5.5.5.55
(Protocol) 5.5.5.55 <- (2) {"method":"miIO.info","params":{"retries":3,"timeout":5000},"id":1}
(Protocol) 5.5.5.55 <- !1pT.�"�Go���rb�v�F���
(Protocol) Start handshake 5.5.5.55
(Protocol) 5.5.5.55 <- (1) {"method":"miIO.info","params":{"retries":3,"timeout":5000},"id":101}
(Protocol) 5.5.5.55 <- !1pT.�"�������l�]��KB�{
(Protocol) Start handshake 5.5.5.55
(Protocol) 5.5.5.55 <- (0) {"method":"miIO.info","params":{"retries":3,"timeout":5000},"id":201}
(Protocol) 5.5.5.55 <- !1pT.�"�E���ˀ�0�Z�[
(Protocol) 5.5.5.55 <- Reached maximum number of retries, giving up miIO.info - {"retries":3,"timeout":5000}
(Protocol) 5.5.5.55 <- Error during send! (timeout) Call to device timed out | Request: {"method":"miIO.info","params":{"retries":3,"timeout":5000},"id":201}
Call to device timed out
 ERROR  Could not connect to the device at 5.5.5.55! Make sure the ip and token are correct!

Log

[7/20/2023, 3:32:46 PM] [homebridge-miot] Restarting Process...
[7/20/2023, 3:32:47 PM] [homebridge-miot] Launched child bridge with PID 12170
[7/20/2023, 3:32:47 PM] Registering platform 'homebridge-miot.miot'
[7/20/2023, 3:32:47 PM] [homebridge-miot] Loaded homebridge-miot v1.6.2 child bridge successfully
[7/20/2023, 3:32:48 PM] Loaded 2 cached accessories from cachedAccessories.0E6BC2844002.
[7/20/2023, 3:32:48 PM] [homebridge-miot] Found cached accessory Door Sensor
[7/20/2023, 3:32:48 PM] Publishing bridge accessory (name: homebridge-miot, publishInfo: {
  username: '0E:6B:C2:84:40:02',
  port: 43259,
  pincode: '***-**-***',
  category: 2,
  bind: undefined,
  mdns: undefined,
  addIdentifyingMaterial: true,
  advertiser: 'bonjour-hap'
}).
[7/20/2023, 3:32:48 PM] [homebridge-miot] Initializing devices
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Got device configuration, initializing device with name: Door Sensor
[7/20/2023, 3:32:48 PM] [homebridge-miot] No accessories to remove!
[7/20/2023, 3:32:48 PM] Homebridge v1.6.1 (HAP v0.11.1) (homebridge-miot) is running on port 43259.
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Found cached device information: isa.magnet.dw2hl
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Model known: isa.magnet.dw2hl!
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Initializing device!
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Creating device instance by model: isa.magnet.dw2hl!
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Not a airconditioner device! Device class could not be found: ../modules/airconditioner/devices/isa.magnet.dw2hl.js
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Not a airer device! Device class could not be found: ../modules/airer/devices/isa.magnet.dw2hl.js
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Not a airfryer device! Device class could not be found: ../modules/airfryer/devices/isa.magnet.dw2hl.js
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Not a airmonitor device! Device class could not be found: ../modules/airmonitor/devices/isa.magnet.dw2hl.js
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Not a airpurifier device! Device class could not be found: ../modules/airpurifier/devices/isa.magnet.dw2hl.js
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Not a bathheater device! Device class could not be found: ../modules/bathheater/devices/isa.magnet.dw2hl.js
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Not a camera device! Device class could not be found: ../modules/camera/devices/isa.magnet.dw2hl.js
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Not a ceilingfan device! Device class could not be found: ../modules/ceilingfan/devices/isa.magnet.dw2hl.js
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Not a coffeemachine device! Device class could not be found: ../modules/coffeemachine/devices/isa.magnet.dw2hl.js
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] It is a contactsensor device! Found device class at ../modules/contactsensor/devices/isa.magnet.dw2hl.js!
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Initializing device services
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Device services: [
  "magnet-sensor",
  "battery"
]
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Initializing device properties
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Device properties: [
  "magnet-sensor:illumination",
  "magnet-sensor:contact-state",
  "battery:battery-level"
]
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Initializing device actions
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Initializing device events
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Initial properties to monitor: [
  "magnet-sensor:illumination",
  "magnet-sensor:contact-state",
  "battery:battery-level"
]
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Successfully created a ContactSensor device! It is a Xiaomi Door and Windows Sensor 2.
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Found cached accessory for this device! Unregistering it first!
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Initializing accessory!
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Creating ContactSensor accessory for device Door Sensor!
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Found accessory class at ../modules/contactsensor/ContactSensorAccessory.js!
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Accessory successfully initialized!
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Final properties to monitor: [
  "magnet-sensor:illumination",
  "magnet-sensor:contact-state",
  "battery:battery-level"
]
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Registering 1 accessories!
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] Everything looks good! Initiating property polling!
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] (Protocol) Start handshake 5.5.5.55
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] (Protocol) Server listening 0.0.0.0:47350
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] (Protocol) 5.5.5.55 -> Handshake reply
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] (Protocol) Call 5.5.5.55: miIO.info - {"timeout":5000,"retries":3} - {}
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] (Protocol) Start handshake 5.5.5.55
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] (Protocol) 5.5.5.55 <- (2) {"method":"miIO.info","params":{"timeout":5000,"retries":3},"id":1}
[7/20/2023, 3:32:48 PM] [homebridge-miot] [Door Sensor] (Protocol) 5.5.5.55 <- !1�p�����T.���%�xS���������eN�S�
[7/20/2023, 3:32:52 PM] [homebridge-miot] [Door Sensor] (Protocol) Start handshake 5.5.5.55
[7/20/2023, 3:32:52 PM] [homebridge-miot] [Door Sensor] (Protocol) 5.5.5.55 <- (1) {"method":"miIO.info","params":{"timeout":5000,"retries":3},"id":101}
[7/20/2023, 3:32:52 PM] [homebridge-miot] [Door Sensor] (Protocol) 5.5.5.55 <- !1�p�����T.���%"�e������S�l^�6��
[7/20/2023, 3:32:56 PM] [homebridge-miot] [Door Sensor] (Protocol) Start handshake 5.5.5.55
[7/20/2023, 3:32:56 PM] [homebridge-miot] [Door Sensor] (Protocol) 5.5.5.55 <- (0) {"method":"miIO.info","params":{"timeout":5000,"retries":3},"id":201}
[7/20/2023, 3:32:56 PM] [homebridge-miot] [Door Sensor] (Protocol) 5.5.5.55 <- !1�p�����T.���%&�6X��R�@x���o���
[7/20/2023, 3:33:00 PM] [homebridge-miot] [Door Sensor] (Protocol) 5.5.5.55 <- Reached maximum number of retries, giving up miIO.info - {"timeout":5000,"retries":3}
[7/20/2023, 3:33:00 PM] [homebridge-miot] [Door Sensor] (Protocol) 5.5.5.55 <- Error during send! (timeout) Call to device timed out | Request: {"method":"miIO.info","params":{"timeout":5000,"retries":3},"id":201}
[7/20/2023, 3:33:00 PM] [homebridge-miot] [Door Sensor] Error: Call to device timed out
[7/20/2023, 3:33:00 PM] [homebridge-miot] [Door Sensor] Error during connection! Retrying in 60 seconds!

@merdok
Copy link
Owner

merdok commented Jul 20, 2023

The ip or token which you provided are most probably incorrect

@denisgabriel5
Copy link

denisgabriel5 commented Jul 20, 2023

What makes you say that?

The token is the one provided by miot cloud list-devices --all

@merdok
Copy link
Owner

merdok commented Jul 20, 2023

Because the plugin cannot connect to the device, this is usually caused by an incorrect token or ip address.
The token in the cloud can be outdated if you did not sync it.

@vsternbach
Copy link

@kikiwora Also wanted to control my Candela lamps, so wrote this plugin https://github.com/vsternbach/homebridge-yeelight-ble and you're welcome to try it.
Note that unfortunately I couldn't make it stable enough to run purely on nodejs with noble, so adapted some python library for bluetooth manipulation for Yeelight BLE devices that serves as a backend for my homebridge plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests