Ok, let me try tackle this issue for you.
I cannot guarantee the accuracy as my setup is not the same as yours, so sorry in advance if my solution is not perfect.
Step 1, How can I see what my system is currently setup as?
Go to https://envoy.local/ivp/meters/
look at the value of [1].measurementType
value: net-consumption = Load with solar production.
value: total-consumption = Load only
Step 2, show the difference between load only and net.
This is where things differ.
View the value of [1].activePower at the URL https://envoy.local/ivp/meters/readings
- When set to total-consumption/(load only), this value will only ever be positive as it represents what the appliances in house are demanding/consuming.
- When set to net-consumption/(load with solar production), you will either see a negative value to indicate power grid export or a positive value to indicate grid import as this value represents what is occurring at the utility/grid/meter.
Example of a user with total-consumption/(load only)
Step 3, what can we calculate with load only?
Source: /ivp/meters/readings | Description | W | kW |
---|---|---|---|
value_json[0].activePower | Power Production | 2000 | 2.0 |
value_json[1].activePower | Power Consumption | 1337.395 | 1.33 |
template sensor calculation | Power Net (Calculated) (consumption-production) | -662.605 | -0.66 |
template sensor calculation | Power Export (Calculated) (production-consumption) | 662.605 | 0.66 |
template sensor calculation | Power Import (Calculated) (consumption-production) | 0 | 0 |
The problem with load only setting is that the value for [1].actEnergyRcvd is empty at https://envoy.local/ivp/meters/readings.
Example of a user with total-consumption/(load only)
The absense of that value causes the energy calculations to no longer be possible.
Source: /ivp/meters/readings | Description | Wh | MWh |
---|---|---|---|
value_json[0].actEnergyDlvd | Energy Production | 609552.964 | 0.6 |
value_json[1].actEnergyDlvd | Energy Consumption | 447569.605 | 0.44 |
template sensor calculation | Energy Export (Calculated) | not possible | |
template sensor calculation | Energy Net (Calculated) | not possible | |
template sensor calculation | Energy Import (Calculated) | not possible |
Step 4, How do we fill the gap for load only users?
Create the following sensors for Load Only installations.
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 Consumption"
value_template: "{{ value_json[1].activePower | int(0) }}"
state_class: measurement
device_class: power
unit_of_measurement: W
icon: mdi:home-lightning-bolt
- name: "Energy Production"
value_template: "{{ (value_json[0].actEnergyDlvd / 1000 | float(0)) | round(2) }}"
device_class: energy
unit_of_measurement: kWh
state_class: total_increasing
icon: mdi:solar-panel
- name: "Energy Consumption"
value_template: "{{ (value_json[1].actEnergyDlvd / 1000 | float(0)) | round(2) }}"
device_class: energy
unit_of_measurement: kWh
state_class: total_increasing
icon: mdi:home-lightning-bolt
Then i added these template sensors to calculate power export and power import
template:
- 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 }}
- sensor:
name: Power Net
state_class: measurement
icon: mdi:transmission-tower
unit_of_measurement: W
device_class: power
state : >
{{ states('sensor.power_consumption') | int(0) - states('sensor.power_production') | int(0) }}
And then finally, add these 2 sensors to convert:
power in W
to
energy in kWh
using https://www.home-assistant.io/integrations/integration/
sensor:
- platform: integration
name: Energy Import
source: sensor.power_import
unit_prefix: k
unit_time: h
method: left
- platform: integration
name: Energy Export
source: sensor.power_export
unit_prefix: k
unit_time: h
method: left
I am unable to test this myself, so feel free to give it a go and let me know.