Tradfri Unknown Error

Hi Team,

I get the following error while trying to use the stock Tradfri Integration:

I am running Home Assistant 2021.3.4

Logfile shows the following stacktrace:

2021-03-24 08:25:39 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/pytradfri/api/aiocoap_api.py", line 96, in _get_response
r = await pr.response
asyncio.exceptions.CancelledError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
resp = await self._request_handler(request)
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
resp = await handler(request)
File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 119, in impl
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 56, in security_filter_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 72, in ban_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 129, in auth_middleware
return await handler(request)
File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle
result = await result
File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 150, in post
return await super().post(request, flow_id)
File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 60, in wrapper
result = await method(view, request, *args, **kwargs)
File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 106, in post
result = await self._flow_mgr.async_configure(flow_id, data)
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 158, in async_configure
result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 216, in _async_handle_step
result: Dict = await getattr(flow, method)(user_input)
File "/usr/src/homeassistant/homeassistant/components/tradfri/config_flow.py", line 53, in async_step_auth
auth = await authenticate(
File "/usr/src/homeassistant/homeassistant/components/tradfri/config_flow.py", line 168, in authenticate
key = await api_factory.generate_psk(security_code)
File "/usr/local/lib/python3.8/site-packages/pytradfri/api/aiocoap_api.py", line 220, in generate_psk
self._psk = await self.request(command)
File "/usr/local/lib/python3.8/site-packages/pytradfri/api/aiocoap_api.py", line 168, in request
result = await self._execute(api_commands)
File "/usr/local/lib/python3.8/site-packages/pytradfri/api/aiocoap_api.py", line 152, in _execute
_, res = await self._get_response(msg)
File "/usr/local/lib/python3.8/site-packages/pytradfri/api/aiocoap_api.py", line 116, in _get_response
await self._update_credentials()
File "/usr/local/lib/python3.8/site-packages/pytradfri/api/aiocoap_api.py", line 236, in _update_credentials
"psk": self._psk.encode("utf-8"),
AttributeError: 'NoneType' object has no attribute 'encode'

Any tips?

Any tips on getting Tradfri to work?

I am no expert, but I had the same error. It turned out that I was using the wrong number on the back of the Tradfri. It’s not the number in the box at the button right, but the first small number directly below the QR code.
Hope this solve your issue

1 Like

Oh thank you, that should have been obvious, but yes - I was using the wrong code.