Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next Steps with Enphase Inverter #107

Closed
aryanbhosale opened this issue Apr 15, 2024 · 16 comments
Closed

Next Steps with Enphase Inverter #107

aryanbhosale opened this issue Apr 15, 2024 · 16 comments
Labels
enhancement New feature or request

Comments

@aryanbhosale
Copy link
Contributor

Detailed Description

Send the AUTHORIZATION_URL to the Home Owner / System Owner to grant permission to us to use their system data, they will send us an ENPHASE_SYSTEM_ID ---> I currently don't have access to this since I don't know anyone who owns an enphase inverter, but if anyone here could grant my AUTHORIZATION_URL permission to use their enphase data that would be really great!

Context

This is with reference to #106 that builds on #66 which fixes #36

Possible Implementation

#106

@aryanbhosale aryanbhosale added the enhancement New feature or request label Apr 15, 2024
@markus-kreft
Copy link

Hi @aryanbhosale,

Thanks for tracking this and updating the code. Are you able to obtain an Access Token like this? I did not find any documentation from Enphase about supporting the Client Credentials Flow and when I try get_enphase_access_token() with my application credentials I get 401 (Unauthorized).

@aryanbhosale
Copy link
Contributor Author

aryanbhosale commented Apr 22, 2024

Hi @aryanbhosale,

Thanks for tracking this and updating the code. Are you able to obtain an Access Token like this? I did not find any documentation from Enphase about supporting the Client Credentials Flow and when I try get_enphase_access_token() with my application credentials I get 401 (Unauthorized).

I think you need to send your authorization url to an enphase H.O., that's how they'll authorize your access to their data. Please go through the docs, i have followed these to update the code, let me know if you have any queries

@markus-kreft
Copy link

I followed the steps in the docs to get a refresh + access token for my test system. But I can't get an access token with get_enphase_access_token.

@aryanbhosale
Copy link
Contributor Author

aryanbhosale commented Apr 24, 2024

I followed the steps in the docs to get a refresh + access token for my test system. But I can't get an access token with get_enphase_access_token.

I think you need to send your authorization url to an enphase H.O., that's how they'll authorize your access to their data.

This is the step you need to follow before going ahead with running that code , do you have an enphase system?

@peterdudfield
Copy link
Contributor

@aryanbhosale I have a system, I perhaps could give you access or details and you could try.
Whats your email address?

@markus-kreft
Copy link

I did login on the authorization url and granted access. This allowed me to obtain an access + refresh token through the Authorization Code Flow as described in the docs. But the get_enphase_access_token does not work for me even after granting access.

@aryanbhosale
Copy link
Contributor Author

aryanbhosale commented Apr 25, 2024

I did login on the authorization url and granted access. This allowed me to obtain an access + refresh token through the Authorization Code Flow as described in the docs. But the get_enphase_access_token does not work for me even after granting access.

Let me take a look at it in that case, a few things to keep in mind, did you add the env vars in a .env file in the root directory on the project? Please refer to .env.example

@aryanbhosale
Copy link
Contributor Author

I did login on the authorization url and granted access. This allowed me to obtain an access + refresh token through the Authorization Code Flow as described in the docs. But the get_enphase_access_token does not work for me even after granting access.

were you granted with a one time code when you logged in to that auth url?

@aryanbhosale
Copy link
Contributor Author

@aryanbhosale I have a system, I perhaps could give you access or details and you could try. Whats your email address?

aryan.bhosale1719@gmail.com
Thanks a lot for this @peterdudfield , will help me try it out better, ill email you with my authorization url just to see how the flow works

@aryanbhosale
Copy link
Contributor Author

aryanbhosale commented Apr 25, 2024

Hi @markus-kreft can you please check #117 and try to test it with your test system? This has the updated authorization grant flow as required by the enphase api v4

@markus-kreft
Copy link

Yes, this flow should work. I can get a the code/redirect URI like this and was able to retrieve data using my own draft code.
However, your code is failing because your definition of get_enphase_access_token() does not accept the required code:

...
  File "/app/quartz_solar_forecast/forecast.py", line 30, in run_forecast
    pv_xr = make_pv_data(site=site, ts=ts)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/quartz_solar_forecast/data.py", line 168, in make_pv_data
    live_generation_wh = get_enphase_data(ENPHASE_SYSTEM_ID)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/quartz_solar_forecast/inverters/enphase.py", line 81, in get_enphase_data
    access_token = get_enphase_access_token(auth_code)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: get_enphase_access_token() takes 0 positional arguments but 1 was given

I think it might be convenient to first add some basic tests with a mocked API to catch things like this.

@aryanbhosale
Copy link
Contributor Author

Yes, this flow should work. I can get a the code/redirect URI like this and was able to retrieve data using my own draft code. However, your code is failing because your definition of get_enphase_access_token() does not accept the required code:

...
  File "/app/quartz_solar_forecast/forecast.py", line 30, in run_forecast
    pv_xr = make_pv_data(site=site, ts=ts)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/quartz_solar_forecast/data.py", line 168, in make_pv_data
    live_generation_wh = get_enphase_data(ENPHASE_SYSTEM_ID)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/quartz_solar_forecast/inverters/enphase.py", line 81, in get_enphase_data
    access_token = get_enphase_access_token(auth_code)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: get_enphase_access_token() takes 0 positional arguments but 1 was given

I think it might be convenient to first add some basic tests with a mocked API to catch things like this.

We're in the phase of testing it, thank you

@markus-kreft
Copy link

Hi, quickly wanted to check if you are still working on this? Otherwise I could make a new PR with my implementation that I could test with a real device.

@aryanbhosale
Copy link
Contributor Author

Hi, quickly wanted to check if you are still working on this? Otherwise I could make a new PR with my implementation that I could test with a real device.

Hi @markus-kreft ,yes I am working on this, had my endsemester exams the last 2 weeks so couldn't find time to work on it, but I will be doing this as my Google Summer of code project

@aryanbhosale
Copy link
Contributor Author

@peterdudfield closing this issue since i have the credentials and have successfully tested the auth here #117

@peterdudfield
Copy link
Contributor

Hi, quickly wanted to check if you are still working on this? Otherwise I could make a new PR with my implementation that I could test with a real device.

hi @markus-kreft

Thanks for getting in touch. Perhaps there is a different inverter type, (not Enphase) that you could try out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants