core icon indicating copy to clipboard operation
core copied to clipboard

Tibber integration not working; server rejected WebSocket connection

Open Atlas553 opened this issue 2 years ago β€’ 2 comments

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

Atlas553 avatar Feb 23 '23 08:02 Atlas553

Hey there @danielhiversen, mind taking a look at this issue as it has been labeled with an integration (tibber) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of tibber can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign tibber Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


tibber documentation tibber source (message by IssueLinks)

home-assistant[bot] avatar Feb 23 '23 08:02 home-assistant[bot]

Same here. Troubleshooting I've tried so far:

  1. I've removed the Tibber integration
  2. created a new API key with Tibber.
  3. Recreated the Tibber integration with new API key: no sensor are showing up.

error log is showing the following error: websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 404 2023-02-23 11:19:15.528 DEBUG (MainThread) [tibber.tibber_home] Waiting for rt_connect

pingme01 avatar Feb 23 '23 10:02 pingme01

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

haraldkujat avatar Feb 27 '23 22:02 haraldkujat

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.

mcflexus avatar Feb 27 '23 22:02 mcflexus

Yes, newer versions of Home Assistant will not have real-time data before this is merged: https://github.com/home-assistant/core/pull/86940#issuecomment-1429235775

Danielhiversen avatar Feb 28 '23 06:02 Danielhiversen

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...

CommanderROR9 avatar Mar 01 '23 22:03 CommanderROR9

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...)

xorbital avatar Mar 02 '23 03:03 xorbital

Thanks! I followed your instructions and Tibber is working again!

Just one question though...do I have to remove the custom component when an official fix has been merged?

CommanderROR9 avatar Mar 02 '23 07:03 CommanderROR9

Yes, newer versions of Home Assistant will not have real-time data before this is merged: #86940 (comment)

@Danielhiversen do we need to make the workaround posted by @xorbital or we wait for the fix ASAP?

simonepittis avatar Mar 02 '23 08:03 simonepittis

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

marcmanusch avatar Mar 02 '23 08:03 marcmanusch

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

simonepittis avatar Mar 02 '23 08:03 simonepittis

Made a Rollback to 2.5 and waiting for working update πŸ‘

Schelin78 avatar Mar 02 '23 10:03 Schelin78

Made a Rollback to 2.5 and waiting for working update πŸ‘

Do you have an easy "how-to", for doing such rollback?

erikinoslo avatar Mar 02 '23 10:03 erikinoslo

Thanks! I followed your instructions and Tibber is working again!

Just one question though...do I have to remove the custom component when an official fix has been merged?

Yes, the custom component overrides home assistants built-in integration, so if you donβ€˜t remove it you wonβ€˜t receive any updates for tibber in the future. If 2023.3.1 came out with a fix just remove the folder and update.

xorbital avatar Mar 02 '23 11:03 xorbital

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?

hkroed avatar Mar 02 '23 13:03 hkroed

Made a Rollback to 2.5 and waiting for working update πŸ‘

Do you have an easy "how-to", for doing such rollback?

You should always (imo) make a fresh backup before upgrading to any HA release, especially the .0 releases. Rollback means just restoring to that backup (that's what I did and it fixed the integration)

dieugab avatar Mar 02 '23 14:03 dieugab

Do you have an easy "how-to", for doing such rollback?

Depends on your skill level as well as what version of HA you are running but I did this:

From SSH & Web Terminal Addon you can run the command:

ha core update --version 2023.2.5

edgein666 avatar Mar 02 '23 14:03 edgein666

Do you have an easy "how-to", for doing such rollback?

Depends on your skill level as well as what version of HA you are running but I did this:

From SSH & Web Terminal Addon you can run the command:

ha core update --version 2023.2.5

Do you know which version you ran before the downgrade? Home Assistant 2023.3.0? Worried about potential db upgrade/migrations that happened after 2023.2.5.

rschildmeijer avatar Mar 02 '23 15:03 rschildmeijer

Do you have an easy "how-to", for doing such rollback?

Depends on your skill level as well as what version of HA you are running but I did this:

From SSH & Web Terminal Addon you can run the command:

ha core update --version 2023.2.5

Do you know which version you ran before the downgrade? Home Assistant 2023.3.0? Worried about potential db upgrade/migrations that happened after 2023.2.5.

rschildmeijer avatar Mar 02 '23 15:03 rschildmeijer

Made a Rollback to 2.5 and waiting for working update πŸ‘

Do you have an easy "how-to", for doing such rollback?

You should always (imo) make a fresh backup before upgrading to any HA release, especially the .0 releases. Rollback means just restoring to that backup (that's what I did and it fixed the integration)

Hi. Yes I always do backup after every change I do to system. So latest backup was 1 day old. Now that backup is restored, and we are all a happy smiling family here at home. For info: restore took approx. 1 h, before it was fully back. Thanks for info and help!

erikinoslo avatar Mar 02 '23 17:03 erikinoslo

Works with 2023.3.1

torge70 avatar Mar 03 '23 09:03 torge70

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.