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

Printer power switch generating errors #403

Open
potchin opened this issue Sep 4, 2024 · 4 comments
Open

Printer power switch generating errors #403

potchin opened this issue Sep 4, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@potchin
Copy link

potchin commented Sep 4, 2024

Version of the moonraker integration

1.3.4

Describe your setup

Klipper, Moonraker, Mainsail, Raspi.

Relay connected to the GPIO on the pi to control power to the printer board (SKR mini)

[power printer]
type: gpio
pin: gpio4
off_when_shutdown: True
initial_state: off
restart_klipper_when_powered: true
bound_services:
 klipper
 klipper-mcu

Describe the bug

My power controls though moonraker work fine. When toggling the power switch entity through HA (switch.am8_printer) the UI shows an error Failed to perform the action switch/turn off. state but the power does toggle correctly.

HA Logs

2024-09-03 19:00:29.076 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 258, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 453, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 168, in async_update_listeners
    update_callback()
  File "/config/custom_components/moonraker/sensor.py", line 796, in _handle_coordinator_update
    self._attr_native_value = self.entity_description.value_fn(self)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/moonraker/sensor.py", line 46, in <lambda>
    value_fn=lambda sensor: sensor.coordinator.data["printer.info"]["state"],
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
KeyError: 'state'
2024-09-03 19:00:35.086 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 462, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 537, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 210, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 813, in get
    return await self.handle(request, camera)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 831, in handle
    image = await _async_get_image(
            ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 185, in _async_get_image
    else await camera.async_camera_image(width=width, height=height)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/moonraker/camera.py", line 162, in async_camera_image
    self.coordinator.data["status"]["print_stats"]["state"]
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: 'status'

The corresponding error from moonraker.log...

2024-09-04 17:53:12,032 [common.py:build_error()] - JSON-RPC Request Error - Requested Method: printer.objects.query, Code: 503, Message: Klippy Host not connected
2024-09-04 17:53:12,039 [common.py:build_error()] - JSON-RPC Request Error - Requested Method: printer.info, Code: 503, Message: Klippy Host not connected

Klippy being disconnected is expected if the printer is off. Any suggestions?

@potchin
Copy link
Author

potchin commented Sep 4, 2024

Also noticed that the state gets out of sync. Eg, the state of the switch entity in HA is "on" but its actually powered off (which is correctly shown in mainsail)

@marcolivierarsenault marcolivierarsenault added the bug Something isn't working label Sep 5, 2024
@marcolivierarsenault
Copy link
Owner

Could you get a full copy of your log and reproduce the problems

https://moonraker-home-assistant.readthedocs.io/en/stable/support/logs.html#get-a-copy-of-your-ha-logs

@marcolivierarsenault marcolivierarsenault self-assigned this Sep 13, 2024
@garretthope98
Copy link

Also having this issue with a Wemo switch.
home-assistant_moonraker_2024-12-16T22-08-28.895Z.log

@philhagger
Copy link

philhagger commented Dec 19, 2024

I have this same issue with the latest updates on my relay connected to the GPIO on the pi to control power to the printer board and an LED light strip.

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

4 participants