I’ll have to play around with it a bit more. Maybe I can get something to work.
I maintain the Enphase Envoy sensor code in Home Assistant (or atleast try to been bust the last few months) just getting back to it now and trying to get the Return to Grid values to correctly appear in Home Assistant.
I have access to multiple Envoys, but only have one at home. The others are for testing
From my understanding just adding an Envoy to Home Assistant is not enough to have the Energy Dashboard show, Solar Production, Consumption, and Return to Grid values. Currently the only sensors that can be added from the Envoy to Home Assistant that will appear in the Energy Dashboard are for the Solar Production and Total Consumption. Right?
So to display Return to Grid values people have to make their own sensor/template. They really should not have to do that.
I agree with you on the shouldnt have to setup extra sensors part, however what I have learned is that the envoy is not collecting grid in and grid out figures separately.
From the envoy point of view, it has 1 CT clamp is on the mains measuring energy going EITHER to OR from the grid (never both) and by how much. Thats the issue here. The grid in/out figure is combined and stored in a single value as consumption. (because you will never have grid in/out occuring at the same time). The current version of the energy dashboard needs these figures separated.
The only other figure envoy is interested in is solar panel production which is stored under production.
Currently the only way to separate these grid in/out figures stored in current_consumption is to calculate them against current_production and get the difference.
In order to do that you need both:
You need to subtract current_production from current_consumption to calculate and separate grid import.
You need to subtract current_consumption from current_production to calculate and separate grid export.
I suspect providing an extra net-consumption figure will not change this but I welcome you to try.
The only solution I can see is perhaps the Home Assistant Devs improving future versions of the energy dashboard so that it can ingest solar inverter lifetime energy production and lifetime energy consumption figures and do the difference calculation for us. That will remove the need for us to create sensors manually. At the moment that is not an option.
I would say any figure other than 0 once the sun has gone down is not mean to happen.
If you have a constant minus figure overnight, wouldnt that cause your production totals to go down/backwards?
For some reason, I am getting zeroes for all the grid values. And, now I am wondering whether it’s worth the effort to set this up.
I had set up a simple dashboard with Grafana with InfluxDB as the database and it was fun to play around with. This [screenshot] is the first version of the Grafana dashboard I’m working on right now…
I would say that the only sensor that actually works with energy dashboard is Solar Production Lifetime.
If you try to use Total Consumption Lifetime, it wont be accurate.
Total Consumption Lifetime doesnt only represent just grid import, it also includes power the house consumed from the solar panels which has nothing to do with the grid. That makes this sensor inaccurate and irrelevant for use anywhere in the energy dashboard.
You should definitely try out the Grafana, InfluxDB integrations in HomeAssistant. It’s very powerful to create beautiful dashboards and pretty easy to learn.
I have some nice graphs in grafana as wel. Maybe this could be an inspiration for someone. If not, scroll further
Each bar is one day.
Gebruik = import
Levering = export
@del13r If the Total Consumption data coming directly from the Enphase Envoy is inaccurate what should it be, as the API is just reading data from the device which should be doing the calculations from W to Wh on its own. Enphase MyEnlighten should be using the same values that I am pulling from the envoy_reader API, are those values inaccurate?
I’m just trying to get a sense of what might need to be changed in the code, so others don’t have to create sensors in Home Assistant for them to get good energy data. Please understand I don’t have access to an Envoy with Consumption and MyEnlighten to compare data values.
It appears that my enlighten may also doing the same calculation in their front end.
The only reason why I said the word inaccurate is because the consumption figure available to us in home assistant includes both grid and home/self consumption combined. This combining of the data is what makes it a inaccurate source for home assistant energy dashboard.
Once we subtract production from consumption, currently via manually created sensors, that is what makes it accurate allows us to see the accurate grid consumption is what I meant.
Hi,
Love the work @del13r .
I’m sorry to have to do this. I have spend the last 3 night after work trying to nut this out.
From ready over this thread many times, I suspect it is my config.
I am only getting the Energy IMPORT available in the Energy integration. The Energy Export and Solar Corrected do not come up as entities for me to select.
Could anyone please help me know where I am going wrong to get this going.
template:
- sensor:
name: Grid Import Power
state_class: measurement
icon: mdi:transmission-tower
unit_of_measurement: W
device_class: power
state: >
{{ [0, states('sensor.oakmont_solar_current_energy_consumption') | int - states('sensor.oakmont_solar_current_energy_production') | int ] | max }}
- sensor:
name: Grid Export Power
state_class: measurement
icon: mdi:transmission-tower
unit_of_measurement: W
device_class: power
state: >
{{ [0, states('sensor.oakmont_solar_current_energy_production') | int - states('sensor.oakmont_solar_current_energy_consumption') | int ] | max }}
- sensor:
name: Solar Power Corrected
state_class: measurement
icon: mdi:solar-panel
unit_of_measurement: W
device_class: power
state: >
{% set value = states('sensor.oakmont_solar_current_energy_production') | int %}
{% if value <= 5 %}
0
{% elif is_state("sun.sun","below_horizon") %}
0
{%- else -%}
{{ value }}
{%- endif %}
sensor:
- platform: template
sensors:
envoy_current_exporting:
friendly_name: "Current Energy Exporting"
value_template: "{{ [0, (states('sensor.oakmont_solar_current_energy_production') | int - states('sensor.oakmont_solar_current_energy_consumption') | int)] | max }}"
unit_of_measurement: 'W'
icon_template: 'mdi:flash'
envoy_current_importing:
friendly_name: "Current Energy Importing"
value_template: "{{ [0, (states('sensor.oakmont_solar_current_energy_consumption') | int - states('sensor.oakmont_solar_current_energy_production') | int)] | max }}"
unit_of_measurement: 'W'
icon_template: 'mdi:flash'
- platform: integration
name: Grid Import Energy
source: sensor.grid_import_power
unit_prefix: k
unit_time: h
device_class: energy
- platform: integration
name: Grid Export Energy
source: sensor.grid_export_power
unit_prefix: k
unit_time: h
device_class: energy
- platform: integration
name: Solar Energy Corrected
source: sensor.solar_power_corrected
unit_prefix: k
unit_time: h
device_class: energy
type or paste code here
Really appreciate any assistance. Its doing my head in.
@hooha_mc I had to manually change one or two of the energy entities ‘device_class’ attributes to energy in the customisation section in settings/configuration before they showed up, even though I defined them in my yams. You may have the same issue, suggest double checking that attribute is being set first, else they won’t show
It seems you have tried to add device class energy to the (not template) integration sensor. This is not allowed in this part of the config for the integration platform and should not be needed if the source power sensors are providing the correct format. I suspect the presence of these device_class lines is causing platform: integration sensors to fail to load. If you are eagle eyed, you might have even noticed Home Assistant trying to warn you when you saved the file with a yellow light next to notifications. Can also go into configuration / logs and see what it had a problem with in the past as well. Please remove those device_class lines from the platform: integration sensors and restore the sensor: line above it
I might also add that if you are doing this at night after work, export won’t show up in the list until the sun starts shining and providing more power than what your house needs.
This page explains what variables are allowed to be used for platform: integration. device_class is not in the list and neither is state_class. You can only ever use what is in the list. Integration - Riemann sum integral - Home Assistant
If you want to force device_class and state_class onto the integration sensors, this is done in the customize.yaml but is optional not required.
customize.yaml
sensor.grid_export_energy:
device_class: energy
unit_of_measurement: kWh
sensor.grid_import_energy:
device_class: energy
unit_of_measurement: kWh
I noticed my enphase sensors have a slightly different name since the developer recently updated the enphase sensor names from energy to power to more accurately show what type of device class it is just in the sensor name. Please check your sensor names match what is actually in your dev tools / states list just in case the oakmount dev has done the same.
Also, not really sure what you are trying to do with these other sensors as they seem redundant because none of the integration sensors list these as a source for converting into energy. That is all the platform: integration sensors do is convert a power figure in W to an energy figure in kWh. I’d you are not feeding correctly formatted power figures into an equivalent integration sensor, I would recommend removing these from the config as it’s just confusing. If you are planning to try to use them anyway I did notice they are missing both the device_class: power and state_class: measurement
You are allowed to add those line to template sensors. You cannot add those lines to the integration sensors
sensor:
- platform: template
sensors:
envoy_current_exporting:
friendly_name: "Current Energy Exporting"
value_template: "{{ [0, (states('sensor.oakmont_solar_current_energy_production') | int - states('sensor.oakmont_solar_current_energy_consumption') | int)] | max }}"
unit_of_measurement: 'W'
icon_template: 'mdi:flash'
envoy_current_importing:
friendly_name: "Current Energy Importing"
value_template: "{{ [0, (states('sensor.oakmont_solar_current_energy_consumption') | int - states('sensor.oakmont_solar_current_energy_production') | int)] | max }}"
unit_of_measurement: 'W'
icon_template: 'mdi:flash'