OpenWonderLabs / homebridge-switchbot

The Homebridge SwitchBot plugin allows you to access your SwitchBot Device(s) from HomeKit. Homebridge.
https://www.switch-bot.com/
ISC License
229 stars 47 forks source link

Bug: plugin loses humidity values for IO-Sensor during Parsing #980

Open nfoonf opened 1 month ago

nfoonf commented 1 month ago

Describe the Bug

in v3.4.0 the IOSensor support loses values for humidity during parsing. In the debug log, one can see that the values are received but change to undefined during parsing

To Reproduce

install v3.4.0 v3.5.0 puts home bridge into a reboot cycle of death, but the bug is in the code as well as far as I can see

Expected Behavior

get humidity data, obviously

Relevant Log Output

[5/30/2024, 3:13:00 PM] [SwitchBot] [DEBUG] WoIOSensor: Terasse address: d9:30:38:35:20:41, model: w
[5/30/2024, 3:13:00 PM] [SwitchBot] [DEBUG] WoIOSensor: Terasse serviceData: {"model":"w","modelName":"WoIOSensorTH","temperature":{"c":20.8,"f":69.4},"fahrenheit":true,"humidity":57,"battery":100}
{
  model: 'w',
  modelName: 'WoIOSensorTH',
  temperature: { c: 20.8, f: 69.4 },
  fahrenheit: true,
  humidity: 57, <========== DATA IS HERE
  battery: 100
}
{
  model: 'w',
  modelName: 'WoIOSensorTH',
  temperature: { c: 20.8, f: 69.4 },
  fahrenheit: true,
  humidity: 57,
  battery: 100
}
{
  model: 'w',
  modelName: 'WoIOSensorTH',
  temperature: { c: 20.8, f: 69.4 },
  fahrenheit: true,
  humidity: 57,
  battery: 100
}
{
  model: 'w',
  modelName: 'WoIOSensorTH',
  temperature: { c: 20.8, f: 69.4 },
  fahrenheit: true,
  humidity: 57,
  battery: 100
}
{
  model: 'w',
  modelName: 'WoIOSensorTH',
  temperature: { c: 20.8, f: 69.4 },
  fahrenheit: true,
  humidity: 57,
  battery: 100
}
[5/30/2024, 3:13:03 PM] [SwitchBot] [DEBUG] WoIOSensor: Terasse BLEparseStatus
[5/30/2024, 3:13:03 PM] [SwitchBot] [DEBUG] Terasse BatteryLevel: 100, StatusLowBattery: 0
[5/30/2024, 3:13:03 PM] [SwitchBot] [DEBUG] WoIOSensor: Terasse Humidity: undefined% <======= Data is lost
[5/30/2024, 3:13:03 PM] [SwitchBot] [DEBUG] WoIOSensor: Terasse Temperature: 20.8°c
[5/30/2024, 3:13:03 PM] [SwitchBot] [DEBUG] WoIOSensor: Terasse CurrentRelativeHumidity: undefined
[5/30/2024, 3:13:03 PM] [SwitchBot] [DEBUG] WoIOSensor: Terasse updateCharacteristic CurrentTemperature: 20.8
[5/30/2024, 3:13:03 PM] [SwitchBot] [DEBUG] WoIOSensor: Terasse updateCharacteristic BatteryLevel: 100
[5/30/2024, 3:13:03 PM] [SwitchBot] [DEBUG] WoIOSensor: Terasse updateCharacteristic StatusLowBattery: 0
[5/30/2024, 3:13:13 PM] [@switchbot/homebridge-switchbot] This plugin generated a warning from the characteristic 'Current Relative Humidity': characteristic value expected valid finite number and received "undefined" (undefined). See https://homebridge.io/w/JtMGR for more info.
[5/30/2024, 3:13:13 PM] [@switchbot/homebridge-switchbot] This plugin generated a warning from the characteristic 'Current Temperature': characteristic value expected valid finite number and received "undefined" (undefined). See https://homebridge.io/w/JtMGR for more info.
[5/30/2024, 3:13:13 PM] [@switchbot/homebridge-switchbot] This plugin generated a warning from the characteristic 'Current Relative Humidity': characteristic value expected valid finite number and received "undefined" (undefined). See https://homebridge.io/w/JtMGR for more info.
[5/30/2024, 3:13:13 PM] [@switchbot/homebridge-switchbot] This plugin generated a warning from the characteristic 'Current Relative Humidity': characteristic value expected valid finite number and received "undefined" (undefined). See https://homebridge.io/w/JtMGR for more info.
[5/30/2024, 3:13:13 PM] [SwitchBot] [DEBUG] WoIOSensor: Terasse BLERefreshStatus
[5/30/2024, 3:13:13 PM] [SwitchBot] [DEBUG] WoIOSensor: Terasse BLE Address: d9:30:38:35:20:41

Config for homebridge-switchbot

the config can be seen here:

 "name": "SwitchBot",
            "credentials": {
                "token": "dsfsdfgsdfgsdf",
                "secret": "sdfgsdfgsfdg",
                "notice": "Keep your Token & Secret a secret!"
            },
            "options": {
                "devices": [
                {
                        "deviceId": "D93038352041",
                        "configDeviceName": "Terasse",
                        "configDeviceType": "WoIOSensor",
                        "connectionType": "BLE",
                        "scanDuration": 10,
                        "history": false,
                        "refreshRate": 20,
                        "external": true,
                        "logging": "debug"
                    }
                ]

Screenshots

No response

Device and Model

raspberry pi model 4 running docker

Node.js Version

v20.12.2

NPM Version

10.5.0

Homebridge Version

Homebridge v1.8.2 in docker container homebridge/homebridge:2024-05-02

Homebridge Switchbot Plugin Version

3.4.0

Homebridge Config UI X Plugin Version

No response

Operating System

Raspian

nfoonf commented 4 weeks ago

Hi! did I forget any vital information in this bug report or did I miss something?

donavanbecker commented 4 weeks ago

No I just haven't had time to figure it out

donavanbecker commented 1 week ago

@nfoonf Can you try the latest beta?

nfoonf commented 1 week ago

Somehow it got even worse....

[6/23/2024, 11:25:33 AM] [SwitchBot] WoIOSensor: Bad ad: {
  "id": "c13932334890",
  "address": "c1:39:32:33:48:90",
  "rssi": -71,
  "serviceData": {
    "model": "w",
    "modelName": "WoIOSensorTH",
    "modelFriendlyName": "Outdoor Meter",
    "temperature": {
      "c": 24.4,
      "f": 75.9
    },
    "fahrenheit": false,
    "humidity": 51,
    "battery": 89
  }
}
[6/23/2024, 11:25:35 AM] TypeError: Cannot read properties of undefined (reading 'c')
    at IOSensor.BLEparseStatus (file:///homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/iosensor.ts:182:47)
    at file:///homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/iosensor.ts:279:11
[6/23/2024, 11:25:35 AM] Got SIGTERM, shutting down Homebridge...
[6/23/2024, 11:25:35 AM] TypeError: Cannot read properties of undefined (reading 'c')
    at IOSensor.BLEparseStatus (file:///homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/iosensor.ts:182:47)
    at runNextTicks (node:internal/process/task_queues:60:5)
    at listOnTimeout (node:internal/timers:540:9)
    at processTimers (node:internal/timers:514:7)
    at file:///homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/iosensor.ts:279:11
[6/23/2024, 11:25:35 AM] [SwitchBot] MeterPlus: Fritzbox failed to get serviceData, serviceData: [object Object]
[6/23/2024, 11:25:35 AM] TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Timeout'
    |     property '_idlePrev' -> object with constructor 'TimersList'
    --- property '_idleNext' closes the circle
    at JSON.stringify (<anonymous>)
    at MeterPlus.BLERefreshConnection (file:///homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/meterplus.ts:338:90)
    at file:///homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/meterplus.ts:272:22
    at runNextTicks (node:internal/process/task_queues:60:5)
    at listOnTimeout (node:internal/timers:540:9)
    at processTimers (node:internal/timers:514:7)
[6/23/2024, 11:25:35 AM] TypeError: Cannot read properties of undefined (reading 'c')
    at MeterPlus.BLEparseStatus (file:///homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/meterplus.ts:169:47)
    at file:///homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/meterplus.ts:268:11
nfoonf commented 1 week ago

It also does not work again after downgrading to 3.4.0 again. So probably the sensors are broken now?

michaelgroening commented 1 week ago

sorry, different accountname here because of different laptop.

i tested once more with the latest beta

humidity goes through, and the sensors are queried correctly a couple of times but then we get another error:


6/28/2024, 1:49:48 AM] [SwitchBot] MeterPlus: Fritzbox ad: {
  "id": "ea7d00692354",
  "address": "ea:7d:00:69:23:54",
  "rssi": -59,
  "serviceData": {
    "model": "i",
    "modelName": "WoSensorTH",
    "modelfriendlyName": "Meter",
    "temperature": {
      "c": 29.1,
      "f": 84.4
    },
    "fahrenheit": false,
    "humidity": 52,
    "battery": 21
  }
}
[6/28/2024, 1:49:49 AM] [SwitchBot] MeterPlus: Fritzbox failed to get serviceData, serviceData: [object Object]
[6/28/2024, 1:49:49 AM] TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Timeout'
    |     property '_idlePrev' -> object with constructor 'TimersList'
    --- property '_idleNext' closes the circle
    at JSON.stringify (<anonymous>)
    at MeterPlus.BLERefreshConnection (file:///homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/meterplus.ts:365:90)
    at file:///homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/meterplus.ts:297:22
[6/28/2024, 1:49:49 AM] Got SIGTERM, shutting down Homebridge...
donavanbecker commented 1 week ago

v3.5.1 has been released, please install and let me know if this has been resolved.