Page 1 of 1

Givenergy - API - Help to build a plugin

PostPosted: Mon Oct 24, 2022 2:20 pm
by mwoodage
Hello,
I've just invested in a battery system for my property and the manufacturer (Givenergy) have an API for the system. Unfortunately i have no idea how to build a plugin so reaching out to see if anyone here has some free time and would like to put one together - all the API info is here, but it's all way beyond me!- https://www.givenergy.cloud/docs/api/v1#introduction
There's also this really useful web site - https://wiki.terravolt.co.uk/docs/givenergy-api/

Any help would be greatly received - or an idea for other ways to bring the data into indigo :)

Thanks
Martin

Re: Givenergy - API - Help to build a plugin

PostPosted: Wed Oct 26, 2022 1:59 am
by neilk
Martin,
The killer here is time but this looks pretty straightforward. I am considering solar and a battery and an API and plugin potential is a must so this is interesting. I am travelling this week but when I get back I will take a closer look and see if we could get some scripts or even a minimum viable plugin.

It is worth thinking about :-

- What device states would you like to surface in Indigo ?
- What control actions would you need or be desirable ?

It would probably mean sharing an API key to test unless they offer a demo account to test against. (Or I bite the bullet and get one). I am also looking at the new Libbi battery/inverter.

Most of the plug-ins I have done do a similar thing so it is definitely possible.

As I say no promises and if anyone has more time then please step in.

Neil

Re: Givenergy - API - Help to build a plugin

PostPosted: Wed Oct 26, 2022 12:40 pm
by mwoodage
Hi Neil,
Thanks for getting back to me, i'd be very grateful if you can have a look at a plugin for this - although it's not an api for all battery systems, only Givenergy solutions. So if you're thinking of getting a Libbi battery then this system will not work with it. I just don't want to waste your time.

I've checked the Givenergy site and they don't have a demo api, so it might be difficult to test as giving out my api key will enable access to all my details, and you don't want that! :shock: .

So, i might have to re-think this, like i say i don't want to waste your time, it would be great to have access via Indigo but i can live without it :D

Let me know what you think,
Martin

Re: Givenergy - API - Help to build a plugin

PostPosted: Fri Oct 28, 2022 5:28 am
by neilk
Hi Martin,
I was thinking the viability of a plugin may influence my choice, as a full and well documented API is high up the list of requirements and this fits the bill so time invested would be fine.
I will still take a look and some scripts might be an option if you don’t mind sharing the results. Shame about a lack of test system as that would make it easy. Once I have had a look I will come back, maybe a zoom call would suffice as once we prove the concept and a few calls are working it should be fine.
Neil

Re: Givenergy - API - Help to build a plugin

PostPosted: Fri Oct 28, 2022 2:53 pm
by mwoodage
Excellent, thanks Neil, I really appreciate your offer to have a look at a plugin, it sounds very exciting.
I'm really enjoying the Givenergy system - it also links with Octopus Energy, so could be even more beneficial to you as i see you've developed the plugin for that.
More than happy to have a zoom call, i'll PM you my email address.

I've had success with the code below, but to be honest, i've no idea what i'm doing - but did manage to get a result. :D



Code: Select all
#####User details here#####
##Givenergy Portal API Key Goes Below between " "
 

$GivEnergyPortalAPI = "API_KEY_GOES_HERE"
$SerialNum = "INVERTER_SERIAL_GOES_HERE"

########end user input#############

##Go Fetch Data##
##Calls Givenergy API and shows current status
$headers_Giv_En = @{
 'Authorization'="Bearer $GivEnergyPortalAPI"
 'Content-Type'='application/json'
 'Accept'='application/json'
 }
$Giv_En =  Invoke-RestMethod -Method 'Get' -Uri https://api.givenergy.cloud/v1/inverter/$SerialNum/system-data/latest/ -Headers $headers_Giv_En
$Giv_En | ConvertTo-Json -Depth 10 | Out-File -FilePath .\InvData_Now.txt -Encoding ASCII

Write-Output "Data Saved to: InvData_Now.txt"
Write-Output "All done - Exit in 5...."
start-sleep -s 5

Exit


Result:-

Code: Select all
{
  "data": {
    "time": "2022-10-28T20:21:40Z",
    "solar": {
      "power": 0,
      "arrays": [
        {
          "array": 1,
          "voltage": 22.5,
          "current": 0,
          "power": 0
        },
        {
          "array": 2,
          "voltage": 20.9,
          "current": 0,
          "power": 0
        }
      ]
    },
    "grid": {
      "voltage": 245.7,
      "current": 2.6,
      "power": 17,
      "frequency": 50.09
    },
    "battery": {
      "percent": 65,
      "power": 621,
      "temperature": 20
    },
    "inverter": {
      "temperature": 34.8,
      "power": 536,
      "output_voltage": 245.8,
      "output_frequency": 50.08,
      "eps_power": 0
    },
    "consumption": 519
  }
}



Logging into the Givenergy site gives some great information, but unfortunately this just times out so can't be shown on a monitor. I i could make something like this with an Indigo Control page, that would be amazing

Re: Givenergy - API - Help to build a plugin

PostPosted: Sun Oct 30, 2022 10:38 am
by neilk
Martin,
I got your message, and thanks for this it is helpful. We will start with getting the results you have here into device states then look in more detail as to what may be useful.
Neil

Re: Givenergy - API - Help to build a plugin

PostPosted: Sun Oct 30, 2022 11:35 am
by mwoodage
Thanks Neil, looking forward to seeing the results :D

Re: Givenergy - API - Help to build a plugin

PostPosted: Sun Oct 30, 2022 1:47 pm
by neilk
Martin,


You will find the initial version https://github.com/neilkplugins/GivEnergy-indigo-plugin/releases and I am pretty sure it may take a couple of interations to get this going.

You can install like a normal plugin, and create an inverter device.

You will need to add your API key and Inverter serial number (as you did in the script you posted)

I have not added any validation on these, so anything will be accepted, so you may need to double check and make sure no extra characters sneak in with a cut and paste.

Please enable debugging, and if this doesn't work then we can figure out how to sort it. Be careful as your API key will be in the event log. I will also drop you an email.

I plugged your test data in, and the states updated correctly (in the example below I tweaked some as the zeros are also the default), so once we make sure the API call is succeeding we should be good to go !

Screenshot 2022-10-30 at 19.48.20.png
Screenshot 2022-10-30 at 19.48.20.png (31.73 KiB) Viewed 1580 times



Let me know how you get on !

Neil

Re: Givenergy - API - Help to build a plugin

PostPosted: Mon Oct 31, 2022 2:14 pm
by mwoodage
Hi Neil,
24 hours with the plug-in running and everything’s working well
I’ll have a think about other features and let you know, but it’s given me what I need so far.

Thank you so much

Martin


Sent from my iPhone using Tapatalk