merdok / homebridge-miot

Homebridge plugin for devices supporting the Xiaomi miot protocol
MIT License
371 stars 62 forks source link

Support for more BLE-based Devices #443

Closed ahmadnazirafiq closed 1 year ago

ahmadnazirafiq commented 1 year ago

Device model

  1. cleargrass.sensor_ht.dk1
  2. miaomiaoce.sensor_ht.t2
  3. lumi.flood.bmcn01
  4. philips.light.nlight

Device name

  1. Mi Temperature and Humidity Monitor
  2. Mi Temperature and Humidity Monitor 2 BLE
  3. Mi Flood Detector
  4. Mijia Philips BLE Nightlight

Does the device require a MiCloud connection? Yes

Anything special about the device? Using the same method of adding Mi Door and Window Sensor 2, the plugin was able to identify all device types correctly but stated as Not Supported in HomeKit. These device types supports native HomeKit feature like temperature sensor, submersion sensor, etc.

Based on helpful thread here #442, I manage to expose the (not-yet-supported on the plugin) Qingping Door/Window Contact sensor the same way as Xiaomi's ones.

ahmadnazirafiq commented 1 year ago

Logs from Homebridge are as follows:

[06/03/2023, 01:32:04] [homebridge-miot] [TESTHygro] Initializing device services [06/03/2023, 01:32:04] [homebridge-miot] [TESTHygro] Device services: [ "temperature-humidity-sensor", "battery" ] [06/03/2023, 01:32:04] [homebridge-miot] [TESTHygro] Initializing device properties [06/03/2023, 01:32:04] [homebridge-miot] [TESTHygro] Device properties: [ "temperature-humidity-sensor:temperature", "temperature-humidity-sensor:relative-humidity", "battery:battery-level" ] [06/03/2023, 01:32:04] [homebridge-miot] [TESTHygro] Initializing device actions [06/03/2023, 01:32:04] [homebridge-miot] [TESTHygro] Successfully created a Generic device! It is a Temperature Humidity Sensor. [06/03/2023, 01:32:04] [homebridge-miot] [TESTHygro] Initializing accessory! [06/03/2023, 01:32:04] [homebridge-miot] [TESTHygro] Accessory successfully initialized! [06/03/2023, 01:32:04] [homebridge-miot] [TESTHygro] Registering 1 accessories! [06/03/2023, 01:32:04] [homebridge-miot] [TESTHygro] Everything looks good! Initiating property polling! [06/03/2023, 01:32:04] [homebridge-miot] [TESTSidewallLight] Using module class for device type Light, indentified by miot spec! Not all features might work! [06/03/2023, 01:32:04] [homebridge-miot] [TESTSidewallLight] Initializing device services [06/03/2023, 01:32:04] [homebridge-miot] [TESTSidewallLight] Device services: [ "motion-sensor" ] [06/03/2023, 01:32:04] [homebridge-miot] [TESTSidewallLight] Initializing device properties [06/03/2023, 01:32:04] [homebridge-miot] [TESTSidewallLight] Device properties: [] [06/03/2023, 01:32:04] [homebridge-miot] [TESTSidewallLight] Initializing device actions [06/03/2023, 01:32:04] [homebridge-miot] [TESTSidewallLight] Successfully created a Light device! It is a Unknown light device. [06/03/2023, 01:32:05] [homebridge-miot] [TESTSidewallLight] Initializing accessory! [06/03/2023, 01:32:05] [homebridge-miot] [TESTSidewallLight] Accessory successfully initialized! [06/03/2023, 01:32:05] [homebridge-miot] [TESTSidewallLight] Registering 1 accessories! [06/03/2023, 01:32:05] [homebridge-miot] [TESTSidewallLight] Everything looks good! Initiating property polling! [06/03/2023, 01:32:05] [homebridge-miot] [TESTFoyerLeak] Initializing device services [06/03/2023, 01:32:05] [homebridge-miot] [TESTFoyerLeak] Device services: [ "submersion-sensor", "battery" ] [06/03/2023, 01:32:05] [homebridge-miot] [TESTFoyerLeak] Initializing device properties [06/03/2023, 01:32:05] [homebridge-miot] [TESTFoyerLeak] Device properties: [ "submersion-sensor:submersion-state", "battery:battery-level" ] [06/03/2023, 01:32:05] [homebridge-miot] [TESTFoyerLeak] Initializing device actions [06/03/2023, 01:32:05] [homebridge-miot] [TESTFoyerLeak] Successfully created a Generic device! It is a Submersion Sensor.

merdok commented 1 year ago

Thanks for the request! Can you shortly describe what is working and what i snot working with the sensors, so i have an idea what i should focus on?

ahmadnazirafiq commented 1 year ago

At the moment, these devices are appear as Not Supported in HomeKit. On Homebridge, only the battery module of each sensors shows up, none of the main sensors. However, on Homebridge logs sent above, the plugin was able to identify all these devices itself and along with its properties. I'm not sure if this information helps.

Regarding the Mi Contact sensors as mentioned in #442, does it have a delay for the status to be reflected in HomeKit? Because when I try to open/close the sensor, it doesn't reflect its actual position even after awhile.

mrmaximas commented 1 year ago

Please don't remember about my hhcc.plantmonitor.v1 ;) It's works via light sensor property, but please link plant-monitor:relative-humidity to the humidity sensor in homekit.

merdok commented 1 year ago

@ahmadnazirafiq whatever the gateway reports will be displayed, in debug mode you will be able to see in the log what values come back.

@mrmaximas i will try to add that too

mrmaximas commented 1 year ago

i will try to add that too

thks for this hardwork!

mrmaximas commented 1 year ago

By the way, is it possible to do this: the first one plant-monitor:relative-humidity with the "value": "XX" signals that it is time to water, the second one just shows the humidity? "propertyMonitor": [ { "property": "plant-monitor:relative-humidity", "name": "Singonium Humidity Alram", "value": "25" }, { "property": "plant-monitor:relative-humidity", "name": "Singonium Humidity", }, { "property": "plant-monitor:soil-ec", "name": "Singonium Soil" }

merdok commented 1 year ago

Yeah, it is possible and you can create as many propertyMonitor entries for a property as you need.

mrmaximas commented 1 year ago

Yeah, it is possible and you can create as many propertyMonitor entries for a property as you need.

I often get a message like this: [Singonium] Poll failed 4 times in a row! Stopping polling and trying to reconnect! Reason: FetchError: network timeout at: https://api.io.mi.com/app/miotspec/prop/get I've tried to add "propertyChunkSize": 1, but there are more and more of these messages. I returned the parameter to default (deleted it). I have 10 such sensors in total. Is this a micloud problem? My polling interval is 10 minutes ( "pollingInterval": 600, ), I don't see the point of polling the plant sensors more often.

merdok commented 1 year ago

Sometimes the micloud server might be slow to respond, you can try to increase the timeout by double and see if that helps.

ahmadnazirafiq commented 1 year ago

Here's the log with debug mode enabled:

[06/03/2023, 18:42:12] [homebridge-miot] [Store Door] (Protocol) Start handshake 192.168.1.72 [06/03/2023, 18:42:12] [homebridge-miot] [Store Door] (Protocol) Call 192.168.1.72: miIO.info - {"timeout":5000,"retries":3} - {} [06/03/2023, 18:42:12] [homebridge-miot] [Store Door] (Protocol) Start handshake 192.168.1.72 [06/03/2023, 18:42:12] [homebridge-miot] [Store Door] (Protocol) 192.168.1.72 <- (2) {"method":"miIO.info","params":{"timeout":5000,"retries":3},"id":202} [06/03/2023, 18:42:12] [homebridge-miot] [Store Door] (Protocol) 192.168.1.72 <- !1p�-��y�C�,�ڈ5E�S�l [06/03/2023, 18:42:12] [homebridge-miot] [Room Window] (Protocol) Start handshake 192.168.1.72 [06/03/2023, 18:42:12] [homebridge-miot] [Room Window] (Protocol) Call 192.168.1.72: miIO.info - {"timeout":5000,"retries":3} - {} [06/03/2023, 18:42:12] [homebridge-miot] [Room Window] (Protocol) Start handshake 192.168.1.72 [06/03/2023, 18:42:12] [homebridge-miot] [Room Window] (Protocol) 192.168.1.72 <- (2) {"method":"miIO.info","params":{"timeout":5000,"retries":3},"id":202} [06/03/2023, 18:42:12] [homebridge-miot] [Room Window] (Protocol) 192.168.1.72 <- !1p�-��y>��i���i����Of� [06/03/2023, 18:42:16] [homebridge-miot] [Store Door] (Protocol) Start handshake 192.168.1.72 [06/03/2023, 18:42:16] [homebridge-miot] [Store Door] (Protocol) 192.168.1.72 <- (1) {"method":"miIO.info","params":{"timeout":5000,"retries":3},"id":302} [06/03/2023, 18:42:16] [homebridge-miot] [Store Door] (Protocol) 192.168.1.72 <- !1p�-��})K�vP�.�S"<�=� [06/03/2023, 18:42:16] [homebridge-miot] [Room Window] (Protocol) Start handshake 192.168.1.72 [06/03/2023, 18:42:16] [homebridge-miot] [Room Window] (Protocol) 192.168.1.72 <- (1) {"method":"miIO.info","params":{"timeout":5000,"retries":3},"id":302} [06/03/2023, 18:42:16] [homebridge-miot] [Room Window] (Protocol) 192.168.1.72 <- !1p�-��}4��"�]�l�-M��J� [06/03/2023, 18:42:16] [homebridge-miot] [Washer Lid] (Protocol) Start handshake 192.168.1.72 [06/03/2023, 18:42:16] [homebridge-miot] [Washer Lid] (Protocol) Call 192.168.1.72: miIO.info - {"timeout":5000,"retries":3} - {} [06/03/2023, 18:42:16] [homebridge-miot] [Washer Lid] (Protocol) Start handshake 192.168.1.72 [06/03/2023, 18:42:16] [homebridge-miot] [Washer Lid] (Protocol) 192.168.1.72 <- (2) {"method":"miIO.info","params":{"timeout":5000,"retries":3},"id":202} [06/03/2023, 18:42:16] [homebridge-miot] [Washer Lid] (Protocol) 192.168.1.72 <- !1p�-��}��Spi�����6�w

Does the BLE gateway's IP address has to be the ones added with this plugin?

mrmaximas commented 1 year ago

Sometimes the micloud server might be slow to respond, you can try to increase the timeout by double and see if that helps.

trying to :) "timeout": 10000,

merdok commented 1 year ago

@ahmadnazirafiq it has to be the gateway where your BLE devices are connected to.

@mrmaximas 👍

mrmaximas commented 1 year ago

Does the BLE gateway's IP address has to be the ones added with this plugin?

In fact, BLE devices can only be polled via micloud. I think the plugin should add the otion "ble": true and force the use of micloud by default.

@ahmadnazirafiq it has to be the gateway where your BLE devices are connected to.

It works with my external GW IP for example, I think it will work with the 1.1.1.1 )

mrmaximas commented 1 year ago

@mrmaximas 👍

didn't help much. trying 20000

ahmadnazirafiq commented 1 year ago

Upon many attempts, this config works for all my contact sensors:

I have removed all propertyMonitor stuff because it works without it although the illuminance sensor doesn't work with it.

@merdok Let me know anything you need from me to try the rest of the BLE-devices requested above.

merdok commented 1 year ago

I am certain that you do not need to use micloud if everything is entered correctly. It should also work with a local connection directly to the gateway which should be more stable.

mrmaximas commented 1 year ago

I am certain that you do not need to use micloud if everything is entered correctly. It should also work with a local connection directly to the gateway which should be more stable.

i will try to use BLE gateway IP, but i have two Xiaomi Smart Home Gateway 3 each of which partially sees my ble devices

ahmadnazirafiq commented 1 year ago

I am certain that you do not need to use micloud if everything is entered correctly. It should also work with a local connection directly to the gateway which should be more stable.

i will try to use BLE gateway IP, but i have two Xiaomi Smart Home Gateway 3 each of which partially sees my ble devices

I've tried, but as soon as I've disabled Force MiCloud connection, the sensors stops reporting again. I will monitor this and see how consistent this is.

By the way, I'm trying to add a BLE temperature sensor cleargrass.sensor_ht.dk1 the same way as the config above. Seems like only the battery status were exposed, nothing else.

ahmadnazirafiq commented 1 year ago

I am certain that you do not need to use micloud if everything is entered correctly. It should also work with a local connection directly to the gateway which should be more stable.

i will try to use BLE gateway IP, but i have two Xiaomi Smart Home Gateway 3 each of which partially sees my ble devices

Pick the gateway closest to the sensor itself. The way BLE-sensor works is that it connects to multiple gateways at the same time.

merdok commented 1 year ago

Not sure how to handle it when you have multiple gateways😅 Anyway, your BLE temperature sensor looks like this http://www.merdok.org/miotspec/?model=cleargrass.sensor_ht.dk1 The temperature and humidity are on a not supported service. Will need to add that... Just it will take some time until i can start to work on that as i am on vacation starting from tomorrow for 3 weeks...

mrmaximas commented 1 year ago

Pick the gateway closest to the sensor itself. The way BLE-sensor works is that it connects to multiple gateways at the same time.

Of course, I gave for part of the sensors first ble gateway IP and the others second ble gateway IP, but it doesn't seem to be working, it only works when I specify the external ip of my core router, which micloud sees and wich token extractor gives me.

ahmadnazirafiq commented 1 year ago

Not sure how to handle it when you have multiple gateways😅 Anyway, your BLE temperature sensor looks like this http://www.merdok.org/miotspec/?model=cleargrass.sensor_ht.dk1 The temperature and humidity are on a not supported service. Will need to add that... Just it will take some time until i can start to work on that as i am on vacation starting from tomorrow for 3 weeks...

Oh haha alright, no worries take your time. Enjoy your holidays :)

romacv commented 1 year ago

+1 for miaomiaoce.sensor_ht.t2 (Mi Temperature and Humidity Monitor 2 BLE), really need to support it. Let me know if i can help somehow.

romacv commented 1 year ago

Device model 1) miaomiaoce.sensor_ht.t2 2) miaomiaoce.sensor_ht.o2

Device name 1) Mi Temperature and Humidity Monitor 2 BLE 2) Xiaomi Temperature and Humidity Monitor Clock BLE

mrmaximas commented 1 year ago

Not sure how to handle it when you have multiple gateways😅 Anyway, your BLE temperature sensor looks like this http://www.merdok.org/miotspec/?model=cleargrass.sensor_ht.dk1 The temperature and humidity are on a not supported service. Will need to add that... Just it will take some time until i can start to work on that as i am on vacation starting from tomorrow for 3 weeks...

Have you forgotten about us? Thanks!

merdok commented 1 year ago

Version 1.6.0 now adds support for those devices.

mrmaximas commented 1 year ago

Version 1.6.0 now adds support for those devices.

it's possible to automatically add sensor name before temperature/soil and illumination? it is difficult to understand which sensor corresponds to which value ) IMG_8769 IMG_8770

merdok commented 1 year ago

You should be able to rename them.

mrmaximas commented 1 year ago

You should be able to rename them.

yes, but the sensor name is added to the humidity automatically 🤷🏻‍♂️ image

mrmaximas commented 1 year ago

You should be able to rename them.

I had a hard time finding and renaming all 30 sensors, then I changed the polling time in the settings and... after restarting plugin all the names were reset ((

merdok commented 1 year ago

Yeah, well that is quite odd. I guess that is the downside after fixing the switch names...

mrmaximas commented 1 year ago

Yeah, well that is quite odd. I guess that is the downside after fixing the switch names...

besides - nothing happens when the "presence detector" is below the limit. I have set a 25% humidity for the alarm, such as this. some sensors have a value below 25% , { "name": "Klara", "ip": "xxxx", "token": "xxxxx", "deviceId": "blt.3.13le5i950e000", "pollingInterval": 300, "deepDebugLog": false, "micloud": { "username": "xxxxxx", "password": "xxxx", "country": "cn", "forceMiCloud": true }, "suppressAutoServiceCreation": [ "temperature", "illumination" ], "propertyMonitor": [ { "property": "plant-monitor:relative-humidity", "name": "Klara Humidity Alarm", "value": "25" } ] },

Screenshot 2023-04-08 at 13 44 49 Screenshot 2023-04-08 at 13 44 57

merdok commented 1 year ago

The value has to be exact 25 to trigger. It would make sense to introduce the possibility to set below or above. If you could open a feature request for that then i will not forget it and include it in the next update.

mrmaximas commented 1 year ago

The value has to be exact 25 to trigger. It would make sense to introduce the possibility to set below or above. If you could open a feature request for that then i will not forget it and include it in the next update.

done!

ahmadnazirafiq commented 1 year ago

Is there any way to turn off the automatic renaming on these BLE devices? Its hard for me to keep track off as the name changes itself with every update/homebridge restarts.

romacv commented 1 year ago

@ahmadnazirafiq my suggestion is: rename it in parent Mi Home app like “Bedroom Thermometer”, “Living Room Thermometer”, etc. Then after adding to HomeKit - you can clear name of sensor and see what exact name and location of sensor. Then easily setup new name of sensor in HomeKit app. IMG_8441

mrmaximas commented 4 months ago

@merdok can you please tell me why it's being ignored suppression of illumination sensor creation with this config? Temperature sensors are not created, but light sensors are. "suppressAutoServiceCreation": [ "temperature", "illumination" ]

=== { "name": "Asparagus L", "ip": "111111", "token": "111111", "deviceId": "blt.3.13le7e6ogek00", "model": "hhcc.plantmonitor.v1", "pollingInterval": 300, "deepDebugLog": false, "micloud": { "username": "11111", "password": "11111", "country": "cn", "forceMiCloud": true }, "buzzerControl": true, "ledControl": true, "childLockControl": true, "modeControl": true, "suppressAutoServiceCreation": [ "temperature", "illumination" ], "propertyMonitor": [ { "property": "plant-monitor:relative-humidity", "name": "Asparagus L Humidity Alarm", "value": "20", "valueOperator": "lessOrEqual" } ] },

From the log:

[Asparagus L] Device properties: [ "plant-monitor:relative-humidity", "plant-monitor:soil-ec", "plant-monitor:illumination", "environment:temperature"

merdok commented 4 months ago

Hmmm, it should work. Might be a bug if the illumination sensor is still created for the device. If that is indeed the case then it would be great if you can open a separate bug.

mrmaximas commented 4 months ago

Hmmm, it should work. Might be a bug if the illumination sensor is still created for the device. If that is indeed the case then it would be great if you can open a separate bug.

PPA for this log:

[3/1/2024, 3:55:48 PM] [homebridge-miot] [Asparagus L] Using module class for device type PlantMonitor, indentified by miot spec! Not all features might work! [3/1/2024, 3:55:48 PM] [homebridge-miot] [Asparagus L] Initializing device services [3/1/2024, 3:55:48 PM] [homebridge-miot] [Asparagus L] Device services: [ "plant-monitor", "environment" ] [3/1/2024, 3:55:48 PM] [homebridge-miot] [Asparagus L] Initializing device properties [3/1/2024, 3:55:48 PM] [homebridge-miot] [Asparagus L] Device properties: [ "plant-monitor:relative-humidity", "plant-monitor:soil-ec", "plant-monitor:illumination", "environment:temperature" ] may be because temperature is environment?

merdok commented 4 months ago

It is very strange. Just double checked the code and everything seems fine, the light sensor should not show up...

mrmaximas commented 4 months ago

It is very strange. Just double checked the code and everything seems fine, the light sensor should not show up...

i'm sorry for my inattention, soil-ec is the illumination sensor too in the HK BTW soil-ec not suppressed too "suppressAutoServiceCreation": [ "temperature", "illumination", "soil-ec" ], Screenshot 2024-03-01 at 16 43 43

merdok commented 4 months ago

Yes, disabling soil ec is not supported. You would need to set the onlyMainAccessory property to disable that.

mrmaximas commented 4 months ago

onlyMainAccessory

how to do it? now i need only relative-humidity and this property monitor

merdok commented 4 months ago

onlyMainService I mean sorry. All the info is in the README.

mrmaximas commented 4 months ago

onlyMainService I mean sorry. All the info is in the README.

, { "name": "Singonium", "ip": "111", "token": "11", "deviceId": "blt.3.18q9fou54e400", "model": "hhcc.plantmonitor.v1", "pollingInterval": 300, "deepDebugLog": false, "micloud": { "username": "111", "password": "111", "country": "cn", "forceMiCloud": true }, "onlyMainService": true, "suppressAutoServiceCreation": [ "temperature", "illumination" ], "propertyMonitor": [ { "property": "plant-monitor:relative-humidity", "name": "Singonium", "value": "20", "valueOperator": "lessOrEqual" } ] },

it's works! have a nice weekend!