core
core copied to clipboard
Tradfri light, various frequent errors: KeyError: '3311', NoneType' object does not support item assignment
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
some extra and ridiculously frequent logging:
Logger: root
Source: /usr/src/homeassistant/homeassistant/bootstrap.py:383
First occurred: 03:17:26 (343646 occurrences)
Last logged: 12:58:14
Uncaught exception
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/aiocoap/transports/tinydtls.py", line 174, in wrapper
return getattr(self, __method)(*args)
File "/usr/local/lib/python3.10/site-packages/aiocoap/transports/tinydtls.py", line 284, in _read
self.coaptransport.ctx.dispatch_message(message)
File "/usr/local/lib/python3.10/site-packages/aiocoap/messagemanager.py", line 115, in dispatch_message
success = self._process_response(message)
File "/usr/local/lib/python3.10/site-packages/aiocoap/messagemanager.py", line 341, in _process_response
return self.token_manager.process_response(response)
File "/usr/local/lib/python3.10/site-packages/aiocoap/tokenmanager.py", line 171, in process_response
if key not in self.outgoing_requests:
TypeError: argument of type 'NoneType' is not iterable
and
Logger: homeassistant.components.tradfri
Source: components/tradfri/coordinator.py:88
Integration: IKEA TRÅDFRI (documentation, issues)
First occurred: 03:15:54 (345599 occurrences)
Last logged: 12:58:14
Unexpected error fetching Update coordinator for <65606 - Hallway dresser bewegingssensor (TRADFRI motion sensor)> data: 'NoneType' object does not support item assignment
Unexpected error fetching Update coordinator for <65709 - Corridor pool (TRADFRIbulbT120E27WSopal470lm)> data: 'NoneType' object does not support item assignment
Unexpected error fetching Update coordinator for <65583 - Parking light (TRADFRI bulb E27 W opal 1000lm)> data: 'NoneType' object does not support item assignment
Unexpected error fetching Update coordinator for <65670 - Garage afstandsbediening (TRADFRI remote control)> data: 'NoneType' object does not support item assignment
Unexpected error fetching Update coordinator for <65716 - Symfonisk afstandsbediening (SYMFONISK Sound Controller)> data: 'NoneType' object does not support item assignment
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 218, in _observe
pr_req, pr_rsp = await self._get_response(msg, timeout)
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 355, in send
request_interface.request(pipe)
File "/usr/local/lib/python3.10/site-packages/aiocoap/tokenmanager.py", line 256, in request
self.outgoing_requests[key] = request
TypeError: 'NoneType' object does not support item assignment
Logger: homeassistant.util.logging
Source: util/logging.py:156
First occurred: 7 januari 2023 om 19:32:55 (1166 occurrences)
Last logged: 00:28:58
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'
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] TypeError: 'NoneType' object is not subscriptable
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/sensor.py", line 212, in _refresh self._attr_native_value = self.entity_description.value(self.coordinator.data) File "/usr/src/homeassistant/homeassistant/components/tradfri/sensor.py", line 83, in <lambda> value=lambda device: cast(int, device.device_info.battery_level), File "/usr/local/lib/python3.10/site-packages/pytradfri/device/__init__.py", line 195, in battery_level if ATTR_DEVICE_BATTERY not in self.raw: File "/usr/local/lib/python3.10/site-packages/pytradfri/device/__init__.py", line 203, in raw return cast(TypeDeviceInfo, self._device.raw[ATTR_DEVICE_INFO]) TypeError: 'NoneType' object is not subscriptable
and counting the endless errors.. currently on 2023.2.5
also:
Logger: homeassistant.components.tradfri
Source: components/tradfri/base_class.py:32
Integration: IKEA TRÅDFRI (documentation, issues)
First occurred: 16:06:59 (6 occurrences)
Last logged: 16:07:28
Unable to execute command <Command put ['15001', 65695]: {'3311': [{'5850': 1}]}>: Gateway payload: {"r":"02"}. Error code: 4.00 Bad Request.
Unable to execute command <Command put ['15001', 65730]: {'3311': [{'5850': 1}]}>: Gateway payload: {"r":"02"}. Error code: 4.00 Bad Request.
This might be the most frequent logger, every 5 seconds:
2023-01-22 00:14:40.494 ERROR (MainThread) [homeassistant] 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/fan.py", line 77, in _refresh
self._device_data = self.coordinator.data.air_purifier_control.air_purifiers[0]
AttributeError: 'NoneType' object has no attribute 'air_purifiers'
Martin confirmed that nothing significant has changed in PyTradfri library, so what else would it be?
- Software update on the Gateway
- Integration in HA
- Maybe network related stuff (using Unifi hardware)
noticed pytrafdri was just updated with a huge amount of new stuff. maybe that helps to fix this.. https://github.com/home-assistant-libs/pytradfri/releases/tag/12.0.0
Note that I said that nothing significant has changed in the integration in recent releases:
https://github.com/home-assistant-libs/pytradfri/issues/617#issuecomment-1399367301
Have the same error, started at the same time you saw it.
Nick is on to something, please see https://github.com/home-assistant/core/issues/86083#issuecomment-1416402508
Note that I said that nothing significant has changed in the integration in recent releases:
sure Martin, that was noted. However, as it seems things might have changed on the Tradfri side of things? It has become a steady issue, and am surprised so few people respond here. The logs are littered with many thousands of lines, and only a HA restart stops it from happening. Until it all starts over
Most of the problems historically have been caused by the gateway and problems in the gateway firmware.
For me it's been working fine for months now.
Maybe it depends on the (number of) devices one has included on the gateway ?
This issue has been around 2 HA cycles now.
Only thing locally changed was the addition of 2 lights and a remote for that , which now have been deleted again.
Maybe they were the overload of allowed number of devices so I took them out to be sure
Yet, the issue persists.... heavily
I oddly fixed it by extending the DHCP release time from 24 hours to days. I had the hub configured with a fixed IP for obvious reasons and somehow the DHCP scrambled the connection for the integration. Maybe that helps someone here. In the meantime I bought the new IKEA Dirigera hub which comes with its own challenges :-)
I do have it set to a fixed Ip on my Unifi Udm pro, but have not lease time configured. Or so I think...
Just an update , and do note the occurrences count...
Logger: homeassistant.components.tradfri
Source: components/tradfri/coordinator.py:88
Integration: IKEA TRÅDFRI (documentation, issues)
First occurred: 16:47:41 (97205 occurrences)
Last logged: 19:52:15
Unexpected error fetching Update coordinator for <65705 - Antiek afstandsbediening (TRADFRI on/off switch)> data: 'NoneType' object does not support item assignment
Unexpected error fetching Update coordinator for <65683 - Library bewegingssensor (TRADFRI motion sensor)> data: 'NoneType' object does not support item assignment
Unexpected error fetching Update coordinator for <65680 - Antiek (TRADFRI bulb E27 WW clear 250lm)> data: 'NoneType' object does not support item assignment
Unexpected error fetching Update coordinator for <65719 - Bureau left (TRADFRI bulb E14 WS opal 400lm)> data: 'NoneType' object does not support item assignment
Unexpected error fetching Update coordinator for <65678 - Bedside guest room left (TRADFRI bulb E27 CWS opal 600lm)> data: 'NoneType' object does not support item assignment
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 239, 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 218, in _observe
pr_req, pr_rsp = await self._get_response(msg, timeout)
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 355, in send
request_interface.request(pipe)
File "/usr/local/lib/python3.10/site-packages/aiocoap/tokenmanager.py", line 256, in request
self.outgoing_requests[key] = request
TypeError: 'NoneType' object does not support item assignment
Looking at the stack trace above, it looks like the library that talks to the gateway is throwing an error. My guess is that the gateway is the root cause, and that there is very little that can be done by anyone developing the Home Assistant system.
I ran the very first version of the gateway (bought it on the day it was released) for years without any issues. The only time I did experience issues what when I flooded the gateway with requests, which caused it to hang.
HI thanks for chiming in!
the gateway has only seen updates by Ikea, and besides that HA has had 2 monthly updates,.
I have not added devices, nor am I flooding the gateway with requests. (btw, could the HA frontend be doing that too? Ive always only checked backend, but maybe the dashboard talks to the Gateway also..?)
What I did notice is that the fans are always listed dominantly. Not sure if anything has changed there in core since 2023? If not the integration, maybe the underlying libraries?
btw, an integration reload mostly fixes it, so, currently, we're back to that point in time where the Integration reload is automated based on 'Keep alive failed'.
and, as stated above, the gateway itself does not hang at all, and I can control all devices nicely with the app.
Even reloading has its issues:
Logger: homeassistant.config_entries
Source: components/tradfri/__init__.py:149
First occurred: 19:23:34 (1 occurrences)
Last logged: 19:23:34
Error unloading entry Ikea Trådfri for tradfri
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 533, in async_unload
result = await component.async_unload_entry(hass, self)
File "/usr/src/homeassistant/homeassistant/components/tradfri/__init__.py", line 149, in async_unload_entry
await factory.shutdown()
File "/usr/local/lib/python3.10/site-packages/pytradfri/api/aiocoap_api.py", line 99, in shutdown
await self._reset_protocol(exc)
File "/usr/local/lib/python3.10/site-packages/pytradfri/api/aiocoap_api.py", line 87, in _reset_protocol
await protocol.shutdown()
File "/usr/local/lib/python3.10/site-packages/aiocoap/protocol.py", line 332, in shutdown
await item
File "/usr/local/lib/python3.10/site-packages/aiocoap/tokenmanager.py", line 65, in shutdown
await self.token_interface.shutdown()
File "/usr/local/lib/python3.10/site-packages/aiocoap/messagemanager.py", line 71, in shutdown
for messageerror_monitor, cancellable in self._active_exchanges.values():
AttributeError: 'NoneType' object has no attribute 'values'
The last track trace you posted indicates there is something going on in aiocoap, which is the library used by the pytradfri integration to talk to the gateway. It was updated to version 0.4.5 in January this year, and the update came into effect in version 2023.2. So to conclude, as Martin said above, nothing significant has been updated as of recently.
Unfortunately, I have no further advice to give other than maybe trying some other equipment like Home Assistant's SkyConnect.
thanks for your analysis. it at least points to versions in underlying libraries we can track (not always obvious when only checking the integration). And no, 2023.3 didnt fix it, so something still is off.
Ofc I already took Martins remark for true, no question there.
But, it might well be the cause for the issue. If Tradfri made updates to their Gateway, and HA (or the underlying libraries) didnt followup there, it might result in what I see?
Anyways, I notice the team updating Tradfri libraries actively, maybe it will get sorted in the end.
Strangest thing is I cant imagine being the only Tradfri/HA user suffering this. As it is a truly breaking issue, there should be more people complaining.....
note this just happened on HA restart, which I didnt notice before. an integration reload fixed it, but its really getting serious
Logger: homeassistant.config_entries
Source: components/tradfri/__init__.py:81
First occurred: 17:31:32 (1 occurrences)
Last logged: 17:31:32
Error setting up entry Ikea Trådfri for tradfri
Traceback (most recent call last):
File "/usr/local/lib/python3.10/asyncio/tasks.py", line 456, in wait_for
return fut.result()
asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
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 458, in wait_for
raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 382, in async_setup
result = await component.async_setup_entry(hass, self)
File "/usr/src/homeassistant/homeassistant/components/tradfri/__init__.py", line 81, in async_setup_entry
devices: list[Device] = await api(devices_commands, timeout=TIMEOUT_API)
File "/usr/local/lib/python3.10/site-packages/pytradfri/api/aiocoap_api.py", line 204, in request
command_results = await asyncio.gather(*commands)
File "/usr/local/lib/python3.10/site-packages/pytradfri/api/aiocoap_api.py", line 167, in _execute
_, res = await self._get_response(msg, timeout)
File "/usr/local/lib/python3.10/site-packages/pytradfri/api/aiocoap_api.py", line 116, in _get_response
await self._reset_protocol(exc)
File "/usr/local/lib/python3.10/site-packages/pytradfri/api/aiocoap_api.py", line 87, in _reset_protocol
await protocol.shutdown()
File "/usr/local/lib/python3.10/site-packages/aiocoap/protocol.py", line 332, in shutdown
await item
File "/usr/local/lib/python3.10/site-packages/aiocoap/tokenmanager.py", line 62, in shutdown
request.add_exception(error.LibraryShutdown())
File "/usr/local/lib/python3.10/site-packages/aiocoap/pipe.py", line 179, in add_exception
self._add_event(self.Event(None, exception, True))
File "/usr/local/lib/python3.10/site-packages/aiocoap/pipe.py", line 164, in _add_event
keep_calling = cb(event)
File "/usr/local/lib/python3.10/site-packages/aiocoap/protocol.py", line 450, in process
self._runner.send(event)
File "/usr/local/lib/python3.10/site-packages/aiocoap/protocol.py", line 493, in _run
self.response.set_exception(first_event.exception)
asyncio.exceptions.InvalidStateError: invalid state
just another way of visualizing the impact of the issue:

Nothing to add unfortunately beside having the same issue, reloading tradfri integration solves the problem for a bit until it turns up again.
yes, Ive just corrected an reinstated the automation to take care of it, an d trigger on the keep-alive malfunctioning:
- alias: Reload Tradfri integration
id: reload_tradfri_integration
mode: restart
trigger:
- platform: event
event_type: system_log_event
event_data:
level: WARNING
id: observation
- platform: event
event_type: system_log_event
event_data:
level: ERROR
id: failed
condition:
# or:
# - >
# {{trigger.event.data.name == 'tradfri.base_class' and 'Observation failed for'
# in trigger.event.data.message[0]}}
- >
{{trigger.event.data.name == 'homeassistant.components.tradfri' and
'Keep-alive failed' in trigger.event.data.message[0]}}
# - >
# {{trigger.event.data.name == 'coap' and
# 'Error received in UDP connection under DTLS' in trigger.event.data.message[0]}}
action:
- service: system_log.write
data:
message: >
Ikea Tradfri '{{trigger.id}}' on {{trigger.event.data.name}} issue logged, reloading integration
level: warning
logger: homeassistant.components.tradfri
- service: script.reload_tradfri_integration
- service: system_log.write
data:
message: >
Ikea Tradfri integration was reloaded because of {{trigger.id}}
level: warning
logger: homeassistant.components.tradfri
- service: persistent_notification.create
data:
title: >
{{trigger.event.data.level}}: Tradfri reloaded
message: >
{{now().timestamp()|timestamp_custom('%X')}}: Ikea Tradfri integration was
reloaded because of {{trigger.id}}:
Message: {{trigger.event.data.message[0]}},
Logger: {{trigger.event.data.name}},
Source: {{trigger.event.data.source}},
Level: {{trigger.event.data.level}}
Full data: {{trigger.event}}
I did comment the other triggers I had before, as they have changed to the ones we have in this issue now.
Keep-alive seems to be the ultimate state into which the system gets after all of the other listed errors, and should be the final moment to have to restart the integration.
this is the result, so you know something happened:
just a bit safer, to prevent concurrent firing of this automation (I noticed the Keep-alive messages were repeated quickly in the log), I added an extra condition, and changed to mode single:
- alias: Reload Tradfri integration
id: reload_tradfri_integration
mode: single
trigger:
- platform: event
event_type: system_log_event
event_data:
level: WARNING
id: observation
- platform: event
event_type: system_log_event
event_data:
level: ERROR
id: failed
condition:
#prevent frequent firing
- >
{{now() - this.attributes.last_triggered > timedelta(minutes=5) if
this.attributes.last_triggered is not none else true}}
- >
{{trigger.event.data.name == 'homeassistant.components.tradfri' and
'Keep-alive failed' in trigger.event.data.message[0]}}
action:
- service: system_log.write
data:
message: >
Ikea Tradfri: '{{trigger.id}}' on {{trigger.event.data.name}} issue logged:
{{trigger.event.data.message[0]}}.
Reloading integration
level: critical
logger: homeassistant.components.tradfri
- service: script.reload_tradfri_integration
- service: system_log.write
data:
message: >
Ikea Tradfri integration was reloaded because of {{trigger.id}}
level: critical
logger: homeassistant.components.tradfri
- service: persistent_notification.create
data:
title: >
{{trigger.event.data.timestamp|timestamp_custom('%X')}}: Tradfri reloaded
message: >
{{now().timestamp()|timestamp_custom('%X')}}: Ikea Tradfri integration was
reloaded because of {{trigger.id}}:
Message: {{trigger.event.data.message[0]}},
Logger: {{trigger.event.data.name}},
Source: {{trigger.event.data.source}},
Level: {{trigger.event.data.level}}
Full data:
{{trigger.event}}
Note I also added the timestamp from the data itself, in the title. It actually proves to be the same as the now() in the message, but this is a nice way to check those timings logged in the system.
and logging history on this to see the impact more clearly: triggered by keep-alive failed
faintly feared it had to do with some actions I fire manually (scenes, triggering automations touching Tradfri lights) but this clearly proves that is not the case, as it was happening twice this night while firmly asleep....
The last track trace you posted indicates there is something going on in
aiocoap, which is the library used by thepytradfriintegration to talk to the gateway. It was updated to version 0.4.5 in January this year, and the update came into effect in version 2023.2.
Getting back to this, I honestly dont understand why devs say this didnt change anything in HA, as it clearly did..? How come you conclude this aiocoap update to 0.4.5 can not be the reason?
given the frequency of the issue, now checking whether this has to do with the transition: used on the Tradfri lights in my scripts/scenes.
which would also relate to other logged and yet unsolved issues in core: https://github.com/home-assistant/core/issues/85535 in Frontend https://github.com/home-assistant/core/issues/80696
so I now commented all transitions on Tradfri lights, and will keep HA on for a day, let's see what gives .....
well, that didnt help. Have lived without transitions on Tradfri lights for the week now, but still seeing the regular Tradfri reload being triggered by the Keep-alive failed logging
seems to be twice a day, but that is about the only thing to notice.. no connection to other events found yet
keeping it alive