DiedB / Homey-SolarPanels

Connects production statistics of a wide range of PV inverters to Homey
https://apps.athom.com/app/it.diederik.solar
GNU General Public License v3.0
54 stars 37 forks source link

Enphase Enlighten v4 API #235

Open JohanvanZanten opened 1 year ago

JohanvanZanten commented 1 year ago

the v2 of the Elighten API will expire jan 18th, the new v4 is already live but entitles an entire;y different concept with paid plans, although there will be a free plan (but with the least features)

will you support the v4 API ?

ferrydl commented 1 year ago

There is also a local API, which off course is free to acces. I would really like it if it is possible to connect to that. The local API is: http://[local-ip]/api/v1/production/. The resulat are:

{
  "wattHoursToday": 1852,
  "wattHoursSevenDays": 16777,
  "wattHoursLifetime": 24426931,
  "wattsNow": 568
}

and it is updated about every 5 minutes.

Slofware commented 1 year ago

Tryed that with a webhook and I got these error: request to https://X.X.X.X/api/v1/production/ failed, reason: self signed certificate Same as when you add a Enphase Envoy. Is that a Homey thing or a Enphase thing.

DiedB commented 1 year ago

Will work on this as soon as I can find the time. @ferrydl the local API is covered in the Enphase Envoy integration of this app for two years already. However, Enphase changed things there as well and the app needs to adapt. @Slofware you are also refering to Envoy, if you have any comments there please add them to issue #215.

DiedB commented 1 year ago

Enlighten V4 goes back to 1000 hits a month, which would mean 2-3 updates per hour if we make it smart (no requests at night).

I don't have an Enphase system myself, is there anyone who could share credentials with me so I can update the implementation? You can send me an email at slower_04_machete@icloud.com.

RoadXY commented 1 year ago

I've send you my credentials.

I'm also a Homey developer (though not as good 😊) and a IT admin.

Let me know if/where I can help

KnarfOfSpam commented 1 year ago

Do not know if anyone seen this but here goes from the Enphase Forum (Sorry don't know how to deep link):

3 of 907

alexbk66

Edited May 10, 2023 at 8:37 PM Not sure if it was mentioned before, but Enphase finally released a new brief which includes the "API" to get he token. Which is a great news as they now made their "API" official!

Quote:

"Accessing IQ Gateway local APIs or local UI with token-based authentication"

For users who want to retrieve a token programmatically, Enphase provides a URL to retrieve a token and mentions the duration for which the token will be valid.

The token is valid only for one year to ensure safety and you must generate a new token upon expiry. The following table lists a few local REST APIs of IQ Gateway.

https://click.email.enphase.com/?qs=787eba345119af180f82c885585570bddc60a3d49a9ff9f55248059addae0c9c440e87fc1f9cbfd60eabe6154d4f0488cf5be0c48bb8c133

Tech Brief-IQ Gateway Local API or UI Access using Token-EN-US-12-14-2022.pdf

DiedB commented 1 year ago

Can someone help me with such a token and remote access to an Envoy (through port forwarding or Wireguard for example)? Hit me up at slower_04_machete@icloud.com

RoadXY commented 1 year ago

I can help you with that.

DiedB commented 1 year ago

For reference: https://community.home-assistant.io/t/enphase-local-api-with-firmware-7-x-my-setup/563828/12

SiskoBen commented 1 year ago

Hi @DiedB, I have been working on this issue as well and gave up on a Homey App as development/debugging on that is not working for me. I have however managed to get a Javascript proof of concept working for Envoys with the D7 firmware (currently hardcoded local envoy IP address [which your solar panels app can get from the mDNS discovery], username and password [to the Enphase Enlighten account used to get a authentication token for the local envoy which the homey app could ask to the user]. I can send you the javascript code i have for you to use to develop/incorporate in your solar panels app. Let me know if you want to look at my javascript code? Best regards/Groetjes, Arjan

Edit: Here is the output of about 10 minutes of running my javascript (Inverter data is updated once every 5 minutes, production data is instantaneous but I read only once per 30 seconds) https://github.com/SiskoBen/Enphase-Envoy-Javascript-output/blob/985618815ac874699be73197e2f9f9f900362086/Sample%20output

DiedB commented 1 year ago

Hi Arjan! Great work, but I sorted it myself already :) Didn't take too much time luckily!

SiskoBen commented 1 year ago

Hi @DiedB , Great! I hope to see the new (test) app soon ;-)

DiedB commented 1 year ago

If anyone wants to try, support for newer Envoy firmware is on the branch feature/envoy-v7. You can install it on your Homey through the Homey CLI (only recommended for power users). Feedback is appreciated.

SiskoBen commented 1 year ago

If anyone wants to try, support for newer Envoy firmware is on the branch feature/envoy-v7. You can install it on your Homey through the Homey CLI (only recommended for power users). Feedback is appreciated.

Hi Diederik, I don't know how the Homey CLI works but I looked at the code. Is it true to say that the code does read only the data in "production.json" (.wNow if relevant/active) and not the data from each individual microinverter data (.lastReportWatts from "api/v1/production/inverters/")?

DiedB commented 1 year ago

Currently, yes. The app does not record data on a micro-inverter level, only the total power/energy for an entire plant. This was also the case for the previous Envoy implementation.

JohanvanZanten commented 1 year ago

[image0.png]

Sent from my favorite Certis iDevice

On 17 Jun 2023, at 11:46, Diederik Bakker @.***> wrote:



If anyone wants to try, support for newer Envoy firmware is on the branch feature/envoy-v7. You can install it on your Homey through the Homey CLI (only recommended for power users). Feedback is appreciated.

— Reply to this email directly, view it on GitHubhttps://github.com/DiedB/Homey-SolarPanels/issues/235#issuecomment-1595694440, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEDC64H5GJB6XE3AR344HYDXLV4HNANCNFSM6AAAAAATCPO6HQ. You are receiving this because you authored the thread.Message ID: @.***>

DiedB commented 1 year ago

I cannot see the image, uploading images only works directly on GitHub.

JohanvanZanten commented 1 year ago

Sorry, my bad ;)

here you go Homey-SolarPanels-feature-envoy-v7 Screenshot

DiedB commented 1 year ago

@JohanvanZanten Should be fixed, please pull and run the app again.

JohanvanZanten commented 1 year ago

Hi Diederik,

the previous error is now gone but, this is always a nice one: "An unknown error occurred while fetching inverter data", is there any way of logging available ?

grtx Johan

ketra commented 1 year ago

@DiedB @JohanvanZanten , i checked the code, and there is a 401 unauthorized error, even when the Token is received, This is because there also needs to be an authenticated cookie in the session before its possible to request data from the production.json endpoint.

ketra commented 1 year ago

@DiedB Added pullrequest with fixes.

JohanvanZanten commented 1 year ago

were there any changes as I still have the same Untitled

WouterAar commented 1 year ago

Hoi Diederik,

Ik heb ook het probleem dat ik met jou top apps, ni t kan connecten ivm benodigde API Key, heb op internet volgende bij enphase gevonden voor ontwikkelaars van apps zoals jij. Mede ivm API.

Heb je hier iets aan? Zal onderstaande de schermafbeeldingen toevoegen.

Laat maar even weten of ik je verder kan helpen?

Gr wout, 50 panels enphase installation with IQ7+ omvormers.

WouterAar commented 1 year ago

image

WouterAar commented 1 year ago

image

WouterAar commented 1 year ago

image

WouterAar commented 1 year ago

image

WouterAar commented 1 year ago

image

WouterAar commented 1 year ago

image

WouterAar commented 1 year ago

Bovenstaande is de tekst en toelichting voor app ontwikkelaars in relatie tot API

WouterAar commented 1 year ago

@DiedB

User id heb ik als systeem eigenaar wel, maar hij vraagt ook om de API key als ik je app envoy enlighten installeer en open. Die API heb ik niet, komt volgens mij omdat er als ik teksten enphase lees hierboven, in de software eea ingebouwd moet zijn ivm API, incl goedkeuring en aanmelding vd app door de programeur bij enphase.

WouterAar commented 1 year ago

Als ik je app installeer op homey pro early 2019 Dan krijg ik onderstaande melding op scherm, denk dat jij dit beter snapt dat ik. image

ketra commented 1 year ago

@WouterAar deze melding krijg je omdat de huidige app in de store nog niet kan praten met de nieuwe firmware van de enphase gateway. hier wordt aan gewerkt.

WouterAar commented 1 year ago

@DiedB

Na installatie van de app op de honey pro early 2019 krijg ik de volgende schermen.

image

image

image

image

Op deze laatste foto zie je dat de app envoy enlighten de user ID vraagt (die heeft elke systeem eigenaar zelf en kan hij/zei uit the app enlighten halen), maar the API KEY kun je niet vinden als systeem eigenaar, dan komt tekst uit eerdere foto's weer boven daar in de app iets ingebouwd moet zijn, app aangemeld moet zijn door ontwikkelaar bij enphase volgens mij om API te kunnen gebruiken in de app.

Kun je hier verder mee? Laat maar even weten.

Thx, gr wout

WouterAar commented 1 year ago

@WouterAar deze melding krijg je omdat de huidige app in de store nog niet kan praten met de nieuwe firmware van de enphase gateway. hier wordt aan gewerkt.

Ok, maar na installatie vraagt app ook om API key en die kun je als systeem eigenaar nergens in de enphase envoy Metered s gateway vinden, nemen jullie dat ook mee?

Gr wout

WouterAar commented 1 year ago

Overigens gebruikte ik tot voor kort jullie app enphase envoy en die vraagt niet om user ID en API KEY zoals jullie app enphase enlighten wel doet, ik weet niet wat verschil is tussen deze twee apps van jullie tav werking en flows.

ketra commented 1 year ago

@WouterAar deze melding krijg je omdat de huidige app in de store nog niet kan praten met de nieuwe firmware van de enphase gateway. hier wordt aan gewerkt.

Ok, maar na installatie vraagt app ook om API key en die kun je als systeem eigenaar nergens in de enphase envoy Metered s gateway vinden, nemen jullie dat ook mee?

Gr wout

De nieuwe feature die nu getest wordt praat lokaal met de gateway en zal alleen een enphase eigenaar account login nodig hebben

WouterAar commented 1 year ago

@WouterAar deze melding krijg je omdat de huidige app in de store nog niet kan praten met de nieuwe firmware van de enphase gateway. hier wordt aan gewerkt.

Ok, maar na installatie vraagt app ook om API key en die kun je als systeem eigenaar nergens in de enphase envoy Metered s gateway vinden, nemen jullie dat ook mee?

Gr wout

De nieuwe feature die nu getest wordt praat lokaal met de gateway en zal alleen een enphase eigenaar account login nodig hebben

Dat klinkt goed, is er bekend wanneer de nieuwe app te downloaden is?

En Heb je nog hulp nodig hierbij om te testen op een installatie, dan hou ik me aanbevolen om te helpen met info die nodig hebt.

ketra commented 1 year ago

Overigens gebruikte ik tot voor kort jullie app enphase envoy en die vraagt niet om user ID en API KEY zoals jullie app enphase enlighten wel doet, ik weet niet wat verschil is tussen deze twee apps van jullie tav werking en flows.

Voor flows geen verschil, de enphase envoy praat lokaal met de gateway, enphase enlighten via de cloud api, waar een developer account voor nodig is, en daarnaast is die api betaald vanaf een x aantal verzoeken

ketra commented 1 year ago

@WouterAar comment aangepast.

WouterAar commented 1 year ago

Overigens gebruikte ik tot voor kort jullie app enphase envoy en die vraagt niet om user ID en API KEY zoals jullie app enphase enlighten wel doet, ik weet niet wat verschil is tussen deze twee apps van jullie tav werking en flows.

Voor flows geen verschil, de enphase envoy praat lokaal met de gateway, enphase enlighten via de cloud api, waar een developer account voor nodig is, en daarnaast is die api betaald vanaf een x aantal verzoeken

Hi, zag vandaag automatische update app zonnepanelen naar versie 5.2. Heb app getest maar krijg bij enphase envoy (lokaal) onderstaande foutmelding. Is 5.2 geschikt voor de enphase met de laatste firmware of adviseer je mij om anders te testen?

image

SiskoBen commented 1 year ago

Hi, I just installed the test version (from https://homey.app/en-us/app/it.diederik.solar/Solar-Panels/test/ ), I could add my Envoy and (after entering my envoy login credentials) it is reading the Power (production) as well as the Energy yield (today). So the token authentication system is working. It would be nice to also have these (power and energy) for (total-consumption), the (net-consumption) and the (storage [i.e. battery]) values from the local Envoy (provided the CTs for this and storage are installed and configured obviously). The individual inverter production (as reported by each individual microinverter to the Envoy with 5 minute intervals) would be a nice to have as well but not crucial. Thanks for getting it working! Best regards/Groetjes, Arjan

DiedB commented 1 year ago

@WouterAar The 5.2 version does not support Envoy v7 yet.

Please install this version, remove your Enphase Envoy from Homey, and then re-add the device as 'Enphase Envoy v7': https://homey.app/nl-nl/app/it.diederik.solar/Zonnepanelen/test/

Slofware commented 1 year ago

I have got 5.2.1 and i can add the Envoy V7 but it keeps giving a value of -0- on both Vermogen and Energie Production

DiedB commented 1 year ago

If it gives you 0, that would mean that the app is able to get data from your inverter and that it reports back those 0 values. What if you manually log into your Envoy, do you see production data?

Slofware commented 1 year ago

Jup then I see the day production and current

SiskoBen commented 1 year ago

Hi, The Energy yield (Today) seems to be the value for lifetime production (or else i already produced 1302 kWh [more than 1mWh ] in 12 hours).

DiedB commented 1 year ago

Can you copy paste the data you get from https://192.168.x.x/api/v1/production?

DiedB commented 1 year ago

Hi, The Energy yield (Today) seems to be the value for lifetime production (or else i already produced 1302 kWh [more than 1mWh ] in 12 hours).

You are right, this has been fixed in the latest test version.