Enphase Envoy on 2024.4

It’s been a few years since I wrote my original guide on how to get Enphase Envoy working with Home Assistant Energy Dashbard.
I figured I would try start from scratch to document what the process and experience would be like for a brand new user with Home Assistant version 2024.4.

Let’s start with my solar setup.
I live in Australia and since 3 years ago in April 2021, I have owned an Enphase Envoy that looks like this on the left and has 2 CT clamps as shown on the right for consumption/production monitoring.

image

Details obtained from the device remotely by visiting https://envoy.local/home and logging in to it using my enphase enlighten/enphase cloud credentials.

Part Number
800-00654-r06
Software Version
D7.6.175 (f79c8d)
Software Build Date
22 Jun, 2023 8:43 PM

In all of the following screenshots, I will be removing my serial number and IP address information for privacy.

New Home Assistant installation

I setup a brand new copy of Home Assistant and once it was finished installing, I found that Home Assistant had automatically discovered my Envoy on the wifi network.

image

I pressed configure and was asked for my Enphase cloud credentials.
To be clear, these are the same credentials you use to login to https://enlighten.enphaseenergy.com/

Once those credentials are accepted, it then shows a Success! message

image

Observations:

  • All power sensors are in kW. (1,000 W = 1 kW)

  • All energy sensors are in kWh. (1 kW of power continuous load over 60mins = 1 kWh of energy consumed)

  • All lifetime energy sensors are in MWh. (1,000,000 Wh = 1,000 kWh = 1 MWh)

  • Each sensor is updated every 60 seconds.

Energy Dashboard

It is pointless trying to get these Enphase provided energy sensors to be used by the Energy Dashboard in their default state as the energy data is different to what is expected by Energy Dashboard, but that doesnt mean we can’t improvise.

The Envoy integration provides sensors for:

  • house consumption instead of grid consumption
    Note: If the house consumes more than the solar system is producing, the house will import the excess power difference it needs from the grid.

  • solar production instead of return to grid
    Note: solar production will first be consumed by the house and if production power is higher than what the house consumes, the excess power difference will be returned to the grid.

As it is physically impossible for your house to be importing and exporting power at the exact same time, we can exploit the mathematical difference between solar production and house consumption to calculate if your house is importing power from the grid or exporting power to the grid.

To get Home Assistant to calculate this for us, we have to setup a template sensor in Home Assistant to calculate what Energy Dashboard is expecting.

The guide is focussed on 2 steps.

Step 1 - Setting up template sensors to perform calculations using data from the enphase sensors.
The template sensors we need to create are:
power import in W (grid in)
power export in W (grid out)

Step 2 - Setting up Riemann Sum sensors which convert:
power import in W to energy import in kWh
power export in W to energy export in kWh

Note: Some people may ask “can’t I have everything in kW?”.
The answer is that the Riemann Sum sensors expect the data source to be in W.
Watts are the only way I could get the Riemann Sum sensors to work.

Edit, I just tried it without specifying the metric prefix, and it will work with whatever source metric you are using.
The issue is, once you click on a metric prefix, you cannot seem to unclick it in the GUI.

If you mess this up, you can correct it in Developer tools

Step 1a - Create a Power Export Template Sensor

Go to settings
image

Devices and services
image

Helpers
image

+Create Helper
image

{} Template
image

Template a sensor
image

Template sensor

Name: Power Export

State template:

{{
[ 0,
states('sensor.envoy_SERIALNUMBER_current_power_production')
| float(0) * 1000
-
states('sensor.envoy_SERIALNUMBER_current_power_consumption')
| float(0) * 1000 ]
| max | int(0)
}}

unit_of_measurement: W
device_class: Power
state_class: Measurement

Press Submit

Step 1b - Create a Power Import Template Sensor

Go to settings
image

Devices and services
image

Helpers
image

+Create Helper
image

{} Template
image

Template a sensor
image

Template sensor

Name: Power Import

State template:

{{
[ 0,
states('sensor.envoy_SERIALNUMBER_current_power_consumption')
| float(0) * 1000
-
states('sensor.envoy_SERIALNUMBER_current_power_production')
| float(0) * 1000 ]
| max | int(0)
}}

unit_of_measurement: W
device_class: Power
state_class: Measurement

Press Submit

Step 1 complete

Step 2a - Create Energy Export Sensor

Go to settings
image

Devices and services
image

Helpers
image

+Create Helper
image

Integration - Riemann sum integral sensor
image

Add Riemann sum integral sensor
Name: Energy Export
Input Sensor: Power Export
Integration Method: Right Riemann Sum
Precision: 3 is default
Metric Prefix: k (kilo)
Time Unit: Hours

Press submit.

Step 2b - Create Energy Import Sensor

Go to settings
image

Devices and services
image

Helpers
image

+Create Helper
image

Integration - Riemann sum integral sensor
image

Add Riemann sum integral sensor
Name: Energy Import
Input Sensor: Power Import
Integration Method: Right Riemann Sum
Precision: 3 is default
Metric Prefix: k (kilo)
Time Unit: Hours

Press submit.

You should now have
2 template based Power sensors
and
2 Integration based Energy Sensors

Step 2 complete.

Note: As it is night time right now for me, my Energy Export sensor will not work at all until tomorrow when the sun starts shining again.

If it is night time, the energy sensor will not be formatted correctly yet.
You can tell due to the subtle difference between the image icon and the image icons for the Energy sensors.

For now, I can go to
Energy
image

and then setup Grid Consumption
image

Choose the Energy Import sensor you just created.
image

I then added my Solar production energy using the sensor:
Envoy SERIALNUMBER Energy production today
image

I then left these overnight to see what happened and what I found was that I had a small amount of production energy occuring overnight which is physically impossible when the sun is below the horizon and something I want to fix in in a post after this post.

2 Likes

Thanks for the work, very clear to follow. I just have a quick question. I see a lot of people using Riemann Sum for utility meters but tbh I haven’t done enough researches to understand why, cause I’m using the directly added values, i.e: sensor.envoy_SN_energy_production_today, or sensor.envoy_SN_current_power_production. What is the advantages of setting up utility meters using Riemann Sum? Thanks again

Hi @xzelz,
The Utility Meter - Home Assistant is used for having multiple tariffs where your provider will charge you different rates at different times of the day.

Here is an example of what is possible with utility meter with 3 import tariffs and 1 export tariff.

image

I have written other guides in the past on how to use utility meter and will eventually get to writing a guide to do it via the GUI in this topic in the near future.

For now, here is a quote from one of my most recent previous guides

1 Like

Thanks @del13r . I’ve seen another post of yours where you used Rest sensors. Have you now abandoned that in favour of the integration?

Hi @Sddawson,

This guide above is for the most basic, bare minimum steps to get a brand new user working with energy dashboard.

I still use the rest sensors in my own setup, however these are a bit more complex for new users so I have chosen not to mention them here.

I wrote this guide as I could tell something had changed with the native enphase integration when I started seeing people trying to multiply kW by 1000 to get W and then asking for help. This indicated to me that my 3 year old guide was out of date and hence why I wrote an updated new user guide above.

OK, makes sense, thanks. When I had an Envoy, I used all your knowledge to integrate that into HA very successfully. I’m about to get a solar quote for a different house, and will probably go Envoy again (in Oz), just because there are guides like yours to follow. I’ll probably go the Rest route. Thanks for everything you do.

1 Like

Thank you for the detailed comment. I do have my setup somewhat similar to yours but I mostly created my sensors with Utility Meter UI and calculations in configuration.yaml and I was not sure if it’s the same as using Riemann sum, I think I get it now. If I was able to read your post earlier I would not do all the energy calculations by myself haha, took me quite some time to finish. I also did calculation for daily power usage, daily solar power usage etc. My electrical plan do onpeak/offpeak/midpeak. The offpeak includes weekend, and holidays as well.

Here is a quick look of my setup:

Using Riemann sum integral alone will not calculate costs.

An example of what Riemann sum integral is used for is for recording the instantanous power figures in W and converting them to energy figures in kW.

If I turn on an electrical device that steadily consumes 1030 W and leave that device on for an hour, then that device has consumed 1.03 kWh over the course of an hour.

Power in W - real world example

Riemann sum integral then incrementally records how much power the device consumed each time the power sensor updates and graphs those samples over time.

Energy in kWh - real world example generated by Riemann sum integral using only the power sensor above as the data input source.

Energy Dashboard basically samples the Lifetime Energy Value at both the start and end of each hour and records only the difference.

Energy Dashboard Samples Value Metric
Lifetime energy value at 3:00 PM 2182.52 kWh
Lifetime energy value at 2:00 PM 2181.49 kWh
Difference between start and end 1.03 kWh

How Energy Dashboard presents this same data.

I use both the built in energy dashboard and additional template sensors because energy dashboard does not support my daily service charge.

Here is a sample of how I am using utility meter readings and adding the daily service charge.
Note: this sensor is not used by Energy Dashboard and is only for my own benefit unrelated to energy dashboard.

  - sensor:
      - name: Today Energy Total Cost
        device_class: monetary
        state_class: total
        unit_of_measurement: AUD
        state: >
          {{ (states('sensor.daily_energy_Peak') | float(0) * (states('input_number.peak') | float(0) * states('input_number.discount') | float(0) ) +
              states('sensor.daily_energy_Shoulder') | float(0) * (states('input_number.shoulder') | float(0) * states('input_number.discount') | float(0) ) +
              states('sensor.daily_energy_OffPeak') | float(0) * (states('input_number.offpeak') | float(0) * states('input_number.discount') | float(0) ) -
              states('sensor.daily_energy_export_buyback') | float(0) * states('input_number.feed_in') | float(0) +
              states('input_number.dailysupply') | float(0) * states('input_number.discount') | float(0) ) | round(2) }}

Here is an example graph of 24 hours where I start the day with my $0.98 service charge, then the cost rises as I consume electricity before the sun rises, then the cost drops as I sell electricity back to the grid, then rises again once the sun sets finishing the day with a total of $2.20 charge.


r

Thank you @del13r for your amazing guide so far.
I’ve been putting together my dashboard using this guide and also parts of your old guide from 2021 - looking forward to more updates.

I’m a relatively newbie with Home assistant and YAML, but using a combination guides from here, YouTube and ChatGPT, I’ve built a functional dashboard to suit my purposes so far.

I’ve run into a couple of snags and wondering if anyone could shed some light…

  1. I’ve been trying to use your old code to generate a sensor for Corrected Solar Power/Energy, as my Envoy generates ~20-25W overnight whilst the sun is down. Using the old Code you’ve provided in your 2021 guide, it results in my solar production numbers being dramatically different compared to the numbers provided by the Envoy integration directly.

  2. My energy retailer similarly has a daily supply charge in addition to a stepped tariff (i.e. above/below 30kWh of import per day). It also has a TOU tariff for the solar feed in. Whilst my export tariff works well, I’ve been trying to create a sensor/entity to track the daily import cost as a “total” cost. Whilst the sensor seems to work and track my total daily cost (I can output to a graph and it seems to be tracking appropriately), for the life of me I can’t select it as an option in the energy dashboard to represent the “total cost” of energy import.

Any feedback on the YAML is welcome (it has been generated by ChatGPT).

sensor:
  - platform: template
    sensors:
      export_tariff:
        friendly_name: "Export Tariff"
        unit_of_measurement: "AUD/kWh"
        value_template: >-
          {% set current_hour = now().hour %}
          {% set peak_start_hour = 16 %}
          {% set peak_end_hour = 21 %}
          {% set offpeak_start_hour = 10 %}
          {% set offpeak_end_hour = 14 %}
          {% set shoulder_periods = [(21, 24), (0, 10), (14, 16)] %}
          {% set peak_tariff = 0.106 %}
          {% set offpeak_tariff = 0.039 %}
          {% set shoulder_tariff = 0.055 %}
        
          {% if current_hour < 24 %}
            {% if peak_start_hour <= current_hour < peak_end_hour %}
              {{ peak_tariff }}
            {% elif offpeak_start_hour <= current_hour < offpeak_end_hour %}
              {{ offpeak_tariff }}
            {% else %}
              {% for start_hour, end_hour in shoulder_periods %}
                {% if start_hour <= current_hour < end_hour %}
                  {{ shoulder_tariff }}
                  {% set shoulder_tariff = 0.0 %}
                  {% break %}
                {% endif %}
              {% endfor %}
            {% endif %}
          {% endif %}

      energy_cost:
        friendly_name: "Daily Energy Cost"
        unit_of_measurement: "AUD"
        value_template: >-
          {% set daily_import_kWh = states('sensor.daily_energy_import') | float %}
          {% set supply_charge = 0.93 %}
          {% set tariff_below_30_kWh = 0.198 %}
          {% set tariff_above_30_kWh = 0.242 %}

          {% if daily_import_kWh < 30 %}
            {{ (daily_import_kWh * tariff_below_30_kWh) + supply_charge }}
          {% else %}
            {{ (30 * tariff_below_30_kWh) + ((daily_import_kWh - 30) * tariff_above_30_kWh) + supply_charge }}
          {% endif %}

Whilst I’m here, our energy distributor has a max inverter size of 10kW, but an export limit of 5kW - any idea how to code for this?

Energy cannot disappear into thin air, so what happens when export exceeds the limit? does the inverter shut off, or is it only that the energy company won’t pay you for the excess?

In any way, if you limit the return sensor to a maximum, the dashboard will assume the house consumed it. So that is not an option.

Let me start off by saying this is a nice post, it will help for people who lack some of the sensors. But there are some tips, or things to consider, depending on what you have in terms of sensors:

This is only true if you have one cable coming in your home. A lot of homes in the Netherlands for instance have three phases coming in. Solar can either be on one or all three. So this rule applies per cable. If you have more you can export on one and import on another. That actually happens in my home. So if you can measure the actual values (for instance use the values from the meter) use those. It is the preferred way. If you have only one power cable coming into your home, then the calculation is valid.

This isn’t a valid reason. Rieman sum converts (k)W in (k)Wh. If you have (k)Wh that is always more accurate than the result a Riemann Sum Integral, which estimates it. having a Riemann sum integral is not a goal in itself, if you have (k)Wh then you don’t need Riemann sum.

Especially from Enphase you only get (k)W samples very infrequently, and it can vary a lot between samples. And if the samples of production and use aren’t taken at the same time, the difference between them can lead to nonsensical values. So if you have (k)Wh, and measure all of them, it is better to use those.

What the (k)W calculations do help with, is that you can import one minute, and export the other. (k)Wh sensors are not going to help you calculate that. They will cross them out against each other. That is where your calculations comes in handy. But do remember, Enphase only reports data infrequently, so Watts will be an approximation. The infrequent samples will miss things.

So For many reasons: Measure if you can, and use (k)Wh if you can.