Trafikverket weather station integration, getting "Unknown error occured"

Hi all,
the trafikverket weather station integration has worked fine for me since a long time (~1year).

However recently it just stopped working, no data was comming from the weather stations any more.
I have not done any changes to my Home Assistant system.

So, I thought I will remove the integration and install it again and start from skratch.

  1. I removed the integration
  2. installed trafikverket integration
  3. added my token and weather station

And then I got the below error:
Trafikverket error

When looking in the HA logfiles, I can not find anything related to the Trafikverket integration.

My system setup:

System Health

version: core-2021.12.10
installation_type: Home Assistant OS
dev: false
hassio: true
docker: true
user: root
virtualenv: false
python_version: 3.9.7
os_name: Linux
os_version: 5.15.32-v8
arch: aarch64
timezone: Europe/Stockholm


GitHub API: ok
Github API Calls Remaining: 5000
Installed Version: 1.19.3
Stage: running
Available Repositories: 1140
Downloaded Repositories: 3


logged_in: false
can_reach_cert_server: ok
can_reach_cloud_auth: ok
can_reach_cloud: ok


host_os: Home Assistant OS 8.4
update_channel: stable
supervisor_version: supervisor-2022.10.2
docker_version: 20.10.14
disk_total: 116.8 GB
disk_used: 9.3 GB
healthy: true
supported: true
board: rpi3-64
supervisor_api: ok
version_api: ok
installed_addons: Samba share (9.5.1), File editor (5.3.3), TellStick (2.1.0), Terminal & SSH (9.3.0), Mosquitto broker (6.0.1), Node-RED (11.1.0)


dashboards: 1
resources: 1
views: 13
mode: yaml

Acctually I am a little bit out of ideas why this might have happended.
Anyone else that has any ideas to what it might be?

Look forward to your ideas :slight_smile: !
/Christian

Hi again!
I read on the Trafikverket home page that some older API’s are shut down.

I am currently in contact with Trafikverket in order to confirm if this might be the root cause to above issue or not. I will keep you updated :slight_smile: .

When asking Trafikverket if my “API key” could become old, I got the following answer back:

I think there is nothing wrong with the API key, but that you are calling an old version of the API that has been shut down. If you have any “v1”, “v1.1”, “v1.2”, “v1.3” or similar in the URL you are calling, try replacing it with “v2”. See this page for more information:
https://api.trafikinfo.trafikverket.se/DynamicContent/ContentDetails/635a63e2dc19bf12f0d448ac

So, the next step would be to confirm what API version the Home Assistant plugin is calling.
I will keep you updated :slight_smile:

It found that the “Trafikverket weather station” integration is already updated to support API V2.0.
Now I will continue to search why my integration stopped working. :grinning: Happy weekend!

When searching for “Trafikverket” in the logfile I find the following 7 items:


When clicking on the redmarked ERROR I find the following:

Logger: aiohttp.server
Source: components/trafikverket_weatherstation/config_flow.py:34
First occurred: 13:39:44 (1 occurrences)
Last logged: 13:39:44

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 98, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 78, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 181, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 137, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 157, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 62, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 252, 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 325, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/trafikverket_weatherstation/config_flow.py", line 58, in async_step_user
    validate = await self.validate_input(api_key, station)
  File "/usr/src/homeassistant/homeassistant/components/trafikverket_weatherstation/config_flow.py", line 34, in validate_input
    await weather_api.async_get_weather(station)
  File "/usr/local/lib/python3.9/site-packages/pytrafikverket/trafikverket_weather.py", line 85, in async_get_weather
    weather_stations = await self._api.async_make_request(
  File "/usr/local/lib/python3.9/site-packages/pytrafikverket/trafikverket.py", line 162, in async_make_request
    error_nodes = etree.fromstring(content).xpath("/RESPONSE/RESULT/ERROR")
  File "src/lxml/etree.pyx", line 3252, in lxml.etree.fromstring
  File "src/lxml/parser.pxi", line 1912, in lxml.etree._parseMemoryDocument
  File "src/lxml/parser.pxi", line 1793, in lxml.etree._parseDoc
  File "src/lxml/parser.pxi", line 1082, in lxml.etree._BaseParser._parseUnicodeDoc
  File "src/lxml/parser.pxi", line 615, in lxml.etree._ParserContext._handleParseResultDoc
  File "src/lxml/parser.pxi", line 725, in lxml.etree._handleParseResult
  File "src/lxml/parser.pxi", line 654, in lxml.etree._raiseParseError
  File "<string>", line 1
lxml.etree.XMLSyntaxError: Start tag expected, '<' not found, line 1, column 1

And the other hits, below:

Unfortunatly I can not interprete what the issue is and where to search next.
I would appriciate any inputs/ideas.

BR Christian

Hi,
since last time I have built a Raspberry Pi 4 based Home assistant. In this setup the Trafikverket weather station integration works great. So it seems something went wrong in the Pi3B+ environment. I will focus my efforts into migrating into the Pi4 instead of understanding the issue in the Pi3B+ environment.

Wish you all a Merry Christmas and a Happy New Year!