tim-hellhake / xiaomi-temperature-humidity-sensor-adapter

Mozilla Public License 2.0
1 stars 2 forks source link

0.0 Temperature and humidity readings even after 24hrs with LYWSD03MMC #8

Closed edster69 closed 3 years ago

edster69 commented 4 years ago

Device connects fine, but no readings are ever shown.

Not sure if the log will help, but here it is:

2020-08-09 09:04:17.363 INFO : Checking for add-on updates... 2020-08-09 09:04:17.930 INFO : Loading add-on: thing-url-adapter 2020-08-09 09:04:18.046 INFO : Loading add-on: zwave-adapter 2020-08-09 09:04:18.050 INFO : Loading add-on: zigbee-adapter 2020-08-09 09:04:18.287 INFO : Fetching add-on https://s3-us-west-2.amazonaws.com/mozilla-gateway-addons/thing-url-adapter-0.4.8.tgz as /tmp/1htY2s/thing-url-adapter.tar.gz 2020-08-09 09:04:19.733 INFO : Expanding add-on /tmp/1htY2s/thing-url-adapter.tar.gz 2020-08-09 09:04:20.091 ERROR : Failed to unload thing-url-adapter properly: TypeError: Cannot read property 'send' of undefined 2020-08-09 09:04:28.152 INFO : zigbee-adapter: Opening database: /home/pi/.mozilla-iot/config/db.sqlite3 2020-08-09 09:04:28.155 INFO : zwave-adapter: Opening database: /home/pi/.mozilla-iot/config/db.sqlite3 2020-08-09 09:04:28.158 INFO : thing-url-adapter: Opening database: /home/pi/.mozilla-iot/config/db.sqlite3 2020-08-09 09:04:36.179 INFO : Loading add-on: thing-url-adapter 2020-08-09 09:04:36.184 INFO : Fetching add-on https://s3-us-west-2.amazonaws.com/mozilla-gateway-addons/zigbee-adapter-0.11.11-linux-arm-v10.tgz as /tmp/6B7haF/zigbee-adapter.tar.gz 2020-08-09 09:04:37.601 INFO : thing-url-adapter: Loading add-on thing-url-adapter from /home/pi/.mozilla-iot/addons/thing-url-adapter 2020-08-09 09:04:37.615 INFO : zigbee-adapter: Loading add-on zigbee-adapter from /home/pi/.mozilla-iot/addons/zigbee-adapter 2020-08-09 09:04:37.631 INFO : zwave-adapter: Loading add-on zwave-adapter from /home/pi/.mozilla-iot/addons/zwave-adapter 2020-08-09 09:04:38.871 INFO : Expanding add-on /tmp/6B7haF/zigbee-adapter.tar.gz 2020-08-09 09:04:39.806 INFO : thing-url-adapter: Opening database: /home/pi/.mozilla-iot/config/db.sqlite3 2020-08-09 09:04:40.712 INFO : thing-url-adapter: Loading add-on thing-url-adapter from /home/pi/.mozilla-iot/addons/thing-url-adapter 2020-08-09 09:04:42.317 INFO : zigbee-adapter: DEBUG config = '' 2020-08-09 09:04:42.416 INFO : thing-url-adapter: Starting mDNS discovery 2020-08-09 09:04:42.428 INFO : zwave-adapter: DEBUG config = '' 2020-08-09 09:04:42.605 INFO : zwave-adapter: Closing database 2020-08-09 09:04:42.804 INFO : zigbee-adapter: Serial ports that were found: 2020-08-09 09:04:43.078 INFO : zigbee-adapter: Serial Device found @ /dev/ttyAMA0 2020-08-09 09:04:43.081 INFO : zigbee-adapter: Serial Device found @ /dev/ttyS0 2020-08-09 09:04:43.086 ERROR : zigbee-adapter: Failed to start add-on zigbee-adapter: No Zigbee dongle found 2020-08-09 09:04:43.179 ERROR : zwave-adapter: Failed to start add-on zwave-adapter: Unable to find ZWave adapter 2020-08-09 09:04:44.387 INFO : thing-url-adapter: Starting mDNS discovery 2020-08-09 09:04:53.947 INFO : Loading add-on: zigbee-adapter 2020-08-09 09:04:53.953 INFO : Fetching add-on https://s3-us-west-2.amazonaws.com/mozilla-gateway-addons/zwave-adapter-0.10.7-linux-arm-v10.tgz as /tmp/MfItRM/zwave-adapter.tar.gz 2020-08-09 09:04:55.794 INFO : zigbee-adapter: Opening database: /home/pi/.mozilla-iot/config/db.sqlite3 2020-08-09 09:04:56.715 INFO : zigbee-adapter: Loading add-on zigbee-adapter from /home/pi/.mozilla-iot/addons/zigbee-adapter 2020-08-09 09:04:59.033 INFO : zigbee-adapter: DEBUG config = '' 2020-08-09 09:04:59.638 INFO : Expanding add-on /tmp/MfItRM/zwave-adapter.tar.gz 2020-08-09 09:04:59.644 INFO : zigbee-adapter: Serial ports that were found: 2020-08-09 09:04:59.646 INFO : zigbee-adapter: Serial Device found @ /dev/ttyAMA0 2020-08-09 09:04:59.647 INFO : zigbee-adapter: Serial Device found @ /dev/ttyS0 2020-08-09 09:04:59.654 ERROR : zigbee-adapter: Failed to start add-on zigbee-adapter: No Zigbee dongle found 2020-08-09 09:05:31.501 INFO : Loading add-on: zwave-adapter 2020-08-09 09:05:31.505 INFO : Finished updating add-ons 2020-08-09 09:05:33.628 INFO : zwave-adapter: Opening database: /home/pi/.mozilla-iot/config/db.sqlite3 2020-08-09 09:05:34.408 INFO : zwave-adapter: Loading add-on zwave-adapter from /home/pi/.mozilla-iot/addons/zwave-adapter 2020-08-09 09:05:36.460 INFO : zwave-adapter: DEBUG config = '' 2020-08-09 09:05:36.726 INFO : zwave-adapter: Closing database 2020-08-09 09:05:37.095 ERROR : zwave-adapter: Failed to start add-on zwave-adapter: Unable to find ZWave adapter 2020-08-09 09:05:47.578 INFO : Starting registration 2020-08-09 09:05:51.448 INFO : Sent subscription to registration server 2020-08-09 09:05:55.064 INFO : Set email on server. 2020-08-09 09:06:07.221 INFO : Set DNS token on registration server 2020-08-09 09:06:22.420 INFO : Received certificate from Let's Encrypt 2020-08-09 09:06:22.424 INFO : Wrote certificates to file system 2020-08-09 09:06:22.426 INFO : Registration success! 2020-08-09 09:06:22.449 INFO : HTTPS server listening on port 4443 2020-08-09 09:06:22.451 INFO : Redirector listening on port 8080 2020-08-09 09:06:24.169 INFO : PageKite connected! 2020-08-09 09:06:24.178 INFO : Starting certificate renewal. 2020-08-09 09:06:24.199 INFO : Certificate not yet due for renewal. 2020-08-09 09:08:18.674 INFO : Tunnel domain found. Tunnel name is: xxxxxxxxxxx and tunnel domain is: mozilla-iot.org 2020-08-09 09:08:18.678 INFO : Tunnel name is set to: https://xxxxxxxxxxxx.mozilla-iot.org 2020-08-09 09:08:18.681 INFO : Local mDNS Service Domain Name is: gateway 2020-08-09 09:09:14.601 INFO : Opened a new things socket 2020-08-09 09:09:14.643 INFO : About to call startPairing on ThingURLAdapter 2020-08-09 09:10:14.648 INFO : Pairing timeout 2020-08-09 09:10:14.656 INFO : thing-url-adapter: Adapter: ThingURLAdapter id thing-url-adapter pairing cancelled 2020-08-09 09:24:20.022 INFO : Fetching add-on https://s3-us-west-2.amazonaws.com/mozilla-gateway-addons/xiaomi-temperature-humidity-sensor-adapter-0.1.7-linux-arm-v10.tgz as /tmp/j2PSdN/xiaomi-temperature-humidity-sensor-adapter.tar.gz 2020-08-09 09:24:22.378 INFO : Expanding add-on /tmp/j2PSdN/xiaomi-temperature-humidity-sensor-adapter.tar.gz 2020-08-09 09:24:31.349 INFO : Loading add-on: xiaomi-temperature-humidity-sensor-adapter 2020-08-09 09:24:33.133 INFO : xiaomi-temperature-humidity-sensor-adapter: Opening database: /home/pi/.mozilla-iot/config/db.sqlite3 2020-08-09 09:24:33.916 INFO : xiaomi-temperature-humidity-sensor-adapter: Loading add-on xiaomi-temperature-humidity-sensor-adapter from /home/pi/.mozilla-iot/addons/xiaomi-temperature-humidity-sensor-adapter 2020-08-09 09:24:36.091 INFO : xiaomi-temperature-humidity-sensor-adapter: Noble adapter is poweredOn 2020-08-09 09:24:36.093 INFO : xiaomi-temperature-humidity-sensor-adapter: Start scanning for devices 2020-08-09 09:24:37.126 INFO : xiaomi-temperature-humidity-sensor-adapter: Detected new Temperature Humidity Sensor with id a4c138fda00a 2020-08-09 09:24:58.304 INFO : Opened a new things socket 2020-08-09 09:24:58.311 INFO : About to call startPairing on ThingURLAdapter 2020-08-09 09:24:58.314 INFO : About to call startPairing on TemperatureHumiditySensorAdapter 2020-08-09 09:24:58.324 INFO : xiaomi-temperature-humidity-sensor-adapter: Start pairing 2020-08-09 09:25:05.657 INFO : Successfully created new thing Xiaomi Bluetooth Temperature and Humidity Sensor 2020-08-09 09:25:07.845 INFO : thing-url-adapter: Adapter: ThingURLAdapter id thing-url-adapter pairing cancelled 2020-08-09 09:25:07.848 INFO : xiaomi-temperature-humidity-sensor-adapter: Cancel pairing 2020-08-09 19:53:58.777 INFO : Opening database: /home/pi/.mozilla-iot/log/logs.sqlite3 2020-08-09 19:54:03.063 INFO : wifi-setup: waitForWiFi: networks exist: [ 'xxxxxxxxx' ] 2020-08-09 19:54:03.145 INFO : wifi-setup: waitForWifi: No wifi connection on attempt 1 2020-08-09 19:54:03.149 INFO : DNS config is: gateway 2020-08-09 19:54:03.152 INFO : Service Discovery: changing profile - local domain is now: gateway 2020-08-09 19:54:05.798 INFO : Service Discovery: state changed to: true 2020-08-09 19:54:06.249 INFO : wifi-setup: waitForWifi: No wifi connection on attempt 2 2020-08-09 19:54:09.339 INFO : wifi-setup: waitForWifi: connection found 2020-08-09 19:54:12.423 INFO : wifi-setup: waitForWifi: connection found 2020-08-09 19:54:15.508 INFO : wifi-setup: waitForWifi: connection found 2020-08-09 19:54:18.590 INFO : wifi-setup: waitForWifi: connection found 2020-08-09 19:54:18.618 INFO : HTTPS server listening on port 4443 2020-08-09 19:54:18.621 INFO : Redirector listening on port 8080 2020-08-09 19:54:27.849 INFO : Loading add-on: thing-url-adapter 2020-08-09 19:54:27.855 INFO : Loading add-on: xiaomi-temperature-humidity-sensor-adapter 2020-08-09 19:54:27.859 INFO : Loading add-on: zigbee-adapter 2020-08-09 19:54:27.862 INFO : Loading add-on: zwave-adapter 2020-08-09 19:54:29.468 INFO : Checking for add-on updates... 2020-08-09 19:54:30.112 ERROR : Failed to parse add-on list: { FetchError: request to https://api.mozilla-iot.org:8443/addons?arch=linux-arm&version=0.12.0&node=64&python=2.7%2C3.7 failed, reason: connect ENETUNREACH 198.18.1.1:8443 at ClientRequest. (/home/pi/mozilla-iot/gateway/node_modules/node-fetch/lib/index.js:1455:11) at ClientRequest.emit (events.js:198:13) at TLSSocket.socketErrorListener (_http_client.js:401:9) at TLSSocket.emit (events.js:198:13) at emitErrorNT (internal/streams/destroy.js:91:8) at emitErrorAndCloseNT (internal/streams/destroy.js:59:3) at process._tickCallback (internal/process/next_tick.js:63:19) message: 'request to https://api.mozilla-iot.org:8443/addons?arch=linux-arm&version=0.12.0&node=64&python=2.7%2C3.7 failed, reason: connect ENETUNREACH 198.18.1.1:8443', type: 'system', errno: 'ENETUNREACH', code: 'ENETUNREACH' } 2020-08-09 19:54:30.639 INFO : thing-url-adapter: Opening database: /home/pi/.mozilla-iot/config/db.sqlite3 2020-08-09 19:54:30.733 INFO : zigbee-adapter: Opening database: /home/pi/.mozilla-iot/config/db.sqlite3 2020-08-09 19:54:30.779 INFO : zwave-adapter: Opening database: /home/pi/.mozilla-iot/config/db.sqlite3 2020-08-09 19:54:31.039 INFO : xiaomi-temperature-humidity-sensor-adapter: Opening database: /home/pi/.mozilla-iot/config/db.sqlite3 2020-08-09 19:54:32.008 INFO : zigbee-adapter: Loading add-on zigbee-adapter from /home/pi/.mozilla-iot/addons/zigbee-adapter 2020-08-09 19:54:32.024 INFO : thing-url-adapter: Loading add-on thing-url-adapter from /home/pi/.mozilla-iot/addons/thing-url-adapter 2020-08-09 19:54:32.048 INFO : zwave-adapter: Loading add-on zwave-adapter from /home/pi/.mozilla-iot/addons/zwave-adapter 2020-08-09 19:54:32.164 INFO : xiaomi-temperature-humidity-sensor-adapter: Loading add-on xiaomi-temperature-humidity-sensor-adapter from /home/pi/.mozilla-iot/addons/xiaomi-temperature-humidity-sensor-adapter 2020-08-09 19:54:32.431 INFO : zwave-adapter: DEBUG config = '' 2020-08-09 19:54:32.434 INFO : zigbee-adapter: DEBUG config = '' 2020-08-09 19:54:32.444 INFO : thing-url-adapter: Starting mDNS discovery 2020-08-09 19:54:32.628 INFO : xiaomi-temperature-humidity-sensor-adapter: Noble adapter is poweredOn 2020-08-09 19:54:32.631 INFO : xiaomi-temperature-humidity-sensor-adapter: Start scanning for devices 2020-08-09 19:54:33.223 INFO : zigbee-adapter: Serial ports that were found: 2020-08-09 19:54:33.331 INFO : zwave-adapter: Closing database 2020-08-09 19:54:33.428 INFO : zigbee-adapter: Serial Device found @ /dev/ttyAMA0 2020-08-09 19:54:33.431 INFO : zigbee-adapter: Serial Device found @ /dev/ttyS0 2020-08-09 19:54:33.434 ERROR : zigbee-adapter: Failed to start add-on zigbee-adapter: No Zigbee dongle found 2020-08-09 19:54:33.731 ERROR : zwave-adapter: Failed to start add-on zwave-adapter: Unable to find ZWave adapter 2020-08-09 19:54:34.069 INFO : xiaomi-temperature-humidity-sensor-adapter: Detected new Temperature Humidity Sensor with id a4c138fda00a 2020-08-09 19:55:10.455 INFO : PageKite connected! 2020-08-09 19:55:10.461 INFO : Starting certificate renewal. 2020-08-09 19:55:10.497 INFO : Certificate not yet due for renewal. 2020-08-09 22:25:46.322 INFO : Tunnel domain found. Tunnel name is: xxxxxxxxxxx and tunnel domain is: mozilla-iot.org 2020-08-09 22:25:46.327 INFO : Tunnel name is set to: https://xxxxxxxxxxxx.mozilla-iot.org 2020-08-09 22:25:46.329 INFO : Local mDNS Service Domain Name is: gateway 2020-08-09 22:27:28.041 INFO : xiaomi-temperature-humidity-sensor-adapter: Detected new Temperature Humidity Sensor with id a4c138fc598d 2020-08-09 22:27:34.200 INFO : Opened a new things socket 2020-08-09 22:27:34.270 INFO : About to call startPairing on ThingURLAdapter 2020-08-09 22:27:34.273 INFO : About to call startPairing on TemperatureHumiditySensorAdapter 2020-08-09 22:27:34.279 INFO : xiaomi-temperature-humidity-sensor-adapter: Start pairing 2020-08-09 22:27:44.525 INFO : Successfully created new thing Office: Xiaomi Bluetooth Temperature and Humidity Sensor 2020-08-09 22:27:46.167 INFO : thing-url-adapter: Adapter: ThingURLAdapter id thing-url-adapter pairing cancelled 2020-08-09 22:27:46.169 INFO : xiaomi-temperature-humidity-sensor-adapter: Cancel pairing

edster69 commented 4 years ago

Looks like this could be down to the LYWSD03MMC encrypting its advertisements.

https://github.com/custom-components/sensor.mitemp_bt#encryptors

tim-hellhake commented 4 years ago

The LYWSD03MMC is currently not supported (#5). It seems to be possible to fetch the data via GATT, but unfortunately, I have no device to test it. I could try to implement it, but you would need to test it for me.

edster69 commented 4 years ago

The LYWSD03MMC is currently not supported (#5). It seems to be possible to fetch the data via GATT, but unfortunately, I have no device to test it. I could try to implement it, but you would need to test it for me.

Ah, sorry, I missed that issue.

I'm more than happy to test for you. Currently trying to get Home Assistant to work, but I do prefer the WebThings Gateway's simplicity.

tim-hellhake commented 4 years ago

@edster69 It's not perfect but it should work now.

edster69 commented 4 years ago

@edster69 It's not perfect but it should work now.

Wonderful, I'll give it a try over the next few days. Thank you.

edster69 commented 3 years ago

Ah Tim, I should have responded earlier.

Your addon does indeed now work very well, but I have found that the batteries in the LYWSD03MMC (I have eight) have drained within two weeks.

I assumed that the ones provided in the box were substandard, so I ordered some more of a reputable brand, but the same is true.

I am now running somes devices without them being connected to the WebThings Gateway to see if their battery life will last any longer, and reach the quoted one year life.

tim-hellhake commented 3 years ago

@edster69 The problem is the broadcasted values are encrypted now. Therefore the adapter has to establish a connection to the sensors to retrieve the values. This more energy-intensive than just broadcasting the data. You reduce the effect by increasing the polling interval. I tried to extract the encryption keys from my sensor so I can implement the broadcast decryption but I had no luck so far.

edster69 commented 3 years ago

Hi Tim,

Did you use the modified Xiaomi home android apk to extract the bind key? I had to do that to get it to work with Home Assistant.

I have the apk if you need it.

tim-hellhake commented 3 years ago

Did you use the modified Xiaomi home android apk to extract the bind key?

No, I used a tool that should retrieve the key via bluetooth.

I had to do that to get it to work with Home Assistant.

I'm not familiar with Home Assistant. Which plugin is the right one for the sensor?

I have the apk if you need it.

That would be very helpful.

edster69 commented 3 years ago

Here's the module to get the LYWSD03MMC sensor working with Home Assistant:

https://github.com/custom-components/ble_monitor

The mod to get the bind key is made by someone called vevsvevs and can be found at the bottom of this page, along with a link to older versions.

https://www.kapiba.ru/2017/11/mi-home.html

To use, install the apk, create folder /your_internal_storage/vevs/logs/ and pair your BLE device using the app and the file pairings.txt with the corresponding data will be created.

edster69 commented 3 years ago

Hi Tim, did you have any success with that Android app to retrieve the bind key?

edster69 commented 2 years ago

@edster69 The problem is the broadcasted values are encrypted now. Therefore the adapter has to establish a connection to the sensors to retrieve the values. This more energy-intensive than just broadcasting the data. You reduce the effect by increasing the polling interval. I tried to extract the encryption keys from my sensor so I can implement the broadcast decryption but I had no luck so far.

I've found out that there are now custom firmwares for the the LYWSD03MMC that remove the encryption. It's very easy to install them.

https://github.com/atc1441/ATC_MiThermometer