flopp999/Tibber-Domoticz

Subscription

Closed this issue Β· 87 comments

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

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

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.

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

πŸ‘

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

You may need to install python3 packages
gql and asyncio

I installed gql by using this command

sudo pip3 install --pre gql[all]

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

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

Sorry, already used a code. :(

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.

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?

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

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

what version is displayed in Domoticz-Hardware?

Tibber API 0.85

Just stop and start DZ to add the additional devices?

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

Tibber API 0.85

Just stop and start DZ to add the additional devices?

Should have been 0.86

Don't seem to get any more devices

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

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

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

Yes, 0.86 and six devices

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

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

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

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

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

headers={'Authorization': 'YOURTOKEN'}

do you get your own Power in real-time?

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? :)

thank you, I just created a link :)

please use this link

https://www.buymeacoffee.com/flopp999

Thank a lot @DeVille70

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

πŸ‘

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)

@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 :)

@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

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

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

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

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

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

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

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

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.

Sure, no problem.

@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

You can check if user has Pulse/watty with:

{
  viewer {
    homes {
      features{
        realTimeConsumptionEnabled
      }

    }
  }
}

You can check if user has Pulse/watty with:

{
  viewer {
    homes {
      features{
        realTimeConsumptionEnabled
      }

    }
  }
}

Thanks that will help me a lot πŸ‘πŸ˜ƒ

Ok, I guess you want to change it then, but it seems to be running fine now.

@DeVille70 updated again, please try when you got time
thanks

Yes, will do. Very busy at the moment, but hopefully tonight.

Sorry for the long delay, I have been very busy.
Installed the new script, and it has been running for a few minutes now. Looks good. :)

Proposal for future versions: The Tibber subscription also offers the variables minPower, averagePower, and maxPower. Not sure I see any use of those for myself at the moment, but perhaps others will.

I also saw that there are a lot more.

Please have a look here and tell me if you need more data. It is fun to add features :)

Do you have solar cell at home?
I want to add data for production as well.

https://developer.tibber.com/docs/reference

Wow, that was a long list, I was not aware of that.
Perhaps the ones I mentioned as well as PriceLevel.

Not sure what the negative effects on Domoticz and the RPi of loading too much data every 10-12 seconds would be, though.

No, I have no solar cells.

I will add your proposals.
I only collect data once per hour, let’s start with this and see if that is enough.
Otherwise I can collect more often for maxPower and other that may change often.
Price and PriceLevel will only change every hour
Thanks for your input

πŸ‘

@DeVille70
I have now updated branch 0.90 with 5 new devices.
The 3 that you "asked" for and also accumulated cost and accumulated consumption.
If you got time to test I'll be happy :)

It looks good.

The 5 new devices did not update until after close to an hour, but I guess that is as intended.

Great work!

Thank you. Correct, the new devices will update next minute 0, or if you restart Hardware twice.
Will fix this in the future.

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)

More than one house
I have a house and a cabin, both with power from Tibber. Would be nice to be able to input home ID or address in order to select the location of interest. As it is now, it apears that the first house in houses is selected

Sugestion:
Allow for home ID as optional input

If no home ID is given:
    Find home ID of first house in houses
else:
    Find the house in houses with the given home ID
    Use the house found

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)

More than one house
I have a house and a cabin, both with power from Tibber. Would be nice to be able to input home ID or address in order to select the location of interest. As it is now, it apears that the first house in houses is selected

Sugestion:
Allow for home ID as optional input

If no home ID is given:
    Find home ID of first house in houses
else:
    Find the house in houses with the given home ID
    Use the house found

I think I can do a solution.
Please create a new issue with the request.
This issue is solved and long :)

Sorry to bug you again. This plugin has worked excellently since March, but after a crash I partially had to rebuild my system. Installing this plugin does not go so well. No devices are created, and even if I select Tibber API 1.11 it comes up as Tibber API 0.89. Any advise to share, please?

From Domoticz log:
2022-01-05 14:34:58.510 Error: Tibber: (Tibber) failed to load 'plugin.py', Python Path used was '/home/pi/domoticz/plugins/Tibber-Domoticz/:/usr/lib/python37.zip:/usr/lib/python3.7:/usr/lib/python3.7/lib-dynload:/usr/local/lib/python3.7/dist-packages:/usr/lib/python3/dist-packages:/usr/lib/python3.7/dist-packages'.
2022-01-05 14:34:58.510 Error: Tibber: (Tibber) Module Import failed, exception: 'ModuleNotFoundError'
2022-01-05 14:34:58.510 Error: Tibber: (Tibber) Module Import failed: ' Name: python_graphql_client'
2022-01-05 14:34:58.510 Error: Tibber: (Tibber) Error Line details not available.

I have had other people also having problem since yesterday. I don't know why, maybe an update for a package?
Anyway please update again to 1.12, I just did a change in 1.11
Please tell me how it goes :)

Thanks for quick response.
So I replace the plugin.py file, and restart Domoticz. Then plugin version 1.12 is available to install, but after installation it shows up as 0.89 in Hardware list. And no devices are installed.

From Domoticz log:
2022-01-05 15:03:34.102 Error: Tibber 1.12: (Tibber) failed to load 'plugin.py', Python Path used was '/home/pi/domoticz/plugins/Tibber-Domoticz/:/usr/lib/python37.zip:/usr/lib/python3.7:/usr/lib/python3.7/lib-dynload:/usr/local/lib/python3.7/dist-packages:/usr/lib/python3/dist-packages:/usr/lib/python3.7/dist-packages'.
2022-01-05 15:03:34.102 Error: Tibber 1.12: (Tibber 1.12) Module Import failed, exception: 'SyntaxError'
2022-01-05 15:03:34.102 Error: Tibber 1.12: (Tibber 1.12) Import detail: File: /home/pi/domoticz/plugins/Tibber-Domoticz/plugin.py, Line: 49, offset: -1
2022-01-05 15:03:34.102 Error: Tibber 1.12: (Tibber 1.12) Error Line '"""

Please restart DZ.
Did you copy the text and paste or did you download the file and replaced the file?

Restarted Domoticz, but to no change.

I copied and pasted text into the file, yes. I have limited linux skills, and the Windows tool i use for file browsing had access problems.

OK, because I think some of the text was copied/pasted in wrong way.
Please try to copy the text as raw from Github or replace the file(recommended)

Ok, I copied via raw into a new file, and now 8 devices showed up. But they are all about power, and one about signal strength, and the ones I had before with min, max, and current price are no longer there. Has the plugin changed function?

Ok, prices perhaps comes only every midnight. But power updates is much rarer now, every 30 s or so. And still reports API version 0.89 in Hardware.

Ok, I copied via raw into a new file, and now 8 devices showed up. But they are all about power, and one about signal strength, and the ones I had before with min, max, and current price are no longer there. Has the plugin changed function?

Depends how old the other version was.
I think I changed ID for the devices around version 0.75.
Otherwise it shall give you lots of devices, if you have a Real-time sensor

Ok, prices perhaps comes only every midnight. But power updates is much rarer now, every 30 s or so. And still reports API version 0.89 in Hardware.

Did the prices came up?
Yes, I changed so it will update Real-time data every 10 seconds and it will only update ~10 devices then after 10 seconds another 10 devices and so on.
Restart DZ to see the correct version under Hardware.
In DZ log when you start the plugin it should give 1.12

I have 17 Tibber devices, but none of them are prices.
The device Tibber-power only updates every 30 seconds.
In hardware still says 0.89.
Under Home ID it only says Yes, no actual ID

From Domoticz log:
2022-01-07 07:20:37.795 Error: Tibber: (Tibber) 'onMessage' failed 'TypeError':''NoneType' object is not subscriptable'.
2022-01-07 07:20:37.795 Error: Tibber: (Tibber) ----> Line 500 in '/home/pi/domoticz/plugins/Tibber-Domoticz/plugin.py', function onMessage
2022-01-07 07:20:37.795 Error: Tibber: (Tibber) ----> Line 265 in '/home/pi/domoticz/plugins/Tibber-Domoticz/plugin.py', function onMessage

Strange that it still says 0.89.

Can you try to replace plugin.py again.

Check that you copy the file from Main branch on GitHub

The old plugin folder, with 0.89 is still there, and I am not able to delete it. So it seems that the plugin.py from the old folder is read, even though I select 1.12. In fact, it seems both plugin.py files are read, because in the hardware page pretty much all information is displayed twice.
image

Why can't you not delete it?
try "sudo rm -r [folder name]"

if there is two folder with same plugin-name(inside plugin.py) it can be strange behavior

I had tried sudo rm before but -r seems to to do the trick. Now 1.12 shows up in hardware. But power updates only every 30 secs and no prices. I'll leave it until tomorrow and see then.

Thanks so far.

Restarting Domoticz:
2022-01-11 23:26:19.529 Error: Tibber: (Tibber) 'onMessage' failed 'TypeError':''NoneType' object is not subscriptable'.
2022-01-11 23:26:19.529 Error: Tibber: (Tibber) ----> Line 500 in '/home/pi/domoticz/plugins/Tibber-Domoticz/plugin.py', function onMessage
2022-01-11 23:26:19.529 Error: Tibber: (Tibber) ----> Line 265 in '/home/pi/domoticz/plugins/Tibber-Domoticz/plugin.py', function onMessage

Same situation. Still no prices, power updates every 30 secs, and most of the other devices stopped updating at different times throughout the night.

Fix is in version 1.13 that I just uploaded.

Thanks. There are now more devices, 25 in total, but still no prices. And power updates now around every 50 seconds.

I may have forgotten but do you buy electricity from Tibber?
If not you will get any prices.
Great that you get more devices now.
Yes, every 50 second it updates power.
I had to change this because of timeout when asking for data.
Version 1.14 the text in DZ log will be correct.
Now it still says "... every 10 seconds..."

Yes,, I buy electricity from Tibber.

Every 50 sec is not very often. Is it because downloading all the other data, like current and voltage for each phase, and other things?

I have two other persons that also use 1.13 and they get prices.
Can you attach Tibber log file.
What parameter/s do you want every 10 seconds?
power, minPower, maxPower, powerProduction, powerReactive, powerProductionReactive, minPowerProduction, maxPowerProduction, lastMeterProduction, powerFactor, voltagePhase1, voltagePhase2, voltagePhase3, currentL1, currentL2, currentL3, signalStrength, lastMeterConsumption, accumulatedConsumption, accumulatedProduction, accumulatedConsumptionLastHour, accumulatedProductionLastHour, accumulatedCost, accumulatedReward, averagePower

I have two other persons that also use 1.13 and they get prices.
Can you attach Tibber log file.
What parameter/s do you want every 10 seconds?
power, minPower, maxPower, powerProduction, powerReactive, powerProductionReactive, minPowerProduction, maxPowerProduction, lastMeterProduction, powerFactor, voltagePhase1, voltagePhase2, voltagePhase3, currentL1, currentL2, currentL3, signalStrength, lastMeterConsumption, accumulatedConsumption, accumulatedProduction, accumulatedConsumptionLastHour, accumulatedProductionLastHour, accumulatedCost, accumulatedReward, averagePower