hbblebc / homebridge-bed-control

Homebridge plugin to control compatible smart beds
Apache License 2.0
7 stars 2 forks source link

Occupancy Sensor Null error and crash #13

Open BlurrySasquatch opened 1 month ago

BlurrySasquatch commented 1 month ago

Describe The Bug: The plugin starts but almost immediately throws these errors

[7/7/2024, 10:25:22 AM] [homebridge-bed-control] This plugin threw an error from the characteristic 'Occupancy Detected': Unhandled error thrown inside read handler for characteristic: Cannot read properties of null (reading 'isInBed'). See https://homebridge.io/w/JtMGR for more info.
[7/7/2024, 10:25:22 AM] [homebridge-bed-control] This plugin threw an error from the characteristic 'Occupancy Detected': Unhandled error thrown inside read handler for characteristic: Cannot read properties of null (reading 'isInBed'). See https://homebridge.io/w/JtMGR for more info.
[7/7/2024, 10:25:23 AM] [homebridge-bed-control] This plugin generated a warning from the characteristic 'Brightness': characteristic was supplied illegal value: number 0 exceeded minimum of 5. See https://homebridge.io/w/JtMGR for more info.

This then leads to the following error


[7/7/2024, 10:25:42 AM] TypeError: Cannot read properties of null (reading 'alertDetailedMessage')
    at file:///usr/local/lib/node_modules/homebridge-bed-control/src/platform.ts:363:35
    at Array.forEach (<anonymous>)
    at file:///usr/local/lib/node_modules/homebridge-bed-control/src/platform.ts:362:67
    at Array.forEach (<anonymous>)
    at Timeout._onTimeout (file:///usr/local/lib/node_modules/homebridge-bed-control/src/platform.ts:356:18)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
[7/7/2024, 10:25:42 AM] Got SIGTERM, shutting down Homebridge... 

Then homebridge restarts To Reproduce:

Enable the bed control plugin

Expected behavior: Occupancy sensor to work without causing a crash loop

Logs:

[7/7/2024, 10:34:28 AM] [homebridge-bed-control] This plugin threw an error from the characteristic 'Occupancy Detected': Unhandled error thrown inside read handler for characteristic: Cannot read properties of null (reading 'isInBed'). See https://homebridge.io/w/JtMGR for more info.
[7/7/2024, 10:34:28 AM] [homebridge-bed-control] This plugin threw an error from the characteristic 'Occupancy Detected': Unhandled error thrown inside read handler for characteristic: Cannot read properties of null (reading 'isInBed'). See https://homebridge.io/w/JtMGR for more info.
[7/7/2024, 10:34:29 AM] [homebridge-bed-control] This plugin generated a warning from the characteristic 'Brightness': characteristic was supplied illegal value: number 0 exceeded minimum of 5. See https://homebridge.io/w/JtMGR for more info.
[7/7/2024, 10:38:07 AM] [homebridge-bed-control] This plugin threw an error from the characteristic 'Occupancy Detected': Unhandled error thrown inside read handler for characteristic: Cannot read properties of null (reading 'isInBed'). See https://homebridge.io/w/JtMGR for more info.
[7/7/2024, 10:38:07 AM] [homebridge-bed-control] This plugin threw an error from the characteristic 'Occupancy Detected': Unhandled error thrown inside read handler for characteristic: Cannot read properties of null (reading 'isInBed'). See https://homebridge.io/w/JtMGR for more info.
[7/7/2024, 10:38:08 AM] [homebridge-bed-control] This plugin generated a warning from the characteristic 'Brightness': characteristic was supplied illegal value: number 0 exceeded minimum of 5. See https://homebridge.io/w/JtMGR for more info

Plugin Config:


{
    "bridge": {
        "name": "Homebridge 32AA",
        "username": "XXX",
        "port": 51665,
        "pin": "XXX",
        "advertiser": "bonjour-hap"
    },
    "accessories": [],
    "platforms": [
        {
            "name": "Config",
            "port": 8581,
            "platform": "config"
        },
        {
            "name": "ConnectLife AC",
            "deviceNickName": "Basement Office AC",
            "loginID": "x",
            "password": "x",
            "debugMode": 1,
            "platform": "ConnectLifeAcPlugin"
        },
        {
            "country": "US",
            "language": "en-US",
            "auth_mode": "token",
            "refresh_token": "",
            "username": "",
            "password": "",
            "platform": "LGThinQ"
        },
        {
            "devices": [
                {
                    "type": "Dehumidifier",
                    "name": "Midea Cube Dehumidifier",
                    "id": 151732604817950,
                    "advanced_options": {
                        "token": "",
                        "key": ""
                    }
                },
                {
                    "type": "Air Conditioner",
                    "name": "Midea Portable AC",
                    "id":,
                    "advanced_options": {
                        "token": "",
                        "key": ""
                    }
                }
            ],
            "platform": "midea-platform"
        },
        {
            "name": "Levoit Air Purifiers",
            "email": "",
            "password": "--",
            "experimentalFeatures": [
                "DeviceDisplay"
            ],
            "platform": "LevoitAirPurifiers"
        },
        {
            "bedPlatform": "sleep number",
            "email": "myemail@private.com",
            "password": "NotMyRealPassword",
            "updateInterval": 60,
            "delay": 2,
            "ignore": [
                "-9223372025969836071.leftSide.footwarming",
                "-9223372025969836071.rightSide.footwarming",
                "-9223372025969836071.rightSide.footControl",
                "-9223372025969836071.rightSide.headControl",
                "-9223372025969836071.anySide.outlet",
                "-9223372025969836071.leftSide.outlet",
                "-9223372025969836071.rightSide.outlet"
            ],
            "platform": "BedControl"
        }
    ],
    "disabledPlugins": []
}

Screenshots:

Environment:

BlurrySasquatch commented 1 month ago

Some more information after troubleshooting again.

We have two SleepNumber beds:

C2 Twin 360 I7 Queen 360 FlexFit 2

It seems that the error is only thrown for the C2 Twin. I confirmed the bed is online in Sleep Number app and it is detecting occupancy correctly.

Putting the occupancy sensors from the twin on the ignore list makes the errors go away, but would prefer they worked for all beds

BlurrySasquatch commented 1 month ago

Correction: putting the twin occupancy sensors on the ignore list makes the occupancy sensors errors go away, but the last error still appears and crashes homebridge

hbblebc commented 1 month ago

I haven't worked with a twin bed before, I bet there is some difference in the API since it doesn't have both sides present.

If you feel comfortable in doing so, I would love to see the API requests for controlling the bed. you would need to set up something like Charles proxy on your phone and set it up to do MITM https proxying to get the requests and responses for the *.sleepiq.* domain.