openclimatefix / open-source-quartz-solar-forecast

Open Source Solar Site Level Forecast
MIT License
60 stars 51 forks source link

Next Steps with Enphase Inverter #107

Closed aryanbhosale closed 4 months ago

aryanbhosale commented 5 months ago

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

markus-kreft commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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

markus-kreft commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

@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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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

peterdudfield commented 4 months ago

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