Enphase local API with firmware 7.x - my setup

I know there is a lot of confusion with all of the forks of the Enphase integration because of the authentication switch with the update to firmware 7.x. I was able to solve this using the REST sensor - no enphase integration needed.

Get a Token

All local API access now needs a token to use. For some reason the website to get the token does not work for me. So if you try that and it doesn’t work, there’s a simple way to do it via an easy python script:

import json
import requests

# REPLACE ITEMS BELOW 
user='[email protected]'
password='password'
envoy_serial='your_envoy_serial_number'
# DO NOT CHANGE ANYTHING BELOW

data = {'user[email]': user, 'user[password]': password}
response = requests.post('https://enlighten.enphaseenergy.com/login/login.json?',data=data)
response_data = json.loads(response.text)
data = {'session_id': response_data['session_id'], 'serial_num': envoy_serial, 'username':user}
response = requests.post('https://entrez.enphaseenergy.com/tokens', json=data)
token_raw = response.text
print(token_raw)

You need to fill in your username, password, and the serial number of your envoy box. You can find the serial number in the enlighten app by going to Menu->Devices->Gateway.

When you run this script it will print out your token. It will look something like:

eyJraWQiOiI3ZDEwMDA1ZC03ODk5LTRkMGQtYmNiN......<trucated for clarity>

According to the docs, this token is good for 1yr at which point you will need to get another one. I just put a reminder on my calendar at 11 months to do it to ensure I don’t miss any data. So save the script so you can just run it again the next time you need a token

Make the REST sesnor in HA

Once you have the token, then you can make a rest sensor in HA:

sensor:
  - platform: rest
    resource: https://envoy.local/ivp/meters/readings
    name: Solar Power Output
    unique_id: solar_array_output_id
    scan_interval: 60
    value_template: "{{ value_json[0].activePower | float }}"
    headers:
      Authorization: Bearer <token>
    verify_ssl: False
    state_class: measurement
    device_class: power
    unit_of_measurement: W
    json_attributes_path: "$.[0]"
    json_attributes:
      - eid
      - actEnergyDlvd
      - timestamp
      - voltage
      - current
      - freq

Reload the REST entities in HA and you should see the sensor appear in the state page.

The sensor state will be the current power output in W, with some other items of interest in the attributes.
Note: this assumes your envoy box is on the same LAN as your HA instance and is reachable with the default address of envoy.local, if it isn’t, you can replace envoy.local with the IP of your envoy box.

Make the energy sensor to use in the Energy Dashboard

If you then want an entity that works in the energy dashboard, you can use the integration platform to do it:

sensor:
  - platform: integration
    name: Solar Array Production
    source: sensor.solar_power_output
    unit_prefix: k
    unit_time: h
    method: left
    unique_id: solar_array_production_id

The above will make a sensor that integrates the power output over time to produce the energy measurement required by the energy dashboard.

For reference, I learned how to querey the API and get the tokens from the Enphase documentation. They also show the full JSON output of the various enpoints if you want to extract other information

12 Likes

Thanks Steve,

Worked great. You saved me several hours of research. Previously, I was able to get to the proper curl command to my local IP with the token to get data via command line. It would have taken me several hours to get to the next step. Much appreciated.

rest:
  - headers:
      Authorization: Bearer (token)
    verify_ssl: False
    scan_interval: 60
    resource: https://envoy.local/ivp/meters/readings
    sensor:
      - name: "PVG activePower"
        unique_id: PVG_activePower
        value_template: "{{ value_json[0].activePower | float }}"
        device_class: power
        unit_of_measurement: W
      - name: "PVG Voltage"
        unique_id: PVG_Voltage
        value_template: "{{ value_json[0].voltage }}"
        device_class: voltage
        unit_of_measurement: V
      - name: "PVG actEnergyDlvd"
        unique_id: PVG_actEnergyDlvd
        value_template: "{{ value_json[0].actEnergyDlvd }}"
        device_class: energy
        unit_of_measurement: KW

thanks … work in progress

cannot found any conversie matrix
what is actEnergyDlvd?

rest:
  - headers:
      Authorization: Bearer (token)
    verify_ssl: False
    scan_interval: 60
    resource: https://envoy.local/ivp/meters/readings    
    sensor:
      - name: "PVG activePower"
        unique_id: PVG_activePower
        value_template: "{{ value_json[0].activePower | float }}"
        device_class: power
        unit_of_measurement: W
      - name: "PVG Voltage"
        unique_id: PVG_Voltage
        value_template: "{{ value_json[0].voltage }}"
        device_class: voltage
        unit_of_measurement: V
      - name: "PVG actEnergyDlvd"
        unique_id: PVG_actEnergyDlvd
        value_template: "{{ value_json[0].actEnergyDlvd }}"
        device_class: energy
        unit_of_measurement: KW
      - name: "PVG totaal hoeveelheid opgewekte engergie v2"
        unique_id: PVG_energie_totaal_v2
        value_template: "{{ value_json[0].actEnergyDlvd | float / 1000 }}"
        state_class: total_increasing
        device_class: energy
        unit_of_measurement: "kWh"
        icon: mdi:solar-power

it’s dark here now… will see if values ​​are correct in the coming days

last value can used by engery dasbord

1 Like

tnx!

but maybe a stupid question:
if i open **HTTP**://envoy.local/ivp/meters/readings directly in my browser i get the json data. Why do i need to use a token ?

edit:
i think i see why… " * Software Version D5.0.62 (5e57a9)"

edit2:
interesting to see that no update is available in the enlighten manager

problem is the new firmware

browser has cookies en stuff… curl not

my token works only 12 hours… try now python script

Welp this is pretty darn tootin sweet @ha_steve. Python script worked like a charm. I setup a cron to run it at 11 months, and used an !include file for the token.

Now we just gotta make sensors for all the things, like panel production, and live data etc :slight_smile:

1 Like

token by site don`t work for me… (12 hours vailed)
token by python it works fine !

@ha_steve thanks !!

1 Like

Glad it worked out! I’ve since moved to the RESTful integration like you had above:

rest:
  - headers:
      Authorization: !secret enphase_api_token
    verify_ssl: False
    scan_interval: 60
    resource: https://envoy.local/ivp/meters/readings    
    sensor:
      - name: "Solar Power Output"
        unique_id: solar_power_output_id
        value_template: "{{ value_json[0].activePower | float }}"
        device_class: power
        unit_of_measurement: W
        state_class: measurement
      - name: "Solar Array Production"
        unique_id: solar_array_production_id
        value_template: "{{ value_json[0].actEnergyDlvd | float / 1000 }}"
        state_class: total_increasing
        device_class: energy
        unit_of_measurement: "kWh"
        icon: mdi:solar-power

The second one is what I use on the energy dashboard. So no need for the integration sensor

2 Likes

Thank you for your great work. I have got a couple of quation hopefully you can help.

  1. How can I check if the sensor is working correctly?
    I can reach the JSON file with the settings (including API key), via a browser.

  2. When I look at the json file (based on the same adres as the sensor), actEnergyDlvd value is always 0 (zero) while the panels are producing energy.

image

Is there an other value that can be used for calculating production?

  1. Adding sensor in the Engery dasboard gives an error: “statistics_not_defined”.
    How can I solve this?

Has anyone found a way to write to an Enphase IQ (or IQ gateway)?
I found that the IQ can be setup to limit the output power to the grid. But that is a static thing, what an installer programs when the PV system is installed.
https://enphase.com/nl-nl/download/iq8m-iq8-microinverter-data-sheet
search for Power export limiting (PEL)
and https://enphase.com/download/iq8d-microinverter-power-export-limit-tech-brief

I also have an inverter/charger with a batterybank.
It would be nice, if the grid failes, my battery is still charged. But I then have to limit the PV output if my loads and/or charger reaches the maximum power.
So, the PV output power should be adjustable…

What is the whole JSON return from https://envoy.local/ivp/meters/readings?

Tried to get it to work using the rest approach.
I do have a token, and postman gives me some results using the rest call with the token.
However, i get a negatve active in the JSON?

“activePower”: -0.724,

Any ideas?

Regards
Rein

– complete response; removed some ID’s. dunno if that was necessary, but better safe then sorry ;-)’

[
    {
        "eid": xx,
        "timestamp": 1684522041,
        "actEnergyDlvd": 0.000,
        "actEnergyRcvd": 0.000,
        "apparentEnergy": 0.000,
        "reactEnergyLagg": 0.000,
        "reactEnergyLead": 0.000,
        "instantaneousDemand": -0.724,
        "activePower": -0.724,
        "apparentPower": 82.067,
        "reactivePower": 0.582,
        "pwrFactor": 0.000,
        "voltage": 708.192,
        "current": 0.348,
        "freq": 50.000,
        "channels": [
            {
                "eid": xx,
                "timestamp": 1684522041,
                "actEnergyDlvd": 0.000,
                "actEnergyRcvd": 0.000,
                "apparentEnergy": 0.000,
                "reactEnergyLagg": 0.000,
                "reactEnergyLead": 0.000,
                "instantaneousDemand": -0.724,
                "activePower": -0.724,
                "apparentPower": 25.686,
                "reactivePower": 0.582,
                "pwrFactor": 0.000,
                "voltage": 233.027,
                "current": 0.111,
                "freq": 50.000
            },
            {
                "eid": xx,
                "timestamp": 1684522041,
                "actEnergyDlvd": 0.000,
                "actEnergyRcvd": 0.000,
                "apparentEnergy": 0.000,
                "reactEnergyLagg": 0.000,
                "reactEnergyLead": 0.000,
                "instantaneousDemand": -0.000,
                "activePower": -0.000,
                "apparentPower": 0.000,
                "reactivePower": -0.000,
                "pwrFactor": 0.000,
                "voltage": 237.044,
                "current": -0.000,
                "freq": 50.000
            },
            {
                "eid": xx,
                "timestamp": 1684522041,
                "actEnergyDlvd": 0.000,
                "actEnergyRcvd": 0.000,
                "apparentEnergy": 0.000,
                "reactEnergyLagg": 0.000,
                "reactEnergyLead": 0.000,
                "instantaneousDemand": -0.000,
                "activePower": -0.000,
                "apparentPower": 56.381,
                "reactivePower": -0.000,
                "pwrFactor": 0.000,
                "voltage": 238.121,
                "current": 0.237,
                "freq": 50.000
            }
        ]
    },
    {
        "eid": xx,
        "timestamp": 1684522041,
        "actEnergyDlvd": 0.000,
        "actEnergyRcvd": 0.000,
        "apparentEnergy": 0.000,
        "reactEnergyLagg": 0.000,
        "reactEnergyLead": 0.000,
        "instantaneousDemand": -3.193,
        "activePower": -3.193,
        "apparentPower": 69.516,
        "reactivePower": -0.623,
        "pwrFactor": 0.000,
        "voltage": 708.202,
        "current": 0.292,
        "freq": 50.000,
        "channels": [
            {
                "eid": xx,
                "timestamp": 1684522041,
                "actEnergyDlvd": 0.000,
                "actEnergyRcvd": 0.000,
                "apparentEnergy": 0.000,
                "reactEnergyLagg": 0.000,
                "reactEnergyLead": 0.000,
                "instantaneousDemand": 0.000,
                "activePower": 0.000,
                "apparentPower": -0.000,
                "reactivePower": -0.000,
                "pwrFactor": 0.000,
                "voltage": 233.014,
                "current": 0.000,
                "freq": 50.000
            },
            {
                "eid": xx,
                "timestamp": 1684522041,
                "actEnergyDlvd": 0.000,
                "actEnergyRcvd": 0.000,
                "apparentEnergy": 0.000,
                "reactEnergyLagg": 0.000,
                "reactEnergyLead": 0.000,
                "instantaneousDemand": -1.226,
                "activePower": -1.226,
                "apparentPower": 24.477,
                "reactivePower": -0.623,
                "pwrFactor": 0.000,
                "voltage": 236.935,
                "current": 0.103,
                "freq": 50.000
            },
            {
                "eid": xx,
                "timestamp": 1684522041,
                "actEnergyDlvd": 0.000,
                "actEnergyRcvd": 0.000,
                "apparentEnergy": 0.000,
                "reactEnergyLagg": 0.000,
                "reactEnergyLead": 0.000,
                "instantaneousDemand": -1.967,
                "activePower": -1.967,
                "apparentPower": 45.039,
                "reactivePower": 0.000,
                "pwrFactor": 0.000,
                "voltage": 238.253,
                "current": 0.189,
                "freq": 50.000
            }
        ]
    }
]

Hi Steve,

Complete repsonse is exactly the same as reinhochstenbach posted.

Seems like I can get some data around this api:
https://envoy.local/api/v1/production/inverters
it response is updated every 5 minutes en gives data for each of my inverters:

[
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746033,
        "devType": 1,
        "lastReportWatts": 102,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746033,
        "devType": 1,
        "lastReportWatts": 109,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746036,
        "devType": 1,
        "lastReportWatts": 96,
        "maxReportWatts": 296
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746038,
        "devType": 1,
        "lastReportWatts": 111,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746039,
        "devType": 1,
        "lastReportWatts": 111,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746042,
        "devType": 1,
        "lastReportWatts": 100,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746044,
        "devType": 1,
        "lastReportWatts": 92,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746044,
        "devType": 1,
        "lastReportWatts": 63,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746047,
        "devType": 1,
        "lastReportWatts": 109,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746049,
        "devType": 1,
        "lastReportWatts": 110,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746050,
        "devType": 1,
        "lastReportWatts": 103,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746053,
        "devType": 1,
        "lastReportWatts": 105,
        "maxReportWatts": 296
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746054,
        "devType": 1,
        "lastReportWatts": 100,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746055,
        "devType": 1,
        "lastReportWatts": 94,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746058,
        "devType": 1,
        "lastReportWatts": 108,
        "maxReportWatts": 296
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746059,
        "devType": 1,
        "lastReportWatts": 108,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746061,
        "devType": 1,
        "lastReportWatts": 109,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746064,
        "devType": 1,
        "lastReportWatts": 90,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746066,
        "devType": 1,
        "lastReportWatts": 112,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746067,
        "devType": 1,
        "lastReportWatts": 86,
        "maxReportWatts": 296
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746070,
        "devType": 1,
        "lastReportWatts": 97,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746071,
        "devType": 1,
        "lastReportWatts": 89,
        "maxReportWatts": 296
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746073,
        "devType": 1,
        "lastReportWatts": 94,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746077,
        "devType": 1,
        "lastReportWatts": 94,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746079,
        "devType": 1,
        "lastReportWatts": 70,
        "maxReportWatts": 296
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746078,
        "devType": 1,
        "lastReportWatts": 92,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746083,
        "devType": 1,
        "lastReportWatts": 109,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746085,
        "devType": 1,
        "lastReportWatts": 102,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746085,
        "devType": 1,
        "lastReportWatts": 100,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746088,
        "devType": 1,
        "lastReportWatts": 107,
        "maxReportWatts": 297
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746090,
        "devType": 1,
        "lastReportWatts": 91,
        "maxReportWatts": 296
    },
    {
        "serialNumber": "XX",
        "lastReportDate": 1684746089,
        "devType": 1,
        "lastReportWatts": 101,
        "maxReportWatts": 297
    }
]

Maybe I can iterate through the json and calculate the sum of lastReportWatts for all of the inverters and take that as a reading.

having the same question
on the installer page http://enphase.local/installer/setup/home# there’s a button below to disable/enable Power Production

would be great if i can toggle this in HA

wuuuut?

Are you on the 7.x firmware? Is everything correct when you login to enlighten or use the phone app? Something is definitely weird with your setup?

Thanks for this post, very usefull.

I can’t get any value’s from the local URL.

I did create a API key with the /entrez-auth-token?serial_num= URL. And the API key works, I can access the local web page with it.

But there is 0 response from the REST call;

Well, there is a response, just a very very brief one, no values etc.

You can’t do it in the browser- or at least I don’t think so. You would need to send the authorization header. You need to to use curl

When I first hit the URL, it says that i need to authorize, i paste the api key, and the authorization dialogue goes away, and I get to see the empty brackets. What I know from rest, you should always be able to see it from a browser.

Anyway, I’ve also tried the rest sensor in HA. It’s created, but has a unknown value;

Solar Array Production
20 seconds ago
Unknown

I have a very new system, installed yesterday;

Software Version
D7.6.168 (f1975b)

Something wrong there, seems like rest calls are disabled or so…

----------------------- found the answer;

Apparently I have the Enphase Envoy Standard. And for these REST calls to work, you need the Enphase envoy-s-metered. I can do API calls to see the production of the inverters…

For the record; it is very well possible to test you REST api calls in the browser…