hannseman / homebridge-mi-hygrothermograph

Homebridge plugin for the Xiaomi Mi Bluetooth Temperature and Humidity Sensor
MIT License
266 stars 52 forks source link

When adding the E-Ink clock / LYWSD02MMC auto discover works fine but via MAC address it does not expose/asks for Bind key #139

Closed saiajin closed 3 years ago

saiajin commented 3 years ago

Expected Behavior

Device easily discovered exposed automatically ADD the MAC address for this device so I can add multiple devices

Current Behavior

Device exposes automatically fine but when adding the MAC address it shows as not responding in Homekit, it appears to need a bind key.

Steps to Reproduce (for bugs)

add mac address

Versions

I AM USING HOOBS: HOOBS Version | 3.3.3 Node Version | 14.15.1

Configuration

    {
        "accessory": "Hygrotermograph",
        "plugin_map": {
            "plugin_name": "homebridge-mi-hygrothermograph",
            "index": 0
        },
        "name": "Temperature & Humidity",
        "temperatureName": "Temperature",
        "humidityName": "Humidity",
        "fakeGatoEnabled": true,
        "timeout": 15,
        "forceDiscovering": false,
        "forceDiscoveringDelay": 2500,
        "disableBatteryLevel": false,
        "lowBattery": 10,
        "temperatureOffset": 0,
        "humidityOffset": 0,
        "updateInterval": 5,
        "address": "E7:2E:00:71:F4:72"
    }

Homebridge Log / Command Output

3/6/2021, 1:49:31 PM [Temperature & Humidity] Error: Sensor data is encrypted. Please configure a bindKey. at Parser.decryptPayload (/home/hoobs/.hoobs/node_modules/homebridge-mi-hygrothermograph/lib/parser.js:163:13) at Parser.parse (/home/hoobs/.hoobs/node_modules/homebridge-mi-hygrothermograph/lib/parser.js:59:12) at Scanner.parseServiceData (/home/hoobs/.hoobs/node_modules/homebridge-mi-hygrothermograph/lib/scanner.js:171:52) at Scanner.onDiscover (/home/hoobs/.hoobs/node_modules/homebridge-mi-hygrothermograph/lib/scanner.js:92:25) at Noble.emit (events.js:315:20) at Noble.onDiscover (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/noble.js:196:10) at NobleBindings.emit (events.js:315:20) at NobleBindings.onDiscover (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:169:10) at Gap.emit (events.js:315:20) at Gap.onHciLeAdvertisingReport (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/hci-socket/gap.js:244:10) at Hci.emit (events.js:315:20) at Hci.processLeAdvertisingReport (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/hci-socket/hci.js:656:12) at Hci.processLeMetaEvent (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/hci-socket/hci.js:612:10) at Hci.onSocketData (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/hci-socket/hci.js:483:12) at BluetoothHciSocket.emit (events.js:315:20)

Is this normal? Do I always need bind keys when adding multiple devices regardless of the model?

saiajin commented 3 years ago

Here is my complete entry when adding 2 of my devices9One with Bind Key) ....which neither work when doing this... I did not clean the mac addresses this time:

{ "accessory": "Hygrotermograph", "plugin_map": { "plugin_name": "homebridge-mi-hygrothermograph", "index": 0 }, "name": "Temperature & Humidity", "temperatureName": "Temperature", "humidityName": "Humidity", "fakeGatoEnabled": true, "timeout": 15, "forceDiscovering": true, "forceDiscoveringDelay": 2500, "disableBatteryLevel": false, "lowBattery": 10, "temperatureOffset": 0, "humidityOffset": 0, "updateInterval": 5, "address": "E7:2E:00:71:F4:72" }, { "accessory": "Hygrotermograph", "plugin_map": { "plugin_name": "homebridge-mi-hygrothermograph", "index": 0 }, "name": "Guest Room Temperature & Humidity", "temperatureName": "Temperature", "humidityName": "Humidity", "fakeGatoEnabled": false, "timeout": 15, "bindKey": "e1423a17b76546d66dbe3a54d98d471e", "forceDiscovering": true, "forceDiscoveringDelay": 2500, "disableBatteryLevel": false, "lowBattery": 10, "temperatureOffset": 0, "humidityOffset": 0, "address": "A4:C1:38:96:9E:56" }

saiajin commented 3 years ago

SOLVED....WELL.... THE KEY WAS...TO LEAVE IT ALONE.... LOL ...after leaving it overnight, the next day everything was working.... Patience is a virtue!

EDIT: Well they worked for couple hours then disconnected after a Homebridge restart......Going to see if they come back..darnit it was long road to get here...I thought I made it!! it appears the 2 with encryption keep disconnecting......is this a result of the BT range of the RPI? I have a 3B+..does the RPI 4 have better BT range? or is there a way to extend it?

hannseman commented 3 years ago

This could be caused by bad range, can you try and place one of them next to the RPI for a day or so and see if it's more stable?

Edit: If this is caused by range you can experiment with bluetooth dongles or try to upgrade to a RPI 4. I have one sensor which is not behaving well because of being out-of-range, I've tweaked timeout to 2 hours (i.e wait 2 hours without any data before setting it as unresponsive).

saiajin commented 3 years ago

@hannseman

Ok..So I'm seeing something new in the logs:

3/7/2021, 7:28:18 PM noble warning: adapter state unauthorized, please run as root or with sudo 3/7/2021, 7:28:18 PM or see README for information on running without root/sudo: 3/7/2021, 7:28:18 PM https://github.com/sandeepmistry/noble#running-on-linux 3/7/2021, 7:28:18 PM [Temperature & Humidity] Stop scanning. (unauthorized) 3/7/2021, 7:28:18 PM [Guest Room Temperature & Humidity] Stop scanning. (unauthorized) 3/7/2021, 7:28:18 PM [Kitchen Temperature & Humidity] Stop scanning. (unauthorized)

saiajin commented 3 years ago

Note: I just installed the Govee BT Thermometer plugin which also uses Noble.. did I cause a conflict?

3/7/2021, 7:28:18 PM at Noble.scan (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/noble.js:107:21) 3/7/2021, 7:28:18 PM at Noble.startScanning (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/noble.js:136:10) 3/7/2021, 7:28:18 PM at /home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/noble.js:142:44 3/7/2021, 7:28:18 PM at internal/util.js:297:30 3/7/2021, 7:28:18 PM at new Promise () 3/7/2021, 7:28:18 PM at internal/util.js:296:12 3/7/2021, 7:28:18 PM at Noble.startScanningAsync (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/noble.js:142:99) 3/7/2021, 7:28:18 PM at Object.exports.startDiscovery (/home/hoobs/.hoobs/node_modules/govee-bt-client/dist/index.js:83:27) 3/7/2021, 7:28:18 PM at GoveeHomebridgePlatform.discoverDevices (/home/hoobs/.hoobs/node_modules/homebridge-plugin-govee/src/platform.ts:66:5) 3/7/2021, 7:28:18 PM at HomebridgeAPI. (/home/hoobs/.hoobs/node_modules/homebridge-plugin-govee/src/platform.ts:36:12) 3/7/2021, 7:28:18 PM at HomebridgeAPI.emit (events.js:327:22) 3/7/2021, 7:28:18 PM at HomebridgeAPI.signalFinished (/usr/local/lib/node_modules/@hoobs/hoobs/node_modules/homebridge/src/api.ts:275:10) 3/7/2021, 7:28:18 PM at Server.start (/usr/local/lib/node_modules/@hoobs/hoobs/bridge/server.js:161:18) 3/7/2021, 7:28:18 PM at /usr/local/lib/node_modules/@hoobs/hoobs/bridge/cli.js:94:16 3/7/2021, 7:28:18 PM at processTicksAndRejections (internal/process/task_queues.js:93:5) 3/7/2021, 7:28:18 PM (Use node --trace-warnings ... to show where the warning was created) 3/7/2021, 7:28:18 PM (node:4073) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) 3/7/2021, 7:28:18 PM (node:4073) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

saiajin commented 3 years ago

I removed the Govee plugin to isolate the problem and I'm no longer getting the Unauthorized message.. but no response from all 3 sensors... there is at least one sensor within 10 feet of the RPI... i am going to try putting them next to it...

PS: If I add a BT Dongle do I need to disable on board BT? Are you aware of the method? ( I'm on Hoobs)

hannseman commented 3 years ago

Regarding the unauthorized error you’re seeing in the logs. You’ll need to give the node binary access to Bluetooth. This is described in the readme:

sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)
saiajin commented 3 years ago

Hello! So Typed that into terminal and everything works now...THANKYOU! however my logs are CONSTANTLY running.... I could barely copy what it is spitting out... I think its solely the Govee plugin..but let me know if you can help!

hannseman commented 3 years ago

Sweet! Regarding the logs, make sure that you're not running homebridge with the debug flag -D or the DEBUG=1 environment variable. If that doesn't help you'll need to reach out to the Govee plugin.

saiajin commented 3 years ago

Hi! thanks for the reply... I did reach out to the Govee Dev...still waiting for a response.......I am on Hoobs and I did not enable debug mode....as far as I know... What I see in the logs is:

To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strictmight be the fix but I dont know how to do that.

here is some of the logs I was able to grab:

3/8/2021, 8:24:24 PM at Hci.emit (events.js:315:20) 3/8/2021, 8:24:24 PM at Hci.processLeAdvertisingReport (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/hci-socket/hci.js:656:12) 3/8/2021, 8:24:24 PM at Hci.processLeMetaEvent (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/hci-socket/hci.js:612:10) 3/8/2021, 8:24:24 PM at Hci.onSocketData (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/hci-socket/hci.js:483:12) 3/8/2021, 8:24:24 PM at BluetoothHciSocket.emit (events.js:315:20) 3/8/2021, 8:24:24 PM (node:24541) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 817) 3/8/2021, 8:24:24 PM (node:24541) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined 3/8/2021, 8:24:24 PM at Hash.update (internal/crypto/hash.js:84:11) 3/8/2021, 8:24:24 PM at Object.generate (/usr/local/lib/node_modules/@hoobs/hoobs/node_modules/hap-nodejs/src/lib/util/uuid.ts:11:11) 3/8/2021, 8:24:24 PM at /home/hoobs/.hoobs/node_modules/homebridge-plugin-govee/src/platform.ts:80:38

then it shut down my Hoobs:

3/9/2021, 12:38:24 AM Error: Client network socket disconnected before secure TLS connection was established at connResetException (internal/errors.js:607:14) at TLSSocket.onConnectEnd (_tls_wrap.js:1544:19) at TLSSocket.emit (events.js:327:22) at endReadableNT (internal/streams/readable.js:1327:12) at processTicksAndRejections (internal/process/task_queues.js:80:21) 3/9/2021, 12:38:33 AM ERROR: uncaughtException: Client network socket disconnected before secure TLS connection was established 3/9/2021, 12:38:33 AM Error: Client network socket disconnected before secure TLS connection was established 3/9/2021, 12:38:33 AM at connResetException (internal/errors.js:607:14) 3/9/2021, 12:38:33 AM at TLSSocket.onConnectEnd (_tls_wrap.js:1544:19) 3/9/2021, 12:38:33 AM at TLSSocket.emit (events.js:327:22) 3/9/2021, 12:38:33 AM at endReadableNT (internal/streams/readable.js:1327:12) 3/9/2021, 12:38:33 AM at processTicksAndRejections (internal/process/task_queues.js:80:21) 3/9/2021, 12:38:43 AM [Hue] heartbeat 14661, drift 492067 3/9/2021, 12:38:45 AM (node:25002) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined 3/9/2021, 12:38:45 AM at Hash.update (internal/crypto/hash.js:84:11) 3/9/2021, 12:38:45 AM at Object.generate (/usr/local/lib/node_modules/@hoobs/hoobs/node_modules/hap-nodejs/src/lib/util/uuid.ts:11:11) 3/9/2021, 12:38:45 AM at /home/hoobs/.hoobs/node_modules/homebridge-plugin-govee/src/platform.ts:80:38 3/9/2021, 12:38:45 AM at Noble. (/home/hoobs/.hoobs/node_modules/govee-bt-client/dist/index.js:59:9) 3/9/2021, 12:38:45 AM at Noble.emit (events.js:327:22) 3/9/2021, 12:38:45 AM at Noble.onDiscover (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/noble.js:196:10) 3/9/2021, 12:38:45 AM at NobleBindings.emit (events.js:315:20) 3/9/2021, 12:38:45 AM at NobleBindings.onDiscover (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:169:10) 3/9/2021, 12:38:45 AM at Gap.emit (events.js:315:20) 3/9/2021, 12:38:45 AM at Gap.onHciLeAdvertisingReport (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/hci-socket/gap.js:244:10) 3/9/2021, 12:38:45 AM at Hci.emit (events.js:315:20) 3/9/2021, 12:38:45 AM at Hci.processLeAdvertisingReport (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/hci-socket/hci.js:656:12) 3/9/2021, 12:38:45 AM at Hci.processLeMetaEvent (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/hci-socket/hci.js:612:10) 3/9/2021, 12:38:45 AM at Hci.onSocketData (/home/hoobs/.hoobs/node_modules/@abandonware/noble/lib/hci-socket/hci.js:483:12) 3/9/2021, 12:38:45 AM at BluetoothHciSocket.emit (events.js:315:20) 3/9/2021, 12:38:45 AM (node:25002) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 363519)

hannseman commented 3 years ago

Yes looks like some issue in homebridge-plugin-govee. You should know that the bluetooth library noble is known to behave weird when multiple plugins use it.

saiajin commented 3 years ago

ugh... thats not good..... can U tell me how to: "use the CLI flag --unhandled-rejections=strict" ? I want to try it but I don't know how...

hannseman commented 3 years ago

You can set an environment variable: export NODE_OPTIONS="--unhandled-rejections=strict"

saiajin commented 3 years ago

You can set an environment variable: export NODE_OPTIONS="--unhandled-rejections=strict"

would I get any response after inputting this in terminal... didn't seem to do anything?

saiajin commented 3 years ago

Yes looks like some issue in homebridge-plugin-govee. You should know that the bluetooth library noble is known to behave weird when multiple plugins use it.

would running another instance of Homebridge/hoobs solve this? although I suspect the Govee plugin is just funky..

codyc1515 commented 3 years ago

There's not really a fix. I just tried using the child bridge solution to get around the BLE limitation and it did not work. Sorry :(