home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.54k stars 30.72k forks source link

Lutron Caseta stops working several times a day #100958

Closed Sperryfreak01 closed 1 year ago

Sperryfreak01 commented 1 year ago

The problem

Several times a day HA looses the ability to control Lutron Casetta devices, Lutron Pico devices also stop triggering automations when the issue occurs. When the issue occurs the only thing that fixes the issue is to restart home assistant. As a sorta workaround right now I am having HA restart every 8 hours but this is not perfect as the issue sometimes happens more frequently than every 8 hours.

Everything has worked for for the last year, using Lutron that entire time. The last time I added a new Lutron device was a month or two before this issue started occurring.

When the issue occurs I am able to operate my Lutron devices via Alexa (through Lutron integration, not using HA at all) and via the Lutron App. Everything else works fine in HA when the issue occurs.

What version of Home Assistant Core has the issue?

System Information version | core-2023.9.2 -- | -- installation_type | Home Assistant OS dev | false hassio | true docker | true user | root virtualenv | false python_version | 3.11.5 os_name | Linux os_version | 6.1.45 arch | x86_64 timezone | America/Los_Angeles config_dir | /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.32.1 Stage | running Available Repositories | 1296 Downloaded Repositories | 16
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 10.5 -- | -- update_channel | stable supervisor_version | supervisor-2023.09.2 agent_version | 1.5.1 docker_version | 23.0.6 disk_total | 30.8 GB disk_used | 20.2 GB healthy | true supported | true board | ova supervisor_api | ok version_api | ok installed_addons | Mosquitto broker (6.3.1), Ring-MQTT with Video Streaming (5.6.3), Terminal & SSH (9.7.1), File editor (5.6.0), ESPHome (2023.8.3), Frigate Proxy (1.3), ESPresense Companion (0.3.40), Double Take Proxy (1.0.0), Node-RED (14.5.0), Matter Server (4.9.0)
Dashboards dashboards | 4 -- | -- resources | 4 views | 11 mode | storage
Recorder oldest_recorder_run | September 16, 2023 at 5:08 PM -- | -- current_recorder_run | September 26, 2023 at 8:00 AM estimated_db_size | 1827.16 MiB database_engine | sqlite database_version | 3.41.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Lutron Casetta

Link to integration documentation on our website

https://www.home-assistant.io/integrations/lutron_caseta/

Diagnostics information

GitHub complained about the length of the file so posted in Gist, https://gist.github.com/Sperryfreak01/c720ba5f0dee9ebc42f9b37fc4bf257c

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.automation.garage_lights_on_when_trash_door_opened
Source: components/lutron_caseta/switch.py:56
Integration: Automation (documentation, issues)
First occurred: 8:19:06 AM (45 occurrences)
Last logged: 11:58:42 AM

Garage Lights - On when door to garage opened: If at step 1: Error executing script. Unexpected error for call_service at pos 1: 'NoneType' object has no attribute '_write_appdata'
Garage Lights - On when door to garage opened: Error executing script. Unexpected error for if at pos 1: 'NoneType' object has no attribute '_write_appdata'
While executing automation automation.garage_lights_on_when_trash_door_opened
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 704, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 666, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 1969, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2006, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 870, in entity_service_call
    response_data = await _handle_entity_call(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 942, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/lutron_caseta/switch.py", line 56, in async_turn_on
    await self._smartbridge.turn_on(self.device_id)
  File "/usr/local/lib/python3.11/site-packages/pylutron_caseta/smartbridge.py", line 435, in turn_on
    await self.set_value(device_id, 100, **kwargs)
  File "/usr/local/lib/python3.11/site-packages/pylutron_caseta/smartbridge.py", line 343, in set_value
    await self._request(
  File "/usr/local/lib/python3.11/site-packages/pylutron_caseta/smartbridge.py", line 254, in _request
    response = await self._leap.request(communique_type, url, body)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pylutron_caseta/leap.py", line 69, in request
    self._writer.write(text + b"\r\n")
  File "/usr/local/lib/python3.11/asyncio/streams.py", line 332, in write
    self._transport.write(data)
  File "/usr/local/lib/python3.11/asyncio/sslproto.py", line 218, in write
    self._ssl_protocol._write_appdata((data,))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '_write_appdata'

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @swails, @bdraco, @danaues, mind taking a look at this issue as it has been labeled with an integration (lutron_caseta) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `lutron_caseta` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign lutron_caseta` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


lutron_caseta documentation lutron_caseta source (message by IssueLinks)

bdraco commented 1 year ago

Please upload debug logs

https://www.home-assistant.io/docs/configuration/troubleshooting/#enabling-debug-logging

Sperryfreak01 commented 1 year ago

Tried doing that a few times and never saw anything extra get logged, I'll try again with the instructions linked

Sperryfreak01 commented 1 year ago

Yeah, So I am dumb didnt realize you had to turn it off to get the logs...

too long to post here, see gist https://gist.github.com/Sperryfreak01/de7a6f930d65c1ee69e4b2544e8d97a4

bdraco commented 1 year ago

It looks like a race in the underlying library

2023-09-26 08:10:57.188 CRITICAL (MainThread) [pylutron_caseta.smartbridge] monitor loop has exited
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/pylutron_caseta/smartbridge.py", line 484, in _monitor
    await self._monitor_once()
  File "/usr/local/lib/python3.11/site-packages/pylutron_caseta/smartbridge.py", line 536, in _monitor_once
    self._leap.close()
  File "/usr/local/lib/python3.11/site-packages/pylutron_caseta/leap.py", line 169, in close
    request.set_exception(BridgeDisconnectedError())
asyncio.exceptions.InvalidStateError: invalid state

Its likely setting the exception twice or too late

Sperryfreak01 commented 1 year ago

Holy hell, did you already submit a PR to address? I'm still trying to read through the code and figure out what you saw.

Anto79-ops commented 1 year ago

thanks for addressing. Maybe you can also tag this issue on your PR? https://github.com/gurumitts/pylutron-caseta/issues/148

I see similar error messages, for example:


2023-09-02 17:34:10.743 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/pylutron_caseta/smartbridge.py", line 709, in _login
    await self._subscribe_to_button_status()
  File "/usr/local/lib/python3.11/site-packages/pylutron_caseta/smartbridge.py", line 1244, in _subscribe_to_button_status
    response, _ = await self._subscribe(
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pylutron_caseta/smartbridge.py", line 270, in _subscribe
    raise BridgeDisconnectedError()
pylutron_caseta.BridgeDisconnectedError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/pylutron_caseta/smartbridge.py", line 724, in _login
    self._login_completed.set_exception(ex)
asyncio.exceptions.InvalidStateError: invalid state
mdonoughe commented 1 year ago

Updating pylutron-caseta may fix this error, but it seems like this installation has significant networking issues and will likely continue to have problems in general.