homebridge-eufy-security / plugin

Homebridge plugin to control certain Eufy Security devices
Apache License 2.0
172 stars 23 forks source link

[Bug]: Eufy Mode mapping doesn't fully support Schedule mode #636

Open thepacketgeek opened 1 month ago

thepacketgeek commented 1 month ago

What happened?

Context: In the Eufy app, I typically oscillate between the Home mode when I'm home and Schedule mode when I'm away, which has a schedule for mostly "Away" mode, but I do have a window for "Home" mode so my yard cameras don't trigger an alarm during the time that my gardener visits. (This works well for me because the Eufy schedule mode has been much more reliable than trying to schedule it with HomeKit automations)

In the Eufy mode mappings I have likely what's pretty typical (except for hkAway mode):

hkHome => eufyHome hkAway => eufySchedule hkNight => eufyNight hkOff => eufyDisabled

This causes an issue when setting the Eufy mode via (or even loading the homebridge Accessories page) with this error (more relevant logs and backtrace below):

Error  STATION Homebase3 No matching HomeKit mode found for Eufy mode 0

When Eufy is actually set to schedule (from the app), it's returning a StationCurrentMode of 0 for Away, but this doesn't match the "Schedule" mode (2) that the plugin knows to map to hkAway. I believe the fix is to use StationGuardMode as this is the configured vs. the active mode:

StationAccessory.js

    /**
     * Handle requests to get the current configured value of the 'Security System Target State' characteristic
     */
    handleSecuritySystemTargetStateGet(stateCharacteristic = 'handleSecuritySystemTargetStateGet') {
        try {
            const configuredValue = this.device.getPropertyValue(eufy_security_client_1.PropertyName.StationGuardMode);
            if (configuredValue === -1) {
                throw new Error('Something wrong with this device', configuredValue);
            }
            this.log.info(`GET StationGuardMode: ${configuredValue}`);
            return this.convertEufytoHK(configuredValue);
        }
        catch (error) {
            this.log.error(`${stateCharacteristic}: Wrong return value`, error);
            return false;
        }
    }

This change seems to at least let me load the Accessories page, but I imagine the change from StationCurrentMode -> StationGuardMode will need to be done in more places.

Device Type

Station (Supported)

Plugin Version

v4.3.x (Best Effort)

HomeBridge Version

v1.8.4 (Supported)

NodeJS Version

v20 (Supported)

Operating System

Ubuntu 22.04+ (Supported)

Relevant log output

[10/07/2024, 19:01:29]  [EufySecurity]  INFO    Homebase3 GET StationCurrentMode: 0
[10/07/2024, 19:01:29]  [EufySecurity]  DEBUG    Homebase3 [
  { hk: 0, eufy: 1 },
  { hk: 1, eufy: 2 },
  { hk: 2, eufy: 3 },
  { hk: 3, eufy: 63 }
]
[10/07/2024, 19:01:29]  [EufySecurity]  ERROR   Homebase3 handleSecuritySystemTargetStateGet: Wrong return value

 Error  STATION Homebase3 No matching HomeKit mode found for Eufy mode 0
error stack:
  • StationAccessory.ts StationAccessory.convertEufytoHK
        StationAccessory.ts:290
  • StationAccessory.ts StationAccessory.handleSecuritySystemTargetStateGet
        StationAccessory.ts:316
  • StationAccessory.ts getValue
        StationAccessory.ts:103
  • BaseAccessory.ts    SecuritySystemTargetState.getHandler
        BaseAccessory.ts:154
  • Characteristic.ts   SecuritySystemTargetState.<anonymous>
        Characteristic.ts:2404
  • tslib.js    step
        tslib.js:195
  • tslib.js    Object.next
        tslib.js:176
  • tslib.js
        tslib.js:169
  • 

  • tslib.js    Object.__awaiter
        tslib.js:165

config

{
            "platform": "EufySecurity",
            "name": "EufySecurity",
            ...
            "country": "US",
            "deviceName": "Homebase3",
            "hkHome": 1,
            "hkAway": 2,
            "hkNight": 3,
            "hkOff": 63,
            "_bridge": {
                ...
                "port": 33498
            }
        }
github-actions[bot] commented 1 month ago

Did you check this Common Issues pages ?