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
70.11k stars 29.16k forks source link

Tradfri light, various frequent errors: KeyError: '3311', NoneType' object does not support item assignment #85254

Closed Mariusthvdb closed 1 week ago

Mariusthvdb commented 1 year ago

The problem

as logged in the beta a couple of times, below error(s) is (are) in the logs.

Update: Not sure if it is actually causing functionality issues, but is is so frequent, something really is not ok.

time has shown this is causing frequent (multiple times daily) connection issues, and Tradfri not responding/communicating to the Gateway any longer. The Gateway btw being fully functional standalone communicating correctly with the Ikea app.

What version of Home Assistant Core has the issue?

2023.1

What was the last working version of Home Assistant Core?

2022.12

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Tradfri

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant
Source: components/tradfri/light.py:93 
First occurred: 18:11:09 (5256 occurrences) 
Last logged: 22:02:15

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 168, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 316, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 121, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/components/tradfri/base_class.py", line 71, in _handle_coordinator_update
    self._refresh()
  File "/usr/src/homeassistant/homeassistant/components/tradfri/light.py", line 93, in _refresh
    self._device_data = self.coordinator.data.light_control.lights[0]
  File "/usr/local/lib/python3.10/site-packages/pytradfri/device/__init__.py", line 84, in light_control
    return LightControl(self)
  File "/usr/local/lib/python3.10/site-packages/pytradfri/device/light_control.py", line 40, in __init__
    if ATTR_LIGHT_DIMMER in self.raw[0]:
  File "/usr/local/lib/python3.10/site-packages/pytradfri/device/light_control.py", line 71, in raw
    return self._device.raw[ATTR_LIGHT_CONTROL]
KeyError: '3311'

and 

Logger: homeassistant.util.logging
Source: util/logging.py:156 
First occurred: 18:11:53 (451 occurrences) 
Last logged: 22:01:55

Exception in set_hub_available when dispatching 'tradfri.gw_status': (True,)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/tradfri/coordinator.py", line 47, in set_hub_available
    await self.async_request_refresh()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 175, in async_request_refresh
    await self._debounced_refresh.async_call()
  File "/usr/src/homeassistant/homeassistant/helpers/debounce.py", line 82, in async_call
    await task
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 201, in async_refresh
    await self._async_refresh(log_failures=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 316, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 121, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/components/tradfri/base_class.py", line 71, in _handle_coordinator_update
    self._refresh()
  File "/usr/src/homeassistant/homeassistant/components/tradfri/light.py", line 93, in _refresh
    self._device_data = self.coordinator.data.light_control.lights[0]
  File "/usr/local/lib/python3.10/site-packages/pytradfri/device/__init__.py", line 84, in light_control
    return LightControl(self)
  File "/usr/local/lib/python3.10/site-packages/pytradfri/device/light_control.py", line 40, in __init__
    if ATTR_LIGHT_DIMMER in self.raw[0]:
  File "/usr/local/lib/python3.10/site-packages/pytradfri/device/light_control.py", line 71, in raw
    return self._device.raw[ATTR_LIGHT_CONTROL]
KeyError: '3311'

Logger: homeassistant.components.tradfri
Source: helpers/update_coordinator.py:201 
Integration: IKEA TRÅDFRI (documentation, issues) 
First occurred: 18:11:02 (2 occurrences) 
Last logged: 18:11:04

Error fetching Update coordinator for <65583 - Parking light (TRADFRI bulb E27 W opal 1000lm)> data: Error communicating with API: Gateway payload: {"r":"02"}. Error code: 4.00 Bad Request..
Error fetching Update coordinator for <65714 - Mademoiselle Filou (TRADFRI bulb E14 W op/ch 400lm)> data: Error communicating with API: Gateway payload: {"r":"02"}. Error code: 4.00 Bad Request..

Logger: homeassistant.components.tradfri
Source: components/tradfri/light.py:93 
Integration: IKEA TRÅDFRI (documentation, issues) 
First occurred: 18:11:09 (2 occurrences) 
Last logged: 18:12:48

Unexpected error fetching Update coordinator for <65714 - Mademoiselle Filou (TRADFRI bulb E14 W op/ch 400lm)> data: '3311'
Unexpected error fetching Update coordinator for <65583 - Parking light (TRADFRI bulb E27 W opal 1000lm)> data: '3311'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 225, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/components/tradfri/coordinator.py", line 88, in _async_update_data
    await self.api(cmd)
  File "/usr/local/lib/python3.10/site-packages/pytradfri/api/aiocoap_api.py", line 199, in request
    result = await self._execute(api_commands, timeout)
  File "/usr/local/lib/python3.10/site-packages/pytradfri/api/aiocoap_api.py", line 137, in _execute
    await self._observe(api_command, timeout)
  File "/usr/local/lib/python3.10/site-packages/pytradfri/api/aiocoap_api.py", line 220, in _observe
    api_command.result = _process_output(pr_rsp)
  File "/usr/local/lib/python3.10/site-packages/pytradfri/command.py", line 91, in result
    self._result = self._process_result(value)
  File "/usr/local/lib/python3.10/site-packages/pytradfri/resource.py", line 62, in observe_callback
    callback(self)
  File "/usr/src/homeassistant/homeassistant/components/tradfri/coordinator.py", line 52, in _observe_update
    self.async_set_updated_data(data=device)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 346, in async_set_updated_data
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 121, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/components/tradfri/base_class.py", line 71, in _handle_coordinator_update
    self._refresh()
  File "/usr/src/homeassistant/homeassistant/components/tradfri/light.py", line 93, in _refresh
    self._device_data = self.coordinator.data.light_control.lights[0]
  File "/usr/local/lib/python3.10/site-packages/pytradfri/device/__init__.py", line 84, in light_control
    return LightControl(self)
  File "/usr/local/lib/python3.10/site-packages/pytradfri/device/light_control.py", line 40, in __init__
    if ATTR_LIGHT_DIMMER in self.raw[0]:
  File "/usr/local/lib/python3.10/site-packages/pytradfri/device/light_control.py", line 71, in raw
    return self._device.raw[ATTR_LIGHT_CONTROL]
KeyError: '3311'

Logger: homeassistant.components.tradfri
Source: components/tradfri/coordinator.py:77 
Integration: IKEA TRÅDFRI (documentation, issues) 
First occurred: 18:14:03 (50 occurrences) 
Last logged: 18:14:03

Unexpected error fetching Update coordinator for <65641 - Master bed outlet (TRADFRI control outlet)> data: Retransmissions exceeded
Unexpected error fetching Update coordinator for <65741 - Ster rechts (TRADFRI bulb E14 WS 470lm)> data: Retransmissions exceeded
Unexpected error fetching Update coordinator for <65719 - Bureau left (TRADFRI bulb E14 WS opal 400lm)> data: Retransmissions exceeded
Unexpected error fetching Update coordinator for <65740 - Ster links (TRADFRI bulb E14 WS 470lm)> data: Retransmissions exceeded
Unexpected error fetching Update coordinator for <65701 - Guest room afstandsbediening (TRADFRI remote control)> data: Retransmissions exceeded
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 225, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/components/tradfri/coordinator.py", line 77, in _async_update_data
    raise exc
  File "/usr/local/lib/python3.10/site-packages/pytradfri/api/aiocoap_api.py", line 107, in _get_response
    pr_resp = await asyncio.wait_for(pr_req.response, timeout)
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 408, in wait_for
    return await fut
  File "/usr/local/lib/python3.10/site-packages/aiocoap/protocol.py", line 612, in _run_outer
    await cls._run(app_request, response, weak_observation, protocol, log)
  File "/usr/local/lib/python3.10/site-packages/aiocoap/protocol.py", line 671, in _run
    blockresponse = await blockrequest.response
  File "/usr/local/lib/python3.10/site-packages/aiocoap/protocol.py", line 897, in __del__
    self._future.result()
  File "/usr/local/lib/python3.10/site-packages/aiocoap/protocol.py", line 897, in __del__
    self._future.result()
  File "/usr/local/lib/python3.10/site-packages/aiocoap/protocol.py", line 897, in __del__
    self._future.result()
  [Previous line repeated 1 more time]
aiocoap.error.ConRetransmitsExceeded: Retransmissions exceeded

Additional information

Aware several other new Tradfri issues have been logged, I decided to create this separate, because the logging is different.

https://github.com/home-assistant/core/issues/85105 https://github.com/home-assistant/core/issues/84624

MartinHjelmare commented 7 months ago

Please don't use this issue as a catch all issue for the Tradfri integration. If the stack trace is different, open a new issue for each stack trace.

Mariusthvdb commented 7 months ago

ok I will do.

Sorry if this was confusing/non-helpful for fixing the issue only posted here, because we had those different stack traces in different issues, and response seemed very low, since January 2023. It seems to be the same issue trickling down to all of those individual traces, and creating some oversight/keeping it up to date seemed logical the logical thing to do while waiting for dev instructions.

btw, the AttributeError: 'NoneType' object has no attribute 'values' was logged since the beginning of this topic.

current change is the manual reload of the integration now fails..

Mariusthvdb commented 7 months ago

Please don't use this issue as a catch all issue for the Tradfri integration. If the stack trace is different, open a new issue for each stack trace.

so we did, is anyone looking at this? The issue has increased a lot, and is up to the point where the integration cant be used reliably anymore, unless we find a reason for this behavior and fix that.

Ive now also filed an issue at aiocoap, specifically directed to do so by the error message, link is above.

The fact there is no-one assigned to the new issue doesn't really help probably... this one still stands firmly:

Scherm­afbeelding 2023-12-15 om 10 32 14
aetha commented 7 months ago

Agree with @Mariusthvdb. It’s not a huge deal to me since I know to use the reconnect automation, but this issue could be leaving new / less technical users with a bad experience. HA is generally a very reliable system, and this one component potentially spoils that impression.

As much as I’d like to see the root cause of this issue discovered and fixed, I think regardless it’s pretty clear the Tradfri integration needs overhauled logic for automatic reconnection. IOW what the workaround automation is doing, should just be a built in feature.

gpuccio87 commented 6 months ago

Same problem here. For a few days now, the gateway has been working from its app but is not reachable from HA. The only way is to restart HA

Mariusthvdb commented 5 months ago

this is getting worse and worse.....

I can't understand why there is not a single sign of involvement here.

Scherm­afbeelding 2024-01-31 om 10 41 50
Mariusthvdb commented 5 months ago

Please don't use this issue as a catch all issue for the Tradfri integration. If the stack trace is different, open a new issue for each stack trace.

Martin, Ive done as you asked, keep things tidy and separated, but I ask my self why, as no one seems to even be bothered by a core integration failing as badly as this?

There has been no response now from anyone, other than telling me not to mix issues... Not having a code-owner doesnt help, but please talk about this in the core team, to have a look how to go forward?

Currently (2024.1.5) it is truly killing the HA experience ...

Scherm­afbeelding 2024-01-31 om 11 06 51
pedolsky commented 5 months ago

And HAF in free fall. The integration has (again) become unreliable.

MartinHjelmare commented 5 months ago

As far as I can tell, the KeyError happens due to a bad response from the gateway with missing information. The gateway or a connected device is unreliable, and doesn't follow the expected response model, is my interpretation.

Personally I've moved over to using the Dirigera via Homekit Controller integration, which has been rock solid. Although I didn't experience that much troubles before with the old gateway and tradfri integration either.

I'm happy to review PRs, if someone comes along that has spent some time troubleshooting the issue. Just posting different logs to this issue won't move the issue along I think.

Mariusthvdb commented 5 months ago

hey Martin, thanks.

the fact some of the devices cant be reached/controlled (completely, sometimes they still are affected, but the front-end does not change its state...) was one thing.

the most problematic issue we now face is this:

Scherm­afbeelding 2024-02-01 om 07 44 37

which we get when we try to reload the integration, and this didnt happen before, it slipped in some updates ago last year.

it seems that has nothing to do with individual devices?

Would that be something to look in to independently from fixing the more detailed issues with devices not responding?

I mean, if we can auto-reload the integration again, we could at least keep the HA instance going.

MartinHjelmare commented 5 months ago

I'm not going to comment here on a different problem than the original post, which is the KeyError.

Mariusthvdb commented 5 months ago

I'm not going to comment here on a different problem than the original post, which is the KeyError.

please do so here then: https://github.com/home-assistant/core/issues/105004

Mariusthvdb commented 3 months ago

Ive given up on this integration ever being fixed. I've moved all of my devices to Dirigera which is seen by HomeKit, a rock solid combination, highly recommended. we can even create automations with device triggers. only devices nor supported are the switches (which were only battery sensors here tools that isnt a big loss)

That's why I wont pursue this any longer, knowing the integration still suffers the issue on a daily base.

Hoping anyone else can pick this up. Because I still feel it's a shame that such a wonderful product line should be as ill served than this.

issue-triage-workflows[bot] commented 1 week ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.