BeatsuDev / tibber.py

An UNOFFICIAL python wrapper for the nordic electricity company Tibber's API.
MIT License
17 stars 2 forks source link

[FEATURE] Live data from more than one home #26

Open TerjeMyk opened 1 year ago

TerjeMyk commented 1 year ago

Hi

I have 2 home with pulser. I writing a program in python so I can look at the realtime use.

But I only get data from 1 of the homes.

I get:

Connection to websocket failed... Retrying in 10 seconds... received 4429 (private use) Too many open connections on this server: 2; then sent 4429 (private use) Too many open connections on this server: 2

This is probably me that has tried to mutch.

WHAT IS THE CORRECT WAY TO GET REALTIME DATA FROM MORE THAN 1 HOME?

Here is my code:

import tibber import init

account = tibber.Account(init.GetTibberKey()) home0 = account.homes[0] home1 = account.homes[1]

@home0.event("live_measurement") def show_accumulated_cost(data): print(f"0 - {data.power} {data.power_production}")

@home1.event("live_measurement") def show_accumulated_cost1(data): print(f"1 - {data.power} {data.power_production}")

if name == 'main':

Start the live feed. This runs forever.

home0.start_live_feed()
home1.start_live_feed()
BeatsuDev commented 1 year ago

Hi, I will look into adding support for multiple homes in one script. For now, you could try splitting each home into separate scripts and see if that works. About the connection issue; I am still trying to figure that one out... There is a similar issue that has been brought up which is probably the same issue you are experiencing. I will be a bit busy the next week but will try to find the problem as soon as I have time!

BeatsuDev commented 1 year ago

Hi, could you try updating to the newest version of tibber (version 0.3.0) and see how it goes? Run:

pip install --upgrade tibber.py

You will still have to split your two homes into two separate scripts for now, but the connection limit error/bug should be fixed or at least improved in the newest version!

home0.py:

import tibber
import init

account = tibber.Account(init.GetTibberKey())
home = account.homes[0]

@home.event("live_measurement")
def show_accumulated_cost(data):
  print(f"0 - {data.power} {data.power_production}")

if __name__ == '__main__':
  home.start_live_feed()

home1.py:

import tibber
import init

account = tibber.Account(init.GetTibberKey())
home = account.homes[1]

@home.event("live_measurement")
def show_accumulated_cost(data):
  print(f"0 - {data.power} {data.power_production}")

if __name__ == '__main__':
  home.start_live_feed()
BeatsuDev commented 1 year ago

The connection limit issue should be fixed now. See issue #23 if the problem persists.

Although you should be able to run multiple homes with the above steps, I'll keep this issue open since adding support for multiple homes in a single file still seems like a potentially nice idea!