Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix KeyError: 'last_triggered' for binary_sensor #1342

Closed
tzachi-dar opened this issue Feb 11, 2024 · 1 comment
Closed

Fix KeyError: 'last_triggered' for binary_sensor #1342

tzachi-dar opened this issue Feb 11, 2024 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@tzachi-dar
Copy link

tzachi-dar commented Feb 11, 2024

Thanks for writing this plugin!

I was able to run the plugin well for a couple of days. Then communication was lost (that is I did not get notifications on alarms).
Restarting HA seems to solve the issue.

Looking at the log I can see the following exception.
Is this a known thing? Anything I can do to help debugging the issue.

^[[33m2024-02-10 17:25:59.939 WARNING (SyncWorker_3) [homeassistant.loader] We found a custom integration sonoff which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant^[[0m
^[[33m2024-02-10 17:25:59.941 WARNING (SyncWorker_3) [homeassistant.loader] We found a custom integration hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant^[[0m
^[[31m2024-02-10 17:26:19.067 ERROR (MainThread) [homeassistant.components.binary_sensor] Error adding entities for domain binary_sensor with platform sonoff
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 752, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1281, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/sonoff/binary_sensor.py", line 118, in async_added_to_hass
    ts = restore.attributes[ATTR_LAST_TRIGGERED]
         ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
KeyError: 'last_triggered'^[[0m
^[[31m2024-02-10 17:26:19.087 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 752, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1281, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/sonoff/binary_sensor.py", line 118, in async_added_to_hass
    ts = restore.attributes[ATTR_LAST_TRIGGERED]
         ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
KeyError: 'last_triggered'^[[0m
^[[33m2024-02-10 17:26:23.361 WARNING (MainThread) [zigpy.application] Zigbee channel 15 utilization is 87.06%!^[[0m
^[[33m2024-02-10 17:26:23.361 WARNING (MainThread) [zigpy.application] If you are having problems joining new devices, are missing sensor updates, or have issues keeping devices joined, ensure your coordinator is away from interference sources such as USB 3.0 devices, SSDs, WiFi routers, etc.^[[0m
^[[33m2024-02-10 20:45:05.144 WARNING (Thread-7) [pychromecast.socket_client] [yes(192.168.4.105):8009] Heartbeat timeout, resetting connection^[[0m
^[[3
{
  "home_assistant": {
    "installation_type": "Home Assistant Container",
    "version": "2024.1.6",
    "dev": false,
    "hassio": false,
    "virtualenv": false,
    "python_version": "3.11.6",
    "docker": true,
    "arch": "armv7l",
    "timezone": "Asia/Jerusalem",
    "os_name": "Linux",
    "os_version": "5.15.76-v7l+",
    "run_as_root": true
  },
  "custom_components": {
    "sonoff": {
      "version": "3.5.4",
      "requirements": [
        "pycryptodome>=3.6.6"
      ]
    },
    "hacs": {
      "version": "1.34.0",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    }
  },
  "integration_manifest": {
    "domain": "sonoff",
    "name": "Sonoff",
    "codeowners": [
      "@AlexxIT"
    ],
    "config_flow": true,
    "dependencies": [
      "http",
      "zeroconf"
    ],
    "documentation": "https://github.com/AlexxIT/SonoffLAN",
    "iot_class": "local_push",
    "issue_tracker": "/api/sonoff/26f46737-4853-4b6d-82a5-bd841a3de5c9",
    "requirements": [
      "pycryptodome>=3.6.6"
    ],
    "version": "3.5.4",
    "is_built_in": false
  },
  "data": {
    "version": "a4a8c5f",
    "cloud_auth": true,
    "config": {
      "username": "***",
      "password": "***",
      "reload": "always"
    },
    "options": {
      "mode": "auto",
      "debug": true
    },
    "errors": [],
    "device": {
      "uiid": 28,
      "params": {
        "bindInfos": "***",
        "version": 8,
        "only_device": {
          "ota": "success"
        },
        "sledOnline": "on",
        "ssid": "***",
        "bssid": "***",
        "init": 1,
        "fwVersion": "3.5.2",
        "rssi": -71,
        "staMac": "***",
        "setState": "arm",
        "rfList": [
          {
            "rfChl": 1,
            "rfVal": "53320252083EB51005"
          },
          {
            "rfChl": 3,
            "rfVal": "563002CC088A12C904"
          },
          {
            "rfChl": 4,
            "rfVal": "549602A0080E975C05"
          },
          {
            "rfChl": 5,
            "rfVal": "52DE028A07EA9DC805"
          }
        ],
        "cmd": "trigger",
        "rfTrig1": "2024-01-31T00:16:13.000Z",
        "timers": "***",
        "rfChl": 4,
        "rfTrig5": "2024-02-09T11:57:50.000Z",
        "rfTrig3": "2024-02-09T14:50:08.000Z",
        "rfTrig4": "2024-02-09T14:01:39.000Z"
      },
      "model": "RFBridge433",
      "online": true,
      "local": true,
      "localtype": "rf",
      "host": "192.168.4.145:8081",
      "deviceid": "1001eb95d6"
    }
  }
}
@AlexxIT AlexxIT added the bug Something isn't working label Feb 12, 2024
@AlexxIT AlexxIT self-assigned this Feb 12, 2024
@AlexxIT AlexxIT changed the title Getting exceptions in log when running the plugin - ATTR_LAST_TRIGGERED Fix KeyError: 'last_triggered' for binary_sensor Feb 12, 2024
@AlexxIT AlexxIT added this to the v3.5.5 milestone Feb 12, 2024
@AlexxIT AlexxIT assigned AlexxIT and unassigned AlexxIT Feb 13, 2024
@AlexxIT
Copy link
Owner

AlexxIT commented Feb 16, 2024

@AlexxIT AlexxIT closed this as completed Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants