Enphase Envoy API Update

Posted on
Sun Mar 12, 2023 2:15 pm
GlennNZ offline
User avatar
Posts: 1573
Joined: Dec 07, 2014
Location: Central Coast, Australia

Re: Enphase Envoy API Update

Good to hear.

What a difference a day makes for those endpoint results!
Interesting that the http ones now work - presumably will be because I allow redirects and presumably redirect to https. Should turn that off for endpoint checking.

Interesting about the jwt endpoint - that is apparently for checking token, and/or giving length of time it remains valid. Currently will leave the web token generation - particularly if lasts a year. But it is possible to do within plugin eventually.

I’ll look at the net consumption lifetime - at a guess will be coming from production.json/production. Where it does seem to exist. May be something else causing issue - I’ll have a look later today.

This is what is returned - would the total consumption be a better option?
(given net is 0 across the board)

Code: Select all
"consumption": [
  {
    "type": "eim",
    "activeCount": 1,
    "measurementType": "total-consumption",
    "readingTime": 1678639066,
    "wNow": 805.972,
    "whLifetime": 16960437.142,
    "varhLeadLifetime": 4004248.586,
    "varhLagLifetime": 1034968.231,
    "vahLifetime": 20389408.396,
    "rmsCurrent": 8.516,
    "rmsVoltage": 244.379,
    "reactPwr": -338.808,
    "apprntPwr": 1040.156,
    "pwrFactor": 0.78,
    "whToday": 11053.142,
    "whLastSevenDays": 167664.142,
    "vahToday": 13398.396,
    "varhLeadToday": 2793.586,
    "varhLagToday": 454.231
  },
  {
    "type": "eim",
    "activeCount": 1,
    "measurementType": "net-consumption",
    "readingTime": 1678639066,
    "wNow": -239.691,
    "whLifetime": 0.0,
    "varhLeadLifetime": 4004248.586,
    "varhLagLifetime": -6557917.437,
    "vahLifetime": 20389408.396,
    "rmsCurrent": 0.998,
    "rmsVoltage": 244.398,
    "reactPwr": 134.528,
    "apprntPwr": 244.008,
    "pwrFactor": -0.98,
    "whToday": 0,
    "whLastSevenDays": 0,
    "vahToday": 0,
    "varhLeadToday": 0,
    "varhLagToday": 0
  }
],


Cheers

Glenn


Sent from my iPad using Tapatalk

Posted on
Mon Mar 13, 2023 5:03 am
GlennNZ offline
User avatar
Posts: 1573
Joined: Dec 07, 2014
Location: Central Coast, Australia

Re: Enphase Envoy API Update

Hi

Posted an update to 0.6.0

Unfortunately needs cryptography installed if not already. (in my case is already in use). Plugin uses this to decode the token and get it’s expiry date.
Code: Select all
pip3 install cryptography

(Which sometimes fails - see AppleTV plugin FAQ about overcoming these simply)

Adds:
Firmware >=7 Token support

1. Option for Manual inputting Token remains. Expiry of token will be unknown however, and up to user.
Plus
2. Option for plugin querying enphase online for token via username, password and then using this until it expires (seems to last 12 months), and then will reissue new token.
or
3. continue without token for those that don’t need it as yet..

Other changes:
- Threads the creation of the panels so no UI hanging whilst creating panel devices.
- Change some of the panel creation data-filling, so should fill data straight-away after creation rather than needing 5 minute cycle.
- Removes redirects from endpoint testing button (redirect remains elsewhere as can’t see harm)
- Uses http:// only for info.xml - seems to work in your posted testing
(this is used to get serial number which should no longer need to be entered/found)
- Adds library pyjwt (included) to decode the token to get expiry date.
(optional need for cryptography)

Both my systems have cryptography installed so haven’t completely tested without - but believe everything except enphase token generation should work. Let me know if doesn’t - as really hate adding a pip3 need, but given cryptography binaries it creates for each system no way to package it.

Options down the track:
Currently don’t save token (could do so) and then just check expiry. Currently with every startup will reissue it, and renew it’s expiry. If some have wider internet locked down - manual token option probably the best.
& \livedata\ endpoint looks vaguely interesting - and may be more there in future of interest.

Glenn


Sent from my iPad using Tapatalk

Posted on
Mon Mar 13, 2023 11:17 am
aldera offline
User avatar
Posts: 188
Joined: Aug 30, 2016
Location: Michigan, USA

Re: Enphase Envoy API Update

Hey Glenn,

Installed v0.6.0 and here's the log after installing it and using the option where you generate the token and get the expiry date. Seems to work. The token you generated is the exact same as the one I generated a few days ago, but only for the first 323 characters. I deleted those 323 characters and the log printout below only shows the remaining portion of the key that you generated. I included those same remaining characters from my key in case is was of any use to you.

I didn't install any cryptography file so I assume I already have it installed. I'm not a Unix/Python guy (YET!) so I'm not sure where to look. I looked under System/Library/Frameworks and found CryptoKit.framework and CryptoTokenKit.framework. Are those the ones you're using?

Concerning the netConsumption value, I already get the lifetime Consumption and Production values and can just generate it myself. I just thought the value from the device would save me a calculation or two.

Ralph

Stopped plugin Enphase Envoy Plugin
Upgrading plugin Enphase Envoy Plugin to newer version 0.6.0 (previous version moved to trash)
Loading plugin "Enphase Envoy Plugin 0.6.0" using API v3.0.0
Starting plugin "Enphase Envoy Plugin 0.6.0" (pid 36519)
Enphase Envoy Plugin
Enphase Envoy Plugin ================================================ Initializing New Plugin Session =================================================
Enphase Envoy Plugin Plugin name: Enphase Envoy Plugin
Enphase Envoy Plugin Plugin version: 0.6.0
Enphase Envoy Plugin Plugin ID: com.GlennNZ.indigoplugin.EnphaseEnvoy
Enphase Envoy Plugin Indigo version: 2022.2.0
Enphase Envoy Plugin Python version: 3.10.2 (v3.10.2:a58ebcc701, Jan 13 2022, 14:50:16) [Clang 13.0.0 (clang-1300.0.29.30)]
Enphase Envoy Plugin Python Directory: /Library/Frameworks/Python.framework/Versions/3.10
Enphase Envoy Plugin ============================================== End Initializing New Plugin Session ===============================================
Started plugin "Enphase Envoy Plugin 0.6.0"
Enphase Envoy Plugin Starting Enphase/Envoy device: Enphase Envoy

Mar 13, 2023 at 12:32:25 PM
Enphase Envoy Plugin Stopping Enphase device: Enphase Envoy and id:Enphase Envoy-S
Enphase Envoy Plugin Starting Enphase/Envoy device: Enphase Envoy

Mar 13, 2023 at 12:32:55 PM
Enphase Envoy Plugin Found Full Enphase Envoy Serial Number:121929070207
Enphase Envoy Plugin Logging in to Enphase to generate Enphase Token. Should only be needed once every 12 months
Enphase Envoy Plugin Generated your Enphase account Token:
.c8wLfYDMFV4y9StGCd1oSGda1LjzHV2KXX4Cw5qZywr3Ly5Luo46Q7lG8uBwq1l1IW0LWX0q4e0msy6wFcNEtQ
Enphase Envoy Plugin This Enphase Token expires at: Tue Mar 12 12:32:59 2024

***********************************NOT PART OF LOG!!*************************************
This is the token I generated and used before the v.0.6.0 update (minus the 1st 323 characters)
.6wG61vsxy1VR_JCwm7M49TV4M2SK-u1OfQB0EN5mQTQ59PbIy1z2altUDNk0rf4OF1-2Q3mVd97v5-7rfdiG-w

Posted on
Mon Mar 13, 2023 2:10 pm
GlennNZ offline
User avatar
Posts: 1573
Joined: Dec 07, 2014
Location: Central Coast, Australia

Re: Enphase Envoy API Update

Great. I can test getting the token - as that works, just not using it…

Presume you must have cryptography installed (don’t believe was part of base python indigo install - but should check in case has changed)

Code: Select all
pip3 show cryptography

Will show whether installed or not.

The plugin uses jwt library which in turn uses cryptography to decode the token and get it’s expiry date.

Released after release and was writing last post.
That:
1. Can check for cryptography install and set a flag whether installed or not, and if not - don’t use the token expiry checks. Rather than currently which will try and generate a error, if missing

Glenn


Sent from my iPad using Tapatalk

Posted on
Mon Mar 13, 2023 3:52 pm
aldera offline
User avatar
Posts: 188
Joined: Aug 30, 2016
Location: Michigan, USA

Re: Enphase Envoy API Update

I guess I've got the cryptography files. Might have gotten installed with another plugin that I use.

Code: Select all
Last login: Mon Mar 13 17:36:04 on ttys000
ralph@Macmini2M1 ~ % pip3 show cryptography
Name: cryptography
Version: 37.0.4
Summary: cryptography is a package which provides cryptographic recipes and primitives to Python developers.
Home-page: https://github.com/pyca/cryptography
Author: The Python Cryptographic Authority and individual contributors
Author-email: cryptography-dev@python.org
License: BSD-3-Clause OR Apache-2.0
Location: /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages
Requires: cffi
Required-by:
ralph@Macmini2M1 ~ %

Posted on
Tue Mar 14, 2023 8:31 pm
GlennNZ offline
User avatar
Posts: 1573
Joined: Dec 07, 2014
Location: Central Coast, Australia

Re: Enphase Envoy API Update

Interesting - usually shows what needed it - in your case blank.

Have updated to
0.6.1
Adds check for presence of library cryptography - if not present present some info and avoid usage (all going to plan)
& for interest Debug log the decoded token - to show all details for interest sake

Who is online

Users browsing this forum: No registered users and 4 guests