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

Subscription #14

Closed DeVille70 closed 2 years ago

DeVille70 commented 3 years ago

Any chance you could expand to also support subscription, please? subscription{ liveMeasurement(homeId:"c70dcbe5-4485-4821-933d-a8a86452737b"){ timestamp power
maxPower } }

flopp999 commented 3 years ago

I do not have live data for my house. Is this your ID, then I can use that to try to solve it?

DeVille70 commented 3 years ago

It is not my ID, it is the test ID provided by Tibber, on https://developer.tibber.com/explorer

If you need a real ID, you can have mine also.

Excellent if you could do this, thanks.

flopp999 commented 3 years ago

It seems to work with Demo so I will use that. Will get back here when I have a solution

DeVille70 commented 3 years ago

👍

flopp999 commented 3 years ago

try this, but please make a backup of your Domoticz folder before you use this code https://github.com/flopp999/Tibber-Domoticz/tree/subscription-beta

flopp999 commented 3 years ago

You may need to install python3 packages gql and asyncio

I installed gql by using this command

sudo pip3 install --pre gql[all]

flopp999 commented 3 years ago

I got two errors every hour at minute 00. I think this is because of backup is running at the same time and DZ is "frozen" for a short while.

Please use my Tibber-link if you do not have used a code already

https://tibber.com/se/invite/8af85f51

DeVille70 commented 3 years ago

Thanks for the updates, I will try it out when I come tonight.

Sorry, already used a code. :(

DeVille70 commented 3 years ago

So, followed the instructions here and at https://github.com/flopp999/Tibber-Domoticz/tree/subscription-beta That created three devices, Tibber - Current Price, Tibber - Mean Price, and Tibber - Current Price incl. fee

I cannot see any power device - I must have missed something.

flopp999 commented 3 years ago

strange, no errors in DZ log? if you enable Debug, it will create a file in domoticz/plugin/Tibber, namned Tibber.log, can you upload the text from that?

DeVille70 commented 3 years ago

No errors in DZ log.

Tibber.log: 2021-03-09 19:57:04.727933 onStart 2021-03-09 19:57:04.990018 Entered CheckInternet 2021-03-09 19:57:04.991092 Try ping 2021-03-09 19:57:05.437289 Ping done 2021-03-09 19:57:05.438421 Entered CheckInternet 2021-03-09 19:57:05.439072 Try ping 2021-03-09 19:57:05.863010 Ping done 2021-03-09 19:57:05.988434 Current Price Updated 2021-03-09 19:57:06.052449 Mean Price Updated 2021-03-09 19:57:15.373577 onHeartbeat 2021-03-09 19:57:25.394924 onHeartbeat 2021-03-09 19:57:35.416730 onHeartbeat 2021-03-09 19:57:45.388325 onHeartbeat 2021-03-09 19:57:55.409987 onHeartbeat 2021-03-09 19:58:05.381404 onHeartbeat 2021-03-09 19:58:15.402594 onHeartbeat 2021-03-09 19:58:25.423251 onHeartbeat 2021-03-09 19:58:35.394572 onHeartbeat 2021-03-09 19:58:45.416058 onHeartbeat 2021-03-09 19:58:55.388033 onHeartbeat 2021-03-09 19:59:05.410784 onHeartbeat

flopp999 commented 3 years ago

So, followed the instructions here and at https://github.com/flopp999/Tibber-Domoticz/tree/subscription-beta That created three devices, Tibber - Current Price, Tibber - Mean Price, and Tibber - Current Price incl. fee

I have now updated the instruction, it will create six devices

flopp999 commented 3 years ago

what version is displayed in Domoticz-Hardware?

DeVille70 commented 3 years ago

Tibber API 0.85

Just stop and start DZ to add the additional devices?

flopp999 commented 3 years ago

stop Tibber hardware in DZ, put new file/code in Tibber folder, then start Tibber hardware in DZ again

flopp999 commented 3 years ago

Tibber API 0.85

Just stop and start DZ to add the additional devices?

Should have been 0.86

DeVille70 commented 3 years ago

Don't seem to get any more devices

flopp999 commented 3 years ago

does it now show 0.86? any erros in DZ log? how does Debug file for Tibber look like?

DeVille70 commented 3 years ago

Still 0.85

2021-03-09 20:15:30.796045 onStart 2021-03-09 20:15:31.062705 Entered CheckInternet 2021-03-09 20:15:31.063739 Try ping 2021-03-09 20:15:31.501657 Ping done 2021-03-09 20:15:31.502879 Entered CheckInternet 2021-03-09 20:15:31.503533 Try ping 2021-03-09 20:15:33.387344 Ping done 2021-03-09 20:15:33.514101 Current Price Updated 2021-03-09 20:15:33.628304 Mean Price Updated 2021-03-09 20:15:42.398108 onHeartbeat 2021-03-09 20:15:52.421948 onHeartbeat 2021-03-09 20:16:02.394329 onHeartbeat 2021-03-09 20:16:12.416547 onHeartbeat 2021-03-09 20:16:22.438464 onHeartbeat 2021-03-09 20:16:32.409982 onHeartbeat 2021-03-09 20:16:42.431533 onHeartbeat 2021-03-09 20:16:52.403027 onHeartbeat 2021-03-09 20:17:02.425236 onHeartbeat 2021-03-09 20:17:12.448194 onHeartbeat 2021-03-09 20:17:22.419724 onHeartbeat 2021-03-09 20:17:32.441182 onHeartbeat 2021-03-09 20:17:42.412666 onHeartbeat 2021-03-09 20:17:52.434388 onHeartbeat 2021-03-09 20:18:02.455981 onHeartbeat 2021-03-09 20:18:12.427586 onHeartbeat 2021-03-09 20:18:22.450027 onHeartbeat 2021-03-09 20:18:32.422228 onHeartbeat 2021-03-09 20:18:42.443398 onHeartbeat 2021-03-09 20:18:52.465367 onHeartbeat 2021-03-09 20:19:02.437690 onHeartbeat 2021-03-09 20:19:12.459685 onHeartbeat 2021-03-09 20:19:22.431474 onHeartbeat 2021-03-09 20:19:32.453463 onHeartbeat 2021-03-09 20:19:42.475667 onHeartbeat 2021-03-09 20:19:52.446952 onHeartbeat 2021-03-09 20:20:02.468403 onHeartbeat 2021-03-09 20:20:12.439678 onHeartbeat

No errors in DZ log

flopp999 commented 3 years ago

hmm, then you do not have the correct file from Git you clone the main branch

try this when you are in domoticz/plugin-folder

git clone -b subscription-beta https://github.com/flopp999/Tibber-Domoticz.git Tibber

DeVille70 commented 3 years ago

Yes, 0.86 and six devices

flopp999 commented 3 years ago

please put any error that you get, in this issue I know that every hour at minute 00 your will one or two errors

flopp999 commented 3 years ago

you also need to change the Token, to your own, inside plugin.py after you changed it and save the changes, restart Tibber hardware

DeVille70 commented 3 years ago

Yes, will do, thanks. Do I not change Token in Domoticz hardware?

flopp999 commented 3 years ago

Yes, will do, thanks. Do I not change Token in Domoticz hardware?

sorry, change HomeID in plugin.py. I will add this ass a text field in the stable version

DeVille70 commented 3 years ago

Ok

flopp999 commented 3 years ago

sorry, you also need to change the Token inside plugin.py at line 264

headers={'Authorization': 'YOURTOKEN'}

DeVille70 commented 3 years ago

Ok

flopp999 commented 3 years ago

do you get your own Power in real-time?

DeVille70 commented 3 years ago

Yes, I do, and it seems to follow quite nicely what I get in the Tibber app. I will keep it running, and report any animalities. Much appreciated, how can I buy you a coffee? :)

flopp999 commented 3 years ago

thank you, I just created a link :)

please use this link

https://www.buymeacoffee.com/flopp999

flopp999 commented 3 years ago

Thank a lot @DeVille70

i have the solution for the timeouterror, today ot tomorrow it will be in the main branch for download

DeVille70 commented 3 years ago

👍

Danielhiversen commented 3 years ago

Great work!

sorry, change HomeID in plugin.py. I will add this ass a text field in the stable version

You can get the HomeID with:


{
  viewer {
    homes {
      id
    }
  }
}

So the user does not need to add it manually.

Btw, it is also important to close the websocket connection when Domoticz exits, since you can have max 3 open connections to Tibber.

Regards Daniel (author of the Tibber integration in Home Assistant)

flopp999 commented 3 years ago

@Danielhiversen thank you.

I also got that idea to get the HomeID from API, I created an issue yesterday so I will not forget it :)

Exit: OK very good information, I will take a look at it. I am a hobby/amateur programmer but I will check how to exit or if async is doing that automatically. I copy/paste until it works and THEN I start to understand how it works :)

flopp999 commented 3 years ago

@Danielhiversen

Btw, it is also important to close the websocket connection when Domoticz exits, since you can have max 3 open connections to Tibber.

it seems that it will close itself, but very nice of you to see this :)
https://github.com/graphql-python/gql/blob/master/gql/transport/aiohttp.py#L103

DeVille70 commented 3 years ago

It has been running steadily now for a few days, and I cannot see any defects at all, timeout or otherwise. Looks good.

flopp999 commented 3 years ago

Thank you for feedback. Then it seems to work fine. I found a solution to hide all error messages, maybe I will work more with that feature so the user know what the problem is

DeVille70 commented 3 years ago

It should perhaps be mentioned in the instructions that Token and HomeId must be amended in plugin.py.

flopp999 commented 3 years ago

Yes, I have now released a new version that give the user an option if Pulse is installed or not and also getting HomeID from Tibber API Thank you

DeVille70 commented 3 years ago

👍

flopp999 commented 3 years ago

@DeVille70 I have a beta if you would like to test it? It is checking if Power is possible to fetch from Tibber, if Yes it will continue to do that every 10 seconds, if Not it will never try again, until you restart Domoticz or Tibber Hardware. What do you think about this?

DeVille70 commented 3 years ago

That sounds user friendly. Sure, I'll be happy to try it out.

flopp999 commented 3 years ago

@DeVille70 this is the beta with automatic check if Power can be fetch
https://github.com/flopp999/Tibber-Domoticz/tree/0.90

DeVille70 commented 3 years ago

It worked quite nicely, but after a few minutes power no longer updated. In Domoticz log: 2021-03-15 20:28:05.747 (Tibber) Something went wrong during getting Power from Tibber. Is Tibber Pulse installed? Restarting Domoticz fixed it, but only for a few minutes until same error again.

Also, when running, it is not collecting every 10 sec, more like 12-13 sec. 2021-03-15 20:35:55.304832 onHeartbeat 2021-03-15 20:36:07.954908 onHeartbeat 2021-03-15 20:36:21.323611 onHeartbeat 2021-03-15 20:36:32.985344 onHeartbeat 2021-03-15 20:36:45.562965 onHeartbeat 2021-03-15 20:36:58.098348 onHeartbeat 2021-03-15 20:37:11.870904 onHeartbeat 2021-03-15 20:37:23.498029 onHeartbeat 2021-03-15 20:37:35.779368 onHeartbeat 2021-03-15 20:37:48.009115 onHeartbeat 2021-03-15 20:38:01.745713 onHeartbeat 2021-03-15 20:38:09.797572 Something went wrong during getting Power from Tibber

flopp999 commented 3 years ago

Thanks. I think I will add check if the first or second run gets Power from Tibber it means that it exists and then it shall ask for it every heartbeat, which is around every 10 second. Thank you so far. I will update and write to you again, if you would like to test it again.

DeVille70 commented 3 years ago

Sure, no problem.

flopp999 commented 3 years ago

@DeVille70 please try when you got time, 0.90 is now updated and will check for Tibber Pulse on first run If it gets a value from Tibber it will try forever to get it If it not get Power from Tibber it will not try again until restart

Danielhiversen commented 3 years ago

You can check if user has Pulse/watty with:

{
  viewer {
    homes {
      features{
        realTimeConsumptionEnabled
      }

    }
  }
}
flopp999 commented 3 years ago

You can check if user has Pulse/watty with:

{
  viewer {
    homes {
      features{
        realTimeConsumptionEnabled
      }

    }
  }
}

Thanks that will help me a lot 👍😃