merdok / homebridge-miot

Homebridge plugin for devices supporting the Xiaomi miot protocol
MIT License
399 stars 64 forks source link

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

Open kikiwora opened 2 years ago

kikiwora commented 2 years ago

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 commented 1 year ago

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

denisgabriel5 commented 1 year ago

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���Sl^�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 commented 1 year ago

The ip or token which you provided are most probably incorrect

denisgabriel5 commented 1 year ago

What makes you say that?

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

merdok commented 1 year ago

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 commented 1 year ago

@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.