basnijholt / home-assistant-streamdeck-yaml

Control Home Assistant on Stream Deck with support on all operating systems and configuration via YAML
Apache License 2.0
241 stars 15 forks source link

Docker/Pi3 - Stream Deck recognised but still shows screensaver #19

Open bacco007 opened 1 year ago

bacco007 commented 1 year ago

It seems to detect the stream deck ok, but the device remains on the elgato logo screensaver - tried rebooting the Pi and restarting the docker container to no avail

I did wonder whether the Pi3 isnt powerful enough though

[07:20:02] Starting Stream Deck           home_assistant_streamdeck_yaml.py:1172
           integration with                                                     
           args.host='192.168.1.90:8123',                                       
           args.config=PosixPath('configu                                       
           ration.yaml'),                                                       
           args.protocol='ws'                                                   
           Found 15 keys,                  home_assistant_streamdeck_yaml.py:856
           deck=<StreamDeck.Devices.Stream                                      
           DeckOriginalV2.StreamDeckOrigin                                      
           alV2 object at 0x74aaad50>                                           
           {"type":"auth_required","ha_ver home_assistant_streamdeck_yaml.py:539
           sion":"2023.4.0b2"}                                                  
           Connected to Home Assistant     home_assistant_streamdeck_yaml.py:540
basnijholt commented 1 year ago

At that point it is waiting for the complete state that will be send over from Home Assistant. For me this can take ~30s. How long did you wait?

My HA is on a Nuc and StreamDeck on RPI4.

bacco007 commented 1 year ago

I've just noticed that its come alive and has the icons I setup as a test - not sure how long it took, but happened since I logged the issue.

Rebooted and now its not working again:

Traceback (most recent call last):
  File "/usr/local/bin/home-assistant-streamdeck-yaml", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/app/home_assistant_streamdeck_yaml.py", line 1176, in main
    asyncio.run(
  File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/app/home_assistant_streamdeck_yaml.py", line 1139, in run
    complete_state = await get_states(websocket)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/home_assistant_streamdeck_yaml.py", line 683, in get_states
    data = json.loads(await websocket.recv())
                      ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 568, in recv
    await self.ensure_open()
  File "/usr/local/lib/python3.11/site-packages/websockets/legacy/protocol.py", line 953, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedOK: received 1000 (OK); then sent 1000 (OK)
basnijholt commented 1 year ago

This error occurs when the WebSocket connection is closed with a status code of 1000 (OK) while your script is still trying to receive data from it.

Here's a breakdown of the error:

  1. In home_assistant_streamdeck_yaml.py, the run() function is calling get_states(websocket).
  2. The get_states() function tries to receive data from the WebSocket by calling await websocket.recv().
  3. In the websockets library, the recv() function checks if the WebSocket connection is still open by calling await self.ensure_open().
  4. The ensure_open() function raises a ConnectionClosedOK exception because the connection was closed with a status code of 1000 (OK).

It appears that the WebSocket connection is being closed normally (with status code 1000), but the script is still trying to receive data from it. This could be due to a timing issue, an issue with the remote server closing the connection, or a problem with the way the script is handling the WebSocket connection.

To resolve this issue, I could add error handling to catch the ConnectionClosedOK exception and handle it gracefully, for example, by retrying the connection or logging an appropriate message. I might also want to somehow investigate why the connection is being closed and ensure that the script is managing the WebSocket connection correctly.

Will try to do this soon!

basnijholt commented 1 year ago

Hey, I wanted to let you know that I've recently released a new Home Assistant Supervisor add-on, which significantly simplifies the configuration process for the Stream Deck integration. It's designed to make your experience even more enjoyable and hassle-free. I invite you to check it out at https://github.com/basnijholt/home-assistant-streamdeck-yaml-addon and give it a try. Your feedback is always appreciated!

basnijholt commented 1 year ago

BTW when debugging I also ran into the 1000 error. It turned out my token didn't have the correct permissions.