-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add support for 6 month owner tokens through enlighten API, and batte… #91
base: main
Are you sure you want to change the base?
Conversation
Because there can be enough time between when _is_enphase_token_expired() is called and when the subsequent http request to the envoy happens, the token freshness check can pass but the envoy will still see an expired token. This results in a 401 from the envoy, which raises an exception. This change looks for these 401s and attempts to refresh the token twice before giving up.
807e593
to
fd6860e
Compare
Rebased on [gh-90] and expanded it to check if cookie can be refreshed. For this use case it's not that the token itself times out (that's good for 6 months), but that the session cookie used to talk to the envoy times out and needs to be refreshed locally. I moved the PR to draft until I can confirm it's stable for a while. If you want to use these changes in HA you can use the custom component I made at https://github.com/DanBeard/enphase_envoy edit: When paired with that custom component, I can see battery percentage too, so this may also solve [gh-72] ? |
I have two combiners, one is running D5.x.x, the other is running D7.x.x, I am getting this error for both when pressing "Submit" on the setup config flow
I thought I had this installed and working fine yesterday, even did multiple restarts and reloads, however today without restarting or reloading the the integration disconnected from both combiners after first giving a Before using this integration I was using the one provided at #78 (comment), it was working fine, however it would disconnect every morning at around 4-5am, which I'm assuming is related to not using the 6 month access token. |
Thanks for trying it out @michaelgaultjr . I just fixed the crash when the checkbox is unchecked. If you want to test the 6 month token be sure the "use enlighten" checkbox is checked and the username and password are what you would use on enlighten.enphaseenergy.com . Thanks for the link: I didn't know about that other integration. I'll try to rebase mine on it so we can have the best of both. I've been running with my custom_component for ~5 days now (Firmware: D7.0.71) and it hasn't disconnected yet. Not sure how to adequately test the 6 month token refresh in a reasonable amount of time though. |
Thanks for the quick fix and reply, those issues have been solved, however I'm now running into two different issues. For the D7.x.x combiner, when pressing "Submit" in the config flow using the enphase enlighten email and password, with
And for the D5.x.x combiner, the integration is added, however it doesn't load due to this error
This seems to be because this combiner doesn't have any batteries connected to it, as our setup is a little strange due to the way the installer set them up, the D7.x.x combiner has 15 panels and the batteries, and the D5.x.x combiner just has ~45 panels. |
…rys through 'Ensemble' API
fd6860e
to
6f33c8d
Compare
Yeah, it didn't handle "ensemble" response without a battery well. I've added a guard around that. I think the 'KeyError: 'token'" on the D7.x.x combiner is because your enlighten account doesn't have permission to access it by its serial number. If you login to If you want to try it out the new changes with the custom component, you may need to delete the envoy_reader directory and envoy_reader-0.21.3.dist-info in "/usr/local/lib/python3.9/site-packages" before using the custom component again. |
Thanks for fixing the ensemble issue. I'm not home to install the new version of the plugin, but I was able to check the token using that link, I didn't get any errors. |
Finally got a chance to try it out. We had some changes made to our system, so D5.x.x combiner (the one with all the solar panels) has been updated to D7.0.71, and with the update to the integration it seems to be working, though I haven't been using it for long. One thing I'm noticing is there's no way to get the amount of energy going in and out of the batteries, just the current charge percentage, It'd be really nice to have those so I can track energy in Home Assistant instead of the Enphase cloud. I'm used this guide this guide on the forum to setup grid import and export sensors, however this doesn't work with the batteries without knowing how much is going in and out. |
Yeah I want to calculate the same thing, but It doesn't look like the "ensemble" api gives the production/consumption from the battery itself. Here's an example of the json that the api gives:
|
Yeah, I ended up digging around a bunch and found out there is no way to get it aside from their cloud API, I read somewhere local battery information was planned for we 2021, but that unfortunately hasn't happened |
@DanBeard Have you or anyone else checked this on older firmwares? |
This solves [gh-78] for my newly provisioned system on Firmware version D7.0.71 . I couldn't figure out how to get the token working from the 'entrez' api, but I found a technical brief by enphase on how to get token through enlighten that is good for 6 months. (link here)
This commit adds a new optional use_enlighten_owner_token param. If set it will attempt to log in to enlighten and grab the token from the enlighten API. I also added the ability to add a time buffer so it will refresh before the expiry date. This can be useful for offline use, so if you grab a new token every month you can be sure you'll have ~5 months left if enphase's server or your internet connection goes down.
It seems that the bearer token only works on the '/auth/check_jwt' endpoint. The other endpoints also want the session cookie that is returned by that endpoint or they return 401. So the change to add cookies to the client may also solve 401s with the entrez api tokens (but I couldn't test that because the entrez token generation api doesn't work for me for whatever reason)
I was also missing battery information for my system even though I have a battery backup. I found out from this post that you have to go through the 'ensemble' API for my model. (No idea how they figured that out. Is this API fully documented anywhere?)
I don't think I modified anything in the other data flows but I can't test on any systems but mine. Let me know if this causes any issues
Pull request recommendations:
Thanks for contributing!