Not a problem but no, this is a valid octet in my network config. Still no matter what I do I get no statuses and the state problem I earlier mentioned. Other docs don’t provide a solution. Is the code I used the one you have it working with?
Your enphase_api
in your secrets.yaml should be defines as:
enphase_api: Bearer eyJraWQiOiI.....
Just making sure you have the word ‘Bearer’ at the beginning. You can also check the logs to see what errors are being produced.
I added the ‘Bearer’ text in front of the token in the secrets.yaml did the trick.Thanks for sticking with me on this one, much obliged!
Hmm apparently I was a bit early cheering, because the actEnergyDlvd
value seems to be empty when I query the Envoy. I did however find another way of displaying the statistics via https://envoy.local/production.json?details=1. It also seems that you can poll this URL like every 500ms so you can get near-realtime statistics. But also in this json view I see that my ‘whToday’ value is empty, so there seems to be something strange going on with my Envoy. Will inspect and keep you posted.
I’m seeing the same behavior both with this new URL and my whToday value is 0 as well as /ivp/meters/readings URL and my actEnergyDlvd value is 0, my ActivePower value is correct however.
This is what I see when I query my device.
{
"eid": 704643328,
"timestamp": 1687269641,
"actEnergyDlvd": 0.000,
"actEnergyRcvd": 0.000,
"apparentEnergy": 0.000,
"reactEnergyLagg": 0.000,
"reactEnergyLead": 0.000,
"instantaneousDemand": 3829.339,
"activePower": 3829.339,
"apparentPower": 4040.183,
"reactivePower": 1107.200,
"pwrFactor": 0.948,
"voltage": 244.966,
"current": 32.503,
"freq": 60.000,
"channels": [
{
"eid": 1778385169,
"timestamp": 1687269641,
"actEnergyDlvd": 0.000,
"actEnergyRcvd": 0.000,
"apparentEnergy": 0.000,
"reactEnergyLagg": 0.000,
"reactEnergyLead": 0.000,
"instantaneousDemand": 1916.977,
"activePower": 1916.977,
"apparentPower": 2023.881,
"reactivePower": 558.906,
"pwrFactor": 0.947,
"voltage": 122.741,
"current": 16.247,
"freq": 60.000
},
{
"eid": 1778385170,
"timestamp": 1687269641,
"actEnergyDlvd": 0.000,
"actEnergyRcvd": 0.000,
"apparentEnergy": 0.000,
"reactEnergyLagg": 0.000,
"reactEnergyLead": 0.000,
"instantaneousDemand": 1912.362,
"activePower": 1912.362,
"apparentPower": 2016.302,
"reactivePower": 548.293,
"pwrFactor": 0.950,
"voltage": 122.225,
"current": 16.256,
"freq": 60.000
},
{
"eid": 1778385171,
"timestamp": 1687269641,
"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": 0.000,
"current": 0.000,
"freq": 60.000
}
]
},
{
"eid": 704643584,
"timestamp": 1687269641,
"actEnergyDlvd": 0.000,
"actEnergyRcvd": 0.000,
"apparentEnergy": 0.000,
"reactEnergyLagg": 0.000,
"reactEnergyLead": 0.000,
"instantaneousDemand": 639.052,
"activePower": 639.052,
"apparentPower": 1217.303,
"reactivePower": 836.618,
"pwrFactor": 0.494,
"voltage": 244.882,
"current": 9.772,
"freq": 60.000,
"channels": [
{
"eid": 1778385425,
"timestamp": 1687269641,
"actEnergyDlvd": 0.000,
"actEnergyRcvd": 0.000,
"apparentEnergy": 0.000,
"reactEnergyLagg": 0.000,
"reactEnergyLead": 0.000,
"instantaneousDemand": -50.215,
"activePower": -50.215,
"apparentPower": 66.753,
"reactivePower": 19.450,
"pwrFactor": -0.778,
"voltage": 122.729,
"current": 0.544,
"freq": 60.000
},
{
"eid": 1778385426,
"timestamp": 1687269641,
"actEnergyDlvd": 0.000,
"actEnergyRcvd": 0.000,
"apparentEnergy": 0.000,
"reactEnergyLagg": 0.000,
"reactEnergyLead": 0.000,
"instantaneousDemand": 689.267,
"activePower": 689.267,
"apparentPower": 1150.550,
"reactivePower": 817.168,
"pwrFactor": 0.570,
"voltage": 122.154,
"current": 9.228,
"freq": 60.000
},
{
"eid": 1778385427,
"timestamp": 1687269641,
"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": 0.000,
"current": 0.000,
"freq": 60.000
}
]
}
]
The metering was disabled by the company that installed the system. They remotely enabled it and it gives me data now. Perhaps you can ask them?
Hi @ha_steve
Firstly, great solution and write up.
I’ve been monitoring the home assistant and enphase forums, and it would seem a lot of people got their firmware automatically upgraded recently, myself included.
I looked at the code on a few integrations and noticed they all pulled data from https://envoy.local/production.json
From my testing of this URL, it can take anywhere from 400ms to 2000ms for the envoy to generate this json file. I suspect this may be due to the envoy having to perform some calculations every time this url is requested.
This caused me to look for alternatives which led me to https://envoy.local/ivp/meters/readings which from my testing takes on average 50ms to 70ms to respond and offers roughly similar data.
This is where I noticed your thread and decided to do some of my own tweaks.
Here is what I did to get my power sensors back on track.
I removed any existing enphase related integrations (native and/or HACS)
Added my 12 month token to /config/secrets.yaml
enphase_api: "Bearer HIDDENFORPRIVACY"
Then, back in /config/configuration.yaml
rest:
- headers:
Authorization: !secret enphase_api
verify_ssl: False
scan_interval: 15
resource: https://envoy.local/ivp/meters/readings
sensor:
- name: "Power Production"
value_template: >
{% set value = value_json[0].activePower | int(0) %}
{% if value <= 5 -%}
0
{% elif is_state('sun.sun','below_horizon') %}
0
{%- else -%}
{{ value }}
{%- endif %}
device_class: power
unit_of_measurement: W
state_class: measurement
icon: mdi:solar-panel
- name: "Power Net"
value_template: "{{ value_json[1].activePower | int(0) }}"
state_class: measurement
device_class: power
unit_of_measurement: W
icon: mdi:transmission-tower
Then once I was happy with those sensors updating every 15 seconds, I was able to use template sensors to do some calculations with them to get the other sensors I needed.
template:
- sensor:
name: Power Consumption
state_class: measurement
icon: mdi:home-lightning-bolt
unit_of_measurement: W
device_class: power
state : >
{{ states('sensor.power_production') | int(0) + states('sensor.power_net') | int(0) }}
- sensor:
name: Power Export
state_class: measurement
icon: mdi:transmission-tower
unit_of_measurement: W
device_class: power
state : >
{{ [0, states('sensor.power_production') | int(0) - states('sensor.power_consumption') | int(0) ] | max }}
- sensor:
name: Power Import
state_class: measurement
icon: mdi:transmission-tower
unit_of_measurement: W
device_class: power
state : >
{{ [0, states('sensor.power_consumption') | int(0) - states('sensor.power_production') | int(0) ] | max }}
Now I am able to have a dashboard like this that updates every 15 seconds.
Feel free to try a smaller number of seconds for yourself.
Or graphs like this
Thanks a lot!
Hi Ha_Steve, bit by bit I get my system running. How do I execute the first part, the python script. How do I integrated this in HA. You see I’am not a pro.
Thanx Gert Gti-Pro
As it is a 12 month token, I have not figured out how to automate this yet.
In the meantime, if you have python installed, you can use the script on the system that has python installed.
If python is not installed, you can alternatively use 2 curl commands instead.
First curl command logs into enphase with your username and password to get a 32 character session id.
Second curl command uses that 32 character session id that was just created and your envoy serial number to generate the 408 character JWT token.
Please see this post
Have you tried using the link below? If it works, it will save you going through the above python route.
- Log into https://enlighten.enphaseenergy.com/
- Get your serial number by going to Settings > System > Devices
- Go to this URL and you should see the token in the output:
https://enlighten.enphaseenergy.com/entrez-auth-token?serial_num=XXXXXXXXXXXX
- Then follow del13r’s post
@del13r Now that you have the data coming in from Enphase system, have you got sensors for the inbuilt HA energy dashboard rather than standalone cards? I assume it needs to be turned into a sensor that keeps track over time.
I sure do.
I am currently writing the instructions for everyone else to follow.
But as a preview i am using utlity_meter to use the lifetime energy sensors as a source which is able to give me a daily kWh figure.
@del13r This looks interesting.
I have Brian Campbell’s HACS version working reliably at present, but would these two work in parallel? I like to see how yours works before ditching the other.
Also - with the 15 second scan interval, is that reflected in your HA dashboard? Mine currently updates every 60 seconds.
Hi @Steve61,
Yes, as the sensor names are different, they should not conflict with the HACS sensors.
The only conflict I forsee with running both in parallel is if you configure the rest Energy sensors and the HACS Energy sensors into Energy Dashboard, you will see double the consumption and production.
As for the graphs, they indeed update every X seconds as do the template sensors that perform the calculations.
Thank you.
In looking at what you have published above, and my Envoy’s output I am assuming it does not give individual micro-inverter data? (Like the integration does)
I use the power of a couple of panels to set conditions in some automations (ie don’t close blind if power of panel xyz is less than x). It’s a proxy for how much sun we are getting.
I like the response rate of your solution, so I might end up using both.
Hi @Steve61,
Yes, correct, I am only extracting what information I am interested in from the envoy, that I can obtain from the URL i am using as a source.
Unfortunately that source of information I am using does not have individual inverter statistics.
In regards to automation, I find that most of mine are setup to evaluate the value of power_import for x minutes
For example here is what i use to turn off the pool pump off when the house starts consuming 200W or more of power from the grid for 8 mins.
- alias: Pool Pump Off grid import
trigger:
- platform: numeric_state
entity_id: sensor.power_import
for:
hours: 0
minutes: 8
seconds: 0
above: 200
Alrighty guys,
Here is the fully manual solution I came up with using just the rest sensor for Enphase Envoy on D7 firmware.
It’s a lengthy guide with lots of explanation.
Hopefully it helps someone else out.
I hope @ha_steve doesn’t mind, but I took his code and put it up on Github. I found it very useful.
I’ve also included the Envoy configuration settings I use in my configuration.yaml.