pyTibber
pyTibber copied to clipboard
pyTibber always loses tibber connection after some time
I have a simple script that connects to tibber server and print my energy consumption forever. Always after around 30 Minutes, sometimes more or less the script loses the connection and never succeeds in reconnecting again. When i kill the script and start it again it will again work for something like 30 Minutes. Any Ideas how i can improve the behaviour ?
Error:
Watchdog: Connection is down, 2023-11-28 16:23:45.302878 Error in watchdog connect, retrying in 45 seconds, 1 Watchdog: Connection is down, 2023-11-28 16:24:35.578354 Error in watchdog connect, retrying in 51 seconds, 2 Traceback (most recent call last): File "/home/ado/.local/lib/python3.10/site-packages/tibber/realtime.py", line 157, in _watchdog await self._resubscribe_homes() File "/home/ado/.local/lib/python3.10/site-packages/tibber/realtime.py", line 178, in _resubscribe_homes await asyncio.gather(*[home.rt_resubscribe() for home in self._homes]) File "/home/ado/.local/lib/python3.10/site-packages/tibber/home.py", line 473, in rt_resubscribe await asyncio.gather( File "/home/ado/.local/lib/python3.10/site-packages/tibber/home.py", line 202, in update_info if data := await self._tibber_control.execute(UPDATE_INFO % self._home_id): File "/home/ado/.local/lib/python3.10/site-packages/tibber/__init__.py", line 104, in execute resp = await self.websession.post(API_ENDPOINT, **post_args) File "/home/ado/.local/lib/python3.10/site-packages/aiohttp/client.py", line 400, in _request raise RuntimeError("Session is closed") RuntimeError: Session is closed Watchdog: Connection is down, 2023-11-28 16:25:31.860971 Error in watchdog connect, retrying in 16 seconds, 3 Traceback (most recent call last): File "/home/ado/.local/lib/python3.10/site-packages/tibber/realtime.py", line 157, in _watchdog await self._resubscribe_homes() File "/home/ado/.local/lib/python3.10/site-packages/tibber/realtime.py", line 178, in _resubscribe_homes await asyncio.gather(*[home.rt_resubscribe() for home in self._homes]) File "/home/ado/.local/lib/python3.10/site-packages/tibber/home.py", line 473, in rt_resubscribe await asyncio.gather( File "/home/ado/.local/lib/python3.10/site-packages/tibber/home.py", line 202, in update_info if data := await self._tibber_control.execute(UPDATE_INFO % self._home_id): File "/home/ado/.local/lib/python3.10/site-packages/tibber/__init__.py", line 104, in execute resp = await self.websession.post(API_ENDPOINT, **post_args) File "/home/ado/.local/lib/python3.10/site-packages/aiohttp/client.py", line 400, in _request raise RuntimeError("Session is closed") RuntimeError: Session is closed ^CTraceback (most recent call last): File "/home/ado/tibb/./tib7.py", line 34, in <module> loop.run_until_complete(run()) File "/usr/lib/python3.10/asyncio/base_events.py", line 636, in run_until_complete self.run_forever() File "/usr/lib/python3.10/asyncio/base_events.py", line 603, in run_forever self._run_once() File "/usr/lib/python3.10/asyncio/base_events.py", line 1871, in _run_once event_list = self._selector.select(timeout) File "/usr/lib/python3.10/selectors.py", line 469, in select fd_event_list = self._selector.poll(timeout, max_ev) KeyboardInterrupt
Script:
`#!/usr/bin/python3
import tibber.const import tibber import asyncio import aiohttp import json import pprint
access_token = "xx"
ACCESS_TOKEN = access_token
def _callback(pkg): data = pkg.get("data") if data is None: return
print(data.get("liveMeasurement"))
power=data.get("liveMeasurement").get("power");
print(power)
async def run(): async with aiohttp.ClientSession() as session: tibber_connection = tibber.Tibber(ACCESS_TOKEN, websession=session, user_agent="change_this") await tibber_connection.update_info() home = tibber_connection.get_homes()[0] await home.rt_subscribe(_callback)
while True:
await asyncio.sleep(10)
loop = asyncio.get_event_loop() loop.run_until_complete(run()) `
I have the same problem. Were you able to solve it?
No, I did not solve it, no idea. I hope Daniel will have an idea what to do when he updates the code next time ..
I have the same problem as well.
On my side it seems the session was closed somehow and I do not find a recovery strategy in the code to handle that situation:
ERROR:tibber.realtime:Watchdog: Connection is down, 2024-01-01 08:38:26.302279
ERROR:tibber.realtime:Error in watchdog connect, retrying in 730 seconds, 28
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/tibber/realtime.py", line 157, in _watchdog
await self._resubscribe_homes()
File "/usr/local/lib/python3.10/site-packages/tibber/realtime.py", line 178, in _resubscribe_homes
await asyncio.gather(*[home.rt_resubscribe() for home in self._homes])
File "/usr/local/lib/python3.10/site-packages/tibber/home.py", line 473, in rt_resubscribe
await asyncio.gather(
File "/usr/local/lib/python3.10/site-packages/tibber/home.py", line 202, in update_info
if data := await self._tibber_control.execute(UPDATE_INFO % self._home_id):
File "/usr/local/lib/python3.10/site-packages/tibber/__init__.py", line 104, in execute
resp = await self.websession.post(API_ENDPOINT, **post_args)
File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 421, in _request
raise RuntimeError("Session is closed")
The same problem here. After some time the connection closes and all internal retries will not work and it loops then with a retry connect with 1200s delay which never ends. Any help is appreciated!
I am facing the same problem. The real-time web socket connection stops after running a few minutes. Is there a rest API to get the realtime data without the web socket?
I rather wanted to "tweak" the tibber pulse to either report to my own MQTT broker to get direct access to live data or have my existing smartreader header send to tibber (I'm not a fan of using any internet services outside my house for home automation). But I gave up on that idea after a whole day trying. So I ended up here.
So, same problem pyTibber doesn't have a reconnect strategy it seems for live data. It seems one must handle this in their own code, sigh.
Same problem here... as a workaround i automatically redeploy my containers, but i'd rather not have to do this. Did anyone find a solution?