Update 21/July/2023 - I have started a new topic that uses a 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.
Original guide from August 2021 - I am setting up a new topic here as Energy Management in Home Assistant is getting pretty crowded and hard to follow with over 380 posts.
Ok, so, all of this recent activity started when when Home Assistant 2021.8 launched with a new Energy feature.
My Enphase Envoy was not doing what I expected it to do in Home Assistant so I read some other posts and this is what I came up with to get it working.
I wont go into detail about why it didnt work, but rather concentrate on what i did to get it working.
As a pre-requisite, please make sure your envoy is a metered version.
This can be confirmed multiple ways.
Within home assistant, go to developer tools / states and search the page for _current
If you see these entries (they dont have to be identical), and they have numbers in the state column in the middle, then you have a metered enphase envoy. Production might be 0 or close to 0 at night. That is fine and expected. Also, the unit_of_measurement should be W and state_class should be measurement in the right column.
Please pay very close attention to the sensor name and note if it says energy or power in the name as some older integrations incorrectly say energy and new integrations correctly say power in the sensor name. Don’t panic if yours says energy in the name, it wont break functionality. Its just confusing naming a sensor with the word energy which is meant to be only used for numbers in kWh.
Now we can start creating the power sensors.
I added the following 2 power sensors to my configuration.yaml file
Please make sure to include these lines for these 2 power sensors as they are not optional and failure to include them will mean this wont work. see Sensor Entity | Home Assistant Developer Docs
state class: measurement - The state represents a measurement in present time
device class: power is applied to the latest power measurement expressed in W for Watts
template:
- sensor:
name: Grid Import Power
state_class: measurement
icon: mdi:transmission-tower
unit_of_measurement: W
device_class: power
state: >
{{ [0, states('sensor.envoy_SERIALNUMBER_current_power_consumption') | int(0) - states('sensor.envoy_SERIALNUMBER_current_power_production') | int(0) ] | max }}
- sensor:
name: Grid Export Power
state_class: measurement
icon: mdi:transmission-tower
unit_of_measurement: W
device_class: power
state: >
{{ [0, states('sensor.envoy_SERIALNUMBER_current_power_production') | int(0) - states('sensor.envoy_SERIALNUMBER_current_power_consumption') | int(0) ] | max }}
What do these sensors do?
This allows us to separate incoming grid power and outgoing grid power into 2 seperate numbers which is what the energy dashboard needs.
These sensors only record positive numbers and ignore any negative numbers generated by the formula.
Without this part, you will see negative numbers in your energy dashboard and you definetly dont want that messing things up.
Next, I then added 2 non-template sensors to the configuration.yaml file. Please make sure these energy sensors are placed lower in the config than the template block which has the power sensors
sensor:
- platform: integration
name: Grid Import Energy
source: sensor.grid_import_power
unit_prefix: k
unit_time: h
method: left
- platform: integration
name: Grid Export Energy
source: sensor.grid_export_power
unit_prefix: k
unit_time: h
method: left
These energy sensors do not need any other options as they will format themselves based on positive data from the power sensors. These lines allow the ‘integration’ integration to convert power in W to energy in kWh. See Integration - Riemann sum integral - Home Assistant
What do these do?
These take the live Power readings in W from the first 2 sensors we created and converts them to an Energy reading over time in kWh.
That should be the bare minimum you need to get you started with the energy dashboard.
NOTE: ENERGY DASHBOARD WILL TAKE 1.2 HOURS (1h12m) TO RECORD AND DISPLAY THE LAST HOUR OF DATA.
This is what you will see in your sensors after restarting Home Assistant
Don’t freak out if its night time and your production doesnt show kWh yet, as you will only importing at this very moment. Once the direction of power/energy changes from import to export or vice versa, the energy sensor formatting should fix itself once the power figure no longer equals 0
It is good idea to click on each of these sensors to confirm that recording is working and the graph is charting. Pay particular attention to the energy sensors. Energy sensors should only ever increase.
This should be the bare minimum you need to do to use the ‘grid consumption’ and ‘return to grid’ features in the energy dashboard.
For ‘Solar Production’, the today_s_ENERGY_production sensor is the ONLY enphase sensor that will work with energy dashboard by default without modifying home assistant and creating extra power and energy sensors. This is due to the state_class: total_increasing attribute that ONLY this sensor appears to have. This is fine as this is the only Enphase sensor that needs this attribute.
NOTE: ENERGY DASHBOARD WILL TAKE 1.2 HOURS (1h12m) TO RECORD AND DISPLAY THE LAST HOUR OF DATA.