Enphase local API with firmware 7.x - my setup

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…

Hi, this looks like a really elegant solution. I’ve created the proper secret and placed this in the configuration.yaml, and after a reload it shows as available for the Energy dashboard, however it’s unable to load any data, and gives me the statistics_not_found error someone else in this thread also mentioned:

When I go to https://envoy.local/ivp/meters/readings I see populated data fields, so it seems to be working:

[
    {
        "eid": xx,
        "timestamp": 1686945645,
        "actEnergyDlvd": 0.000,
        "actEnergyRcvd": 0.000,
        "apparentEnergy": 0.000,
        "reactEnergyLagg": 0.000,
        "reactEnergyLead": 0.000,
        "instantaneousDemand": -12.539,
        "activePower": -12.539,
        "apparentPower": 236.613,
        "reactivePower": 204.446,
        "pwrFactor": -0.048,
        "voltage": 664.372,
        "current": 1.067,
        "freq": 50.000,
        "channels": [
            {
                "eid": xx,
                "timestamp": 1686945645,
                "actEnergyDlvd": 0.000,
                "actEnergyRcvd": 0.000,
                "apparentEnergy": 0.000,
                "reactEnergyLagg": 0.000,
                "reactEnergyLead": 0.000,
                "instantaneousDemand": -2.911,
                "activePower": -2.911,
                "apparentPower": 41.091,
                "reactivePower": 41.091,
                "pwrFactor": 0.000,
                "voltage": 218.207,
                "current": 0.188,
                "freq": 50.000
            },
            {
                "eid": xx,
                "timestamp": 1686945645,
                "actEnergyDlvd": 0.000,
                "actEnergyRcvd": 0.000,
                "apparentEnergy": 0.000,
                "reactEnergyLagg": 0.000,
                "reactEnergyLead": 0.000,
                "instantaneousDemand": -4.864,
                "activePower": -4.864,
                "apparentPower": 121.188,
                "reactivePower": 89.021,
                "pwrFactor": -0.045,
                "voltage": 222.549,
                "current": 0.545,
                "freq": 50.000
            },
            {
                "eid": xx,
                "timestamp": 1686945645,
                "actEnergyDlvd": 0.000,
                "actEnergyRcvd": 0.000,
                "apparentEnergy": 0.000,
                "reactEnergyLagg": 0.000,
                "reactEnergyLead": 0.000,
                "instantaneousDemand": -4.764,
                "activePower": -4.764,
                "apparentPower": 74.334,
                "reactivePower": 74.334,
                "pwrFactor": -0.077,
                "voltage": 223.616,
                "current": 0.333,
                "freq": 50.000
            }
        ]
    },
    {
        "eid": xx,
        "timestamp": 1686945645,
        "actEnergyDlvd": 0.000,
        "actEnergyRcvd": 0.000,
        "apparentEnergy": 0.000,
        "reactEnergyLagg": 0.000,
        "reactEnergyLead": 0.000,
        "instantaneousDemand": 666.108,
        "activePower": 666.108,
        "apparentPower": 986.725,
        "reactivePower": -491.181,
        "pwrFactor": 0.691,
        "voltage": 664.538,
        "current": 4.463,
        "freq": 50.000,
        "channels": [
            {
                "eid": xx,
                "timestamp": 1686945645,
                "actEnergyDlvd": 0.000,
                "actEnergyRcvd": 0.000,
                "apparentEnergy": 0.000,
                "reactEnergyLagg": 0.000,
                "reactEnergyLead": 0.000,
                "instantaneousDemand": 327.920,
                "activePower": 327.920,
                "apparentPower": 390.753,
                "reactivePower": -92.558,
                "pwrFactor": 0.847,
                "voltage": 218.198,
                "current": 1.795,
                "freq": 50.000
            },
            {
                "eid": xx,
                "timestamp": 1686945645,
                "actEnergyDlvd": 0.000,
                "actEnergyRcvd": 0.000,
                "apparentEnergy": 0.000,
                "reactEnergyLagg": 0.000,
                "reactEnergyLead": 0.000,
                "instantaneousDemand": 285.530,
                "activePower": 285.530,
                "apparentPower": 363.707,
                "reactivePower": -178.180,
                "pwrFactor": 0.803,
                "voltage": 222.537,
                "current": 1.630,
                "freq": 50.000
            },
            {
                "eid": xx,
                "timestamp": 1686945645,
                "actEnergyDlvd": 0.000,
                "actEnergyRcvd": 0.000,
                "apparentEnergy": 0.000,
                "reactEnergyLagg": 0.000,
                "reactEnergyLead": 0.000,
                "instantaneousDemand": 52.657,
                "activePower": 52.657,
                "apparentPower": 232.266,
                "reactivePower": -220.443,
                "pwrFactor": 0.238,
                "voltage": 223.802,
                "current": 1.038,
                "freq": 50.000
            }
        ]
    }
]

The Envoy is on firmware D7.0.88 (5580b1). Can you help me figure out what I’m missing?

If you open that entity does it show a value?

Also, can you post the block of yaml where you define the sensor?

How do you enter the token with a browswer? If I go to: https://envoy.local/ivp/meters/readings in Chrome, I just get 401 - not authorized

ha_steve; When I enter the URL; https://envoy.local/api/v1/production I get the unauthorized message, and after that I’m redirected to this login page;

Like I said in my previous post, I just paste my API key. And reopen the URL; https://envoy.local/api/v1/production e voila, I get the JSON as text in the browser;

As long as I have been working with REST API’s, this is a general trick to do troubleshooting.

So for those with a ‘Enphase Envoy-s Standard’, you can use this REST yaml;

rest:
  - headers:
      Authorization: !secret enphase_api_token
    verify_ssl: False
    scan_interval: 60
    resource: https://envoy.local/api/v1/production
    sensor:
      - name: "Zonne panelen huidige opbrengst"
        unique_id: zonne_panelen_opbrengst_nu"
        value_template: "{{ value_json.wattsNow | float }}"
        device_class: power
        state_class: measurement
        unit_of_measurement: W
      - name: "Zonne panelen opbrengst vandaag"
        unique_id: zonne_panelen_opbrengst_vandaag"
        value_template: "{{ value_json.wattHoursToday | float }}"
        device_class: energy
        state_class: measurement
        unit_of_measurement: Wh
      - name: "Zonne panelen totaal opbrengst"
        unique_id: zonne_panelen_opbrengst_totaal"
        value_template: "{{ value_json.wattHoursLifetime | float }}"
        device_class: energy
        state_class: measurement
        unit_of_measurement: Wh        
  - headers:
      Authorization: !secret enphase_api_token
    verify_ssl: False
    scan_interval: 60
    resource: https://envoy.local/api/v1/production/inverters
    sensor:
      - name: "Inverter 1 Power Output"
        unique_id: solar_power_inverter_1
        value_template: "{{ value_json[0].lastReportWatts | float }}"
        device_class: power
        state_class: measurement        
        unit_of_measurement: W
      - name: "Inverter 2 Power Output"
        unique_id: solar_power_inverter_2
        value_template: "{{ value_json[1].lastReportWatts | float }}"
        device_class: power
        state_class: measurement        
        unit_of_measurement: W
      - name: "Inverter 3 Power Output"
        unique_id: solar_power_inverter_3
        value_template: "{{ value_json[2].lastReportWatts | float }}"
        device_class: power
        state_class: measurement        
        unit_of_measurement: W
      - name: "Inverter 4 Power Output"
        unique_id: solar_power_inverter_4
        value_template: "{{ value_json[3].lastReportWatts | float }}"
        device_class: power
        state_class: measurement        

Ofcourse you also have to get your API code etc…

1 Like

This is why. For the IQ-series, you must send the Authorization header with the Bearer token. There is no way (without some extensions) to manually do this in a browser. This is all documented here: Enphase documentation