core: Tibber integration not working; server rejected WebSocket connection

The problem

After updating to the newest beta, the integration stopped working.

What version of Home Assistant Core has the issue?

2023.3.0b0

What was the last working version of Home Assistant Core?

2023.2.5

What type of installation are you running?

Home Assistant OS

Integration causing the issue

tibber

Link to integration documentation on our website

https://rc.home-assistant.io/integrations/tibber

Diagnostics information

Logger: tibber
Source: /usr/local/lib/python3.10/site-packages/tibber/__init__.py:181
First occurred: 9:06:34 AM (16 occurrences)
Last logged: 9:27:58 AM

Error in watchdog connect, retrying in 69 seconds, 9
Error in watchdog connect, retrying in 84 seconds, 10
Error in watchdog connect, retrying in 139 seconds, 11
Error in watchdog connect, retrying in 172 seconds, 12
Error in watchdog connect, retrying in 169 seconds, 13
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/tibber/__init__.py", line 173, in _rt_watchdog
    await self.sub_manager.connect_async()
  File "/usr/local/lib/python3.10/site-packages/gql/client.py", line 632, in connect_async
    await self.transport.connect()
  File "/usr/local/lib/python3.10/site-packages/gql/transport/websockets_base.py", line 490, in connect
    self.websocket = await asyncio.wait_for(
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 650, in _wrap_awaitable
    return (yield from awaitable.__await__())
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/client.py", line 659, in __await_impl_timeout__
    return await asyncio.wait_for(self.__await_impl__(), self.open_timeout)
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 445, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/client.py", line 666, in __await_impl__
    await protocol.handshake(
  File "/usr/local/lib/python3.10/site-packages/websockets/legacy/client.py", line 332, in handshake
    raise InvalidStatusCode(status_code, response_headers)
websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 404

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 9
  • Comments: 22 (1 by maintainers)

Most upvoted comments

I hope someone can fix this quickly…I use Tibber and the Pulse in a few of my automations and they are now all dead in the water. If there is a workaround I can implement myself as a stopgap measure then I would love to hear about it…

You can do the following to get the sensors working again (probably requires home assistant >=2023.3.0):

  1. Go to https://minhaskamal.github.io/DownGit/#/home
  2. Enter https://github.com/home-assistant/core/tree/dev/homeassistant/components/tibber as the URL
  3. Press “Download”
  4. Create a new folder (if it doesn’t already exist) in Home Assistants config folder called custom_components
  5. Create a new folder in config/custom_components called tibber
  6. Paste the contents of the downloaded archive into the tibber folder
  7. Open the unpacked manifest.json and change it to:
{
  "domain": "tibber",
  "name": "Tibber",
  "codeowners": ["@danielhiversen"],
  "config_flow": true,
  "dependencies": ["recorder"],
  "documentation": "https://www.home-assistant.io/integrations/tibber",
  "iot_class": "cloud_polling",
  "loggers": ["tibber"],
  "quality_scale": "silver",
  "requirements": ["pyTibber==0.27.1"],
  "version": "1.0.0"
}
  1. Restart Home Assistant

This forces Home Assistant to use of the latest version of the pytibber library.
You can also create sensors to fetch information manually.
Sadly the consumption data requires a websocket subscription, so you’re limited to price information.
This sensor will fetch an array of todays and tomorrows prices:

# in configuration.yaml
rest:
  - resource: https://api.tibber.com/v1-beta/gql
    method: POST
    scan_interval: 2400
    timeout: 60
    payload: '{ "query": "{ viewer { homes { currentSubscription { priceInfo { current{total} today { total startsAt } tomorrow { total startsAt }}}}}}" }'
    headers:
      Authorization: !secret Tibber_API
      Content-Type: application/json
      User-Agent: REST
    sensor:
      - name: Tibber prices
        json_attributes_path: "$.data.viewer.homes[0].currentSubscription.priceInfo"
        json_attributes:
          - today
          - tomorrow
        value_template: Ok

Make sure to replace !secret Tibber_API with your API key (starts with Bearer…)

I hope someone can fix this quickly…I use Tibber and the Pulse in a few of my automations and they are now all dead in the water. If there is a workaround I can implement myself as a stopgap measure then I would love to hear about it…

Works with 2023.3.1

All sensors stop working :S we need a fix ASAP!

Workaround fixes it… waiting for the fix in the core.

https://github.com/home-assistant/core/issues/88656#issuecomment-1451245229

I just did some local testing and updating the manifest to pyTibber==0.27.1 is confirmed to be working again. Im not sure how to make a pull request as i havn`t before. I can give it a try tomorrow but if someone can do it faster feel free to do so.

I hope someone can fix this quickly…I use Tibber and the Pulse in a few of my automations and they are now all dead in the water. If there is a workaround I can implement myself as a stopgap measure then I would love to hear about it…

You can do the following to get the sensors working again (probably requires home assistant >=2023.3.0):

  1. Go to https://minhaskamal.github.io/DownGit/#/home
  2. Enter https://github.com/home-assistant/core/tree/dev/homeassistant/components/tibber as the URL
  3. Press “Download”
  4. Create a new folder (if it doesn’t already exist) in Home Assistants config folder called custom_components
  5. Create a new folder in config/custom_components called tibber
  6. Paste the contents of the downloaded archive into the tibber folder
  7. Open the unpacked manifest.json and change it to:
{
  "domain": "tibber",
  "name": "Tibber",
  "codeowners": ["@danielhiversen"],
  "config_flow": true,
  "dependencies": ["recorder"],
  "documentation": "https://www.home-assistant.io/integrations/tibber",
  "iot_class": "cloud_polling",
  "loggers": ["tibber"],
  "quality_scale": "silver",
  "requirements": ["pyTibber==0.27.1"],
  "version": "1.0.0"
}
  1. Restart Home Assistant

This forces Home Assistant to use of the latest version of the pytibber library. You can also create sensors to fetch information manually. Sadly the consumption data requires a websocket subscription, so you’re limited to price information. This sensor will fetch an array of todays and tomorrows prices:

# in configuration.yaml
rest:
  - resource: https://api.tibber.com/v1-beta/gql
    method: POST
    scan_interval: 2400
    timeout: 60
    payload: '{ "query": "{ viewer { homes { currentSubscription { priceInfo { current{total} today { total startsAt } tomorrow { total startsAt }}}}}}" }'
    headers:
      Authorization: !secret Tibber_API
      Content-Type: application/json
      User-Agent: REST
    sensor:
      - name: Tibber prices
        json_attributes_path: "$.data.viewer.homes[0].currentSubscription.priceInfo"
        json_attributes:
          - today
          - tomorrow
        value_template: Ok

Make sure to replace !secret Tibber_API with your API key (starts with Bearer…)

Works (Y) Should this folder be removed after update?

All sensors stop working :S we need a fix ASAP!

The Tibber status page says:

API/HA - Tibber API will not work with the latest HA update

Monitoring - Home assistant can currently connect to websockets only when they specify user agent HomeAssistant/2022.12, HomeAssistant/2023.1 or HomeAssistant/2023.2. HomeAssistant/2023.3 wont be able to connect unless it will start using the pyTibber version 0.27. (Currently it uses 0.26). Feb 14, 2023 - 08:20 CET