flopp999 / Tibber-Domoticz

Script to communicate with Tibber. Help me with a buy-me-a-coffee
https://www.buymeacoffee.com/flopp999
GNU General Public License v3.0
8 stars 4 forks source link

Too frequent reconnections to Tibber websocket API #59

Open toini opened 1 year ago

toini commented 1 year ago

Hi!

We're seeing a big number of web socket reconnects using user agent Domoticz/1.22. I'm assuming I found the correct repo?

Last hour I calculated 420 per hour for one client which is once every ten seconds - that's definitely not intended when using web sockets. You should connect only once and then listen to the data sent by the server.

Do you need any help fixing the client?

See best practices here: https://developer.tibber.com/docs/guides/calling-api

andre1975dekkers commented 1 year ago
Tibber-LOG

See log. Every 10s you will see Tibber Live power updated. I don't know if this is going well? Tibber says too many logins?I installed and got the API working a few days ago.Tibber Live power updated is refreshed every 10 seconds, but that's good, otherwise it won't work right? With a refresh of every 10 seconds, you do have the current data continuously.

toini commented 1 year ago

I'm only guessing here but it could be that something like this happens?

  1. Client connects
  2. Client waits for one data package
  3. Server pushes a package
  4. Client disconnects
  5. Client waits for 10 seconds
  6. Go to 1

This is what should happen:

  1. Client connects
  2. Client waits for data
  3. Server pushes a package
  4. Go to 2
flopp999 commented 1 year ago

Yes that is how I did. I don't use this anymore myself, all help is welcomed. I have never script a websocket that is still online after data is received and don't have time to learn.

toini commented 1 year ago

It looks like connection is closed every time a message is received? https://github.com/flopp999/Tibber-Domoticz/blob/main/plugin.py#L325

flopp999 commented 1 year ago

It looks like connection is closed every time a message is received? https://github.com/flopp999/Tibber-Domoticz/blob/main/plugin.py#L325

I am not sure that I use that. I just copied from an employee from Tibber to fix it quickly.

toini commented 1 year ago

I am not sure that I use that. I just copied from an employee from Tibber to fix it quickly.

If you got code from Tibber it probably might have originated from me. But disconnecting after every call back is definitely not correct.

You say that code bit might not be in use. How can I figure out what actually is in use?

andre1975dekkers commented 1 year ago

On https://github.com/flopp999/Tibber-Domoticz I have done the latest plugin.py in folder domoticz/plugins and requirements.txt. Then I restarted Domoticz. I don't see any difference in the Domoticz log. Every 10 seconds I see Tibber live power updated. What I can see in Domoticz VoltagePhase 1, VoltagePhase 2 and VoltagePhase 3 is refreshed every 10 seconds. Does that go well in the script?

pa5kt commented 1 year ago

You say that code bit might not be in use. How can I figure out what actually is in use?

I think what he means to say is that he is not using the plugin himself so he cannot debug and that the has not time available to spent rewriting everything.

I am using the plugin and I think it is very useful. I do not have the Pulse so I dont have realtime data, but getting the hour prices works fine.

I am not a programmer but I can read the code. I went through the program and I dont understand why that disconnect is in the callback. Would removing it change anything to the functionality of the plugin? And change the number of connects? My system only connects once per hour to get the hour prices.

toini commented 1 year ago

Do you have any pointers on how should i set up things to run this code on my computer locally?

Skjal commented 1 year ago

Install domoticz (www.domoticz.com) on your computer(Windows, Linux or rpi). Make a folder called Tibber-Domoticz in domoticz/plugins. Copy the plugin to domoticz/plugins/Tibber-Domoticz. Start domoticz and head to the hardware page. At the bottom of the page, you can choose a plugin to be installed. Select Tibber and fill in the info needed. Press add and you should find new devices on the setup/devices page. Thanks for having a go trying to fix this plugin.