Announcement

Collapse
No announcement yet.

GivEnergy Integration

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    GivEnergy Integration

    "The GivEnergy App uses an API and connects to your GivEnergy Cloud Monitoring account. The APP provides basic information about your Home Energy Demand, Solar PV Generation, Grid import energy and GivEnergy Battery Usage. "

    https://kb.givenergy.cloud/article.php?id=5

    With mcsMQTT the integration is performed on the Cloud Page, URL tab by setting up the URL to givenergy. The POST method is used and authentication is provided as part of a login endpoint

    Click image for larger version  Name:	Capture1.PNG Views:	0 Size:	29.7 KB ID:	1524997
    An HS Device is created to work with this URL. Through this device the endpoints are sent

    Click image for larger version  Name:	Capture2.PNG Views:	0 Size:	29.8 KB ID:	1524998
    A session is started with the following endpoint where YYYY and ZZZZ are login credentials

    Code:
    /login?account=YYYY&password=ZZZZ
    The mcsMQTT MQTT Page, Association tab will show the returned response which includes a success key and other information. The success will be true for a valid login.

    Click image for larger version  Name:	Capture3.PNG Views:	0 Size:	27.2 KB ID:	1524999

    Other API endpoint can now be requested such as below. The full set of API endpoints are provided in the link at the top of this post

    Code:
    /plant/getPlantList
    or

    Code:
    /inverter/getInverterInfo?plantId=1&serialNum=XXXXX
    All information that is returned is presented in the Association table of the MQTT page. Association with HS devices can be done with the "A" column checkbox

    The success key should be monitored with a HS event and the login endpoint sent when success is false so that a new session can be established. Alternately a period logic can be performed as there is no ill-effects from multiple logins. In general a session should be maintained as long as a connection exists, but when the connection is lost then the session is no longer available.

    Attached is update to mcsMQTT to accomodate the session logic.

    #2
    Hi Michael,
    this is fantastic. I can't see the updates attached so not sure if your connection dropped again during the upload?

    Comment


      #3
      I can see them as attached files on post #1. Yesterday I included HS4. Today I added HS3.

      A screenshot of what I see is below.

      Click image for larger version

Name:	Capture.PNG
Views:	301
Size:	146.1 KB
ID:	1525181
      I have been looking into how to handle the Flume integration which is essentially a database query after getting through the login authentication hoops. What I think I will be doing is using the Publist capability of mcsMQTT for this to define the desired queries. It could also be handy for GivEnergy integration where a list of endpoints can be specified and a single event setup for periodic refresh of all the endpoints of interest. This means the user overhead is initial creation of the URL on the Cloud page, the set of the endpoints desired on the MQTT Page, Publist Tab, and then a periodic event to execute the Publist. This is not available in the versions posted in this thread, but will be available very soon. The first element of the publist could be the login endpoint so assured that a fresh session will have the authentication established.

      Comment


        #4
        I did confirm the publist does what is intended.
        If the topic of the publist start with URL/ then the data is sent using URL/HTTP setup rather than through the MQTT broker.

        The example below shows a publish with endpoints for login and inverter info

        Click image for larger version

Name:	Capture1.PNG
Views:	293
Size:	57.3 KB
ID:	1525194

        The event is setup to trigger manually, but normally would be periodic.

        Click image for larger version

Name:	Capture2.PNG
Views:	267
Size:	29.1 KB
ID:	1525195
        The update to support the publist with URL is attached. This should avoid other issues with being able to get the prior version.

        Comment


          #5
          Thanks Michael. Weird that the forum just isn't showing the attachments on the first post but I can see them on this post. I'll have a go getting this up and running later today.

          Comment


            #6
            Got everything working except refreshing the publist. I created one called URL, similarly to your screenshot. When I create the event I get the notification below when I try to save.
            Publist publication list URL will Not execute as an event action until URL Is created.

            The content of my url.pub file is below so it has definitely been created. Not sure if I'm just missing something in how I've set this up, as I've not used the publist functionality in the plugin before.
            Code:
            $$1:=
            $$2:=
            $$3:=
            $$4:=
            URL/https://www.givenergy.cloud/GivManage/api=/inverter/getInverterInfo?plantID=1&serialNum=XXXX
            URL/https://www.givenergy.cloud/GivManage/api=/plant/getPlantList
            URL/https://www.givenergy.cloud/GivManage/api=/plant/event/getPlantEvents?plantID=1
            URL/https://www.givenergy.cloud/GivManage/api=/pcs/batCell/getBatCellData?plantID=1&serialNum=XXXX
            URL/https://www.givenergy.cloud/GivManage/api=/inverter/getInverterRuntime?plantID=1&serialNum=XXXX

            Comment


              #7
              In HS4 the event pages are implemented in the .exe. In HS3 they are in the .dll where most logic resides. I forget about this when I posted only the .dll. The HS4 exe is attached that should take of the message. I remember seeing the Publist message when I was testing. It is placed in the HS root folder.

              As a note that you may already know. The .pub files are just text files that can be edited with any editor more easily than with a browser text box. Just keep the structure with the four replacement variable lines at the top. You could also take advantage of the replacement variables such as shown below.

              Code:
              $$1:=URL/https://www.givenergy.cloud/GivManage/api
              $$2:=
              $$3:=
              $$4:=
              $$1:=/inverter/getInverterInfo?plantID=1&serialNum=XXXX
              $$1:=/plant/getPlantList
              $$1:=/plant/event/getPlantEvents?plantID=1
              $$1:=/pcs/batCell/getBatCellData?plantID=1&serialNum=XXXX
              $$1:=/inverter/getInverterRuntime?plantID=1&serialNum=XXXX
              Attached Files

              Comment


                #8
                Ahh, that's sorted it! I've got everything refreshing now. I had trouble getting the event to start but I think I needed to break up the URL with an "=" before the /login... so hopefully that will work on startup and check as required when the login success variable is false.

                Thanks Michael!!!

                Comment


                  #9
                  Hi Michael McSharry Well, after all that work, they have changed the API. It's more secure now, but a bit of a pain to now re-set it up. I've got the syntax and have it working in powershell, but getting an unauthorised error when I do this from the plugin.
                  The new API documentation is here (although note this is still showing some beta testing info, so "test" shouldn't be included in the paths for example
                  https://givenergy.cloud/docs/api/v1#...em-data-latest

                  I have my parameters as follows:
                  URL: https://api.givenergy.cloud/v1
                  Poll: 30000
                  Polling endpoint: /inverter/##########/system-data/latest
                  Additional headers:
                  Accept: application/json
                  Content-Type: application/json
                  URL type: GET
                  Security type: Bearer
                  and I'm using my API key, which works in powershell. In PS I can use this and it works fine
                  Code:
                  $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
                  Am I setting this up right to use Bearer and the API token?

                  Thanks!

                  Comment


                    #10
                    I see when the Authorization type radio is used with Bearer selected then mcsMQTT uses "Authentication: Bearer" for the header. Looks like GIV is using "Authorization: Bearer". Try using none for the Authorization type radio and adding "Authorization: Bearer {APIKey}" as an additional header.

                    Comment


                      #11
                      That's sorted it, thanks!

                      Comment

                      Working...
                      X