sindrebroch / ha-magicmirror

Custom HomeAssistant-integration for MagicMirror
Apache License 2.0
14 stars 0 forks source link

button.magicmirror_shutdown_host hanging #9

Closed michelnet closed 2 years ago

michelnet commented 2 years ago

i have configured a rule to shutdown the magic mirror and after 30 secounds to turn off the screen and the pi, to save engergy.

That's the rule:

  - service: button.press
    data: {}
    target:
      entity_id: button.magicmirror_shutdown_host
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.strom_magic_mirror

The shutdown process is starting by the debugging in the ui u recive a unknown Error. And the rule wait by this step infinity.

I use the Version 1.3.0

2022-04-08 14:39:36 DEBUG (MainThread) [custom_components.magicmirror] Finished fetching magicmirror data in 0.646 seconds (success: True) 2022-04-08 14:40:15 DEBUG (MainThread) [custom_components.magicmirror] GET url=http://10.82.1.219:8080/api/shutdown. headers={'accept': 'application/json', 'Authorization': 'Bearer ***'} 2022-04-08 14:40:15 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: Server disconnected

sindrebroch commented 2 years ago

Let's see if I undestand your issue correctly. When you try to use the button.magicmirror_shutdown_host, it posts an error in HomeAssistant frontend? And the shutdown-command never completes?

What about if you press the button without the automation?

It seems to be working fine in my instance, but it takes a little bit to complete the shutdown.

To narrow down where the issue it would be nice to know if the MMM-Remote-Control-page works for you. If you go to http://:8080/remote.html#power-menu and try to shutdown from there, does it work?

michelnet commented 2 years ago

i can shutdown the mirror over the mmm-remote-control-page and over the button. in the home assistant frontend i receive follow error: Error executing service button/press. Server disconnected

sindrebroch commented 2 years ago

So the button.magicmirror_shutdown_host works but you get an error? Both when pressing it by itself, as well as using it in the script/automation?

sindrebroch commented 2 years ago

Weird. As I said, it's not happening on my end.

My thinking is that it is related to the system shutting down, and because of that it is not responding properly to the button-command.

I'll take a look at it at some point, but I don't have time until after Easter.

sindrebroch commented 2 years ago

Does this happen every time, or just once in a while? Interested to know if it has something to do with a poll happening at the same time?

michelnet commented 2 years ago

it happens every time. When i use the reboot action have follow error:

2022-04-10 19:40:51 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140117691635216] Response not 200 OK <ClientResponse(http://10.82.1.219:8080/api/restart) [400 Bad Request]> <CIMultiDictProxy('X-DNS-Prefetch-Control': 'off', 'Expect-CT': 'max-age=0', 'X-Frame-Options': 'SAMEORIGIN', 'Strict-Transport-Security': 'max-age=15552000; includeSubDomains', 'X-Download-Options': 'noopen', 'X-Content-Type-Options': 'nosniff', 'X-Permitted-Cross-Domain-Policies': 'none', 'Referrer-Policy': 'no-referrer', 'X-XSS-Protection': '0', 'Content-Type': 'application/json; charset=utf-8', 'Content-Length': '353', 'Etag': 'W/"161-ZwIkDrLafyCKEPy3w2pvBQAQI4Y"', 'Date': 'Sun, 10 Apr 2022 17:40:51 GMT', 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=5')> Traceback (most recent call last):

Im on the HA Version 2004.4.1 and also MMM-Remote-Control is the last release installed.

how can i help with the debugging?

michelnet commented 2 years ago

2022-04-10 19:44:54 DEBUG (MainThread) [custom_components.magicmirror] GET url=http://10.82.1.219:8080/api/shutdown. headers={'accept': 'application/json', 'Authorization': 'Bearer 111'} 2022-04-10 19:44:55 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140117354567712] Server disconnected Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 193, in handle_call_service await hass.services.async_call( File "/usr/src/homeassistant/homeassistant/core.py", line 1634, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1671, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service await service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 677, in entity_service_call future.result() # pop exception if have File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 955, in async_request_call await coro File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 714, in _handle_entity_call await result File "/usr/src/homeassistant/homeassistant/components/button/init.py", line 114, in _async_press_action await self.async_press() File "/config/custom_components/magicmirror/button.py", line 94, in async_press await self.coordinator.api.shutdown() File "/config/custom_components/magicmirror/api.py", line 153, in shutdown return await self.get(API_SHUTDOWN) File "/config/custom_components/magicmirror/api.py", line 94, in get get = await self._session.get( File "/usr/local/lib/python3.9/site-packages/aiohttp/client.py", line 559, in _request await resp.start(conn) File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 898, in start message, payload = await protocol.read() # type: ignore[union-attr] File "/usr/local/lib/python3.9/site-packages/aiohttp/streams.py", line 616, in read await self._waiter aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected

Thats the error from the shutdown command

sindrebroch commented 2 years ago

Thanks for providing more debug information. Pretty sure this is an issue with the API not responding on some of these calls before shutting down the service. I'll see what I can do to handle it on my side to handle that.

sindrebroch commented 2 years ago

Should be fixed in release 1.4.0. Please reopen if the issue persists.