Enphase Envoy with Energy Dashboard

The Enphase Envoy updates every 60 seconds.
I also have a pulse counter called PowerPal but once solar starts producing, then I dont see anything in the day so I prefer to get data every 60 seconds 24 hours a day from Enphase Envoy.

Ok great thanks - mine updates every second, so I can see real-time changes. I’ve trained my family to make decisions on when to turn on kettle/oven/dishwasher/dryer etc using the real-time graphs in Home Assistant. They are Green when I’m producing more than consuming to make it kid-proof.

2 Likes

Ive combined our code to get the best ot both worlds.

  - sensor:
        name: Solar Power Corrected
        state_class: measurement
        icon: mdi:solar-panel
        unit_of_measurement: W
        device_class: power
        state: >
            {% set value = states('sensor.envoy_SERIALNUMBER_current_power_production') | int %}
            {% if value  <= 5 %}
              0
            {% elif is_state("sun.sun","below_horizon") %} 
              0
            {%- else -%}
              {{ value }}
            {%- endif %}

Hoping someone can help, I have created new sensors for energy but they aren’t showing up as selectable options in the dashboard. Any ideas why this might be the case?

I would say the only difference between my energy sensors and yours is that mine have

device_class: energy

whereas yours dont seem to have that attribute yet.

Here are my sensors provided by the Enphase Integration

Here are the POWER sensors I created manually that use the information from the envoy sensors above.


Here are the ENERGY sensors I created manually using the Integration - Riemann sum integral - Home Assistant platform that use the information from the power sensors above


1 Like

Thanks for the offer to help! I am wondering if it is due to the way I have set up my template entities?

Below are my entities:


And below is my code for all my templates, I have them different to yours though, and it won’t allow me to select device class etc…

  - platform: template
    sensors:
      envoy_house_consumption:
        friendly_name: "Current House Consumption"
        value_template: "{{ [0, (states('sensor.envoy_current_energy_production') | int - states('sensor.envoy_current_exporting') | int)] | max }}"
        unit_of_measurement: 'W'
        icon_template: 'mdi:flash'
      envoy_current_exporting:
        friendly_name: "Current Energy Exporting"
        value_template: "{{ [0, (states('sensor.envoy_current_energy_production') | int - states('sensor.envoy_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.envoy_current_energy_consumption') | int - states('sensor.envoy_current_energy_production') | int)] | max }}"
        unit_of_measurement: 'W'
        icon_template: 'mdi:flash'
      envoy_today_s_energy_exporting:
        friendly_name: "Today Energy Exporting"
        value_template: "{{ [0, (states('sensor.envoy_today_s_energy_production') | int - states('sensor.envoy_today_s_energy_consumption') | int)] | max }}"
        unit_of_measurement: 'Wh'
        icon_template: 'mdi:flash'
      envoy_today_s_energy_importing:
        friendly_name: "Today Energy Importing"
        value_template: "{{ [0, (states('sensor.envoy_today_s_energy_consumption') | int - states('sensor.envoy_today_s_energy_production') | int)] | max }}"
        unit_of_measurement: 'Wh'
        icon_template: 'mdi:flash'
      envoy_today_s_energy_utilised:
        friendly_name: "Today Energy Utilised"
        value_template: "{{ [0, (states('sensor.envoy_today_s_energy_production') | int - states('sensor.envoy_today_s_energy_exporting') | int)] | max }}"
        unit_of_measurement: 'Wh'
        icon_template: 'mdi:flash'
      envoy_today_s_consumption_negative:
        value_template: '{{ ((states.sensor.envoy_today_s_energy_consumption.state | float * -1)) | round(1) }}'
        friendly_name: 'Today Energy Consumption'
        unit_of_measurement: 'Wh'
      power_kw:
        friendly_name: "Power Available"
        unit_of_measurement: 'kW'
        value_template: >
          {% if states('sensor.envoy_current_exporting')|float > states('sensor.envoy_current_importing')|float %}
            {{ (states('sensor.envoy_current_exporting') | int / 1000) | round(2)}}
          {% else %}
            {{ (states('sensor.envoy_current_importing') | int / -1000) | round(2)}}
          {% endif %}
      solar_power_corrected:
        friendly_name: "Solar Power Corrected"
        unit_of_measurement: W
        value_template: >
          {% set value = states('sensor.envoy_current_energy_production') | int %}
          {% if value  <= 4 and is_state("sun.sun", "below_horizon") -%} 
            0
          {%- else -%}
            {{ value }}
          {%- endif %}

  - platform: integration
    name: Grid Import Energy
    source: sensor.envoy_current_importing
    unit_prefix: k
    unit_time: h
    method: left
    
  - platform: integration
    name: Grid Export Energy
    source: sensor.envoy_current_exporting
    unit_prefix: k
    unit_time: h
    method: left

  - platform: integration
    name: Solar Energy Corrected
    source: sensor.solar_power_corrected
    unit_prefix: k
    unit_time: h
    method: left

Ok, these 2 are the standard Enphase supplied sensors which have the same attributes as mine except mine include the serial number and yours are named ENERGY whereas mine are named POWER. No big deal.

Next I check your import/export POWER sensors.

  - platform: template
    sensors:
     envoy_current_exporting:
        friendly_name: "Current Energy Exporting"
        value_template: "{{ [0, (states('sensor.envoy_current_energy_production') | int - states('sensor.envoy_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.envoy_current_energy_consumption') | int - states('sensor.envoy_current_energy_production') | int)] | max }}"
        unit_of_measurement: 'W'
        icon_template: 'mdi:flash'

The differences here are that you havent included

        state_class: measurement
        device_class: power

for both of these POWER sensors. You will probably need to add both lines to each of the 2 POWER sensors above.

Next I check your ENERGY sensors

  - platform: integration
    name: Grid Import Energy
    source: sensor.envoy_current_importing
    unit_prefix: k
    unit_time: h
    method: left
    
  - platform: integration
    name: Grid Export Energy
    source: sensor.envoy_current_exporting
    unit_prefix: k
    unit_time: h
    method: left

these look fine

1 Like

Thanks for this! I have recreated duplicate sensors using your template method, which seems to have fixed the issue :slight_smile: I can now select my created sensors, so looks like they definitely needed to have a device_class and state_class set for the Energy Dashboard to find them.

Thanks again, legend!

1 Like

No worries.

Its good practice to always use the correct device class when manually creating a sensor in configuration.yaml

Here is a list of device classes from Sensor Entity | Home Assistant Developer Docs

Type Unit Description
battery % % of battery that is left.
carbon_dioxide ppm parts per million of carbon dioxide concentration
carbon_monoxide ppm parts per million of carbon monoxide concentration
humidity % % of humidity in the air.
illuminance lx/lm Light level.
signal_strength dB/dBm Signal strength.
temperature °C/°F Temperature.
timestamp ISO8601 Timestamp.
power W,kW Power.
pressure hPa,mbar Pressure.
current A Current.
energy Wh,kWh Energy.
power_factor % Power Factor.
voltage V Voltage.
monetary ISO 4217 Monetary value with a currency

here is more info about state_class from Sensor Entity | Home Assistant Developer Docs

measurement - The state represents a measurement in present time

1 Like

Thanks @del13r for this post. I followed your recommendations and setup those sensors, etc. They appear to show reasonable values when viewed separately. However, for some reason, the energy dashboard doesn’t display any of the values. The graphs have stayed blank through the day as well.

Any ideas?

Sensor values

Energy Dashboard

1 Like

Did you copy and paste every line of the config I posted in the first post?

I’ve helped a few people today who left some lines out or renamed sensors

Go to developer tools / states
sensor.grid_export_energy
Cross check the attributes
Here are mine

state_class: measurement
last_reset: '2021-08-08T07:32:53.851525+00:00'
source: sensor.grid_export_power
unit_of_measurement: kWh
friendly_name: Grid Export Energy
icon: mdi:chart-histogram
device_class: energy

If you are missing any of these attributes, then I’m confident that the config I posted has not been fully copied to yours or you might need to reboot home assistant to activate any recent changes to sensors you might have made

I think I have them all. Your last_reset is a string (quoted) while mine seems to be an actual date-time.

state_class: measurement
last_reset: 2021-08-10T22:24:38.833748+00:00
source: sensor.grid_export_power
unit_of_measurement: kWh
friendly_name: Grid Export Energy
icon: mdi:chart-histogram
device_class: energy

That looks good to me. Perhaps try re assigning the energy sensors in configuration / energy and then a reboot

Hi there!

first things first: thanks to del13r & dgaust for all the work!

I do have a question though. I’m having a difficult time to understand how you convert power to energy. Imagine a value for the ‘power’ sensor of 50 W for a certain minute (i understand there is a value for each minute). Assuming this is the average power output for that minute (not sure about that), you need to divide the value by 60 to go from Wmin to Wh and again times 100 to go to kWh.
That calculation is not done in de definition of your non-template ‘energy’ sensor.

Or is there something that I’m missing?

Thanks for all the efforts & feedback!

In addition to my previous remark, i’m also struggling with the produced energy. the none-template sensory ‘energy production’ is not recognised as device_class: energy, where as the other two none-template sensors that you advised (import energy & export energy) are recognised as such. Without that recognition, the sensor does not show up in the configuration pane of the energy module. there seems to be no way to set this manually for a none-template sensor.

Any ideas on how I can make HA recognise ‘energy production’ as a device_class:energy?

My configuration.yaml entry:

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
  - platform: integration
    name: Solar Production Energy
    source: sensor.my_solar_energy_current_power_production
    unit_prefix: k
    unit_time: h
    
template: 
- sensor:
        name: Grid Import Power
        state_class: measurement
        icon: mdi:transmission-tower
        unit_of_measurement: W
        device_class: power
        state: >
            {{ [0, states('sensor.my_solar_energy_current_power_consumption') | int - states('sensor.my_solar_energy_current_power_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.my_solar_energy_current_power_production') | int - states('sensor.my_solar_energy_current_power_consumption') | int ] | max }}

Any help is much appreciated!

Hi, you don’t need to do any calculations yourself. the power to energy conversion is handled by this non-template ‘integration’ sensor which does everything for you.


# Example configuration.yaml entry
sensor:
  - platform: integration
    source: sensor.current_power

More information here

A lot of the issues I have helped people with are due to their config not matching my example config.

Looking at the order here, it seems you are creating energy sensors higher up on the config before the power sensors are created yet.

There is a good reason why I have created the power sensors first because the energy sensors need the data from the power sensors.

I assume that home assistant processes the configuration.yaml in a top to bottom fashion.
It might get to


source: sensor.grid_import_power

`and say hey, where is this sensor? It doesn’t exist yet.

Also the indents on your template sensors don’t seem correct. Try further indenting

template:
  - sensor

As the energy sensors require figures above 0 from the power sensors to finish formatting correctly, I’d suggest putting the energy sensors below the power sensors. Alternatively, just copy and paste my code verbatim and it will work properly.

The integration ‘integration’ is what detects a properly formatted power figure and then converts that properly formatted power figure to energy.
This is why both sensors won’t format correctly immediately because both power figures will not be above 0 at the same time. This is why if it’s nighttime you have to wait till the sun is up to see the export energy sensor format corrrectly.

This explains how it works

ahhh guys,

this thread threw me off big time … untill it hit me.
I was completly puzzled for a couple of days why o why you would need to create those kwh import/export sensors. I couldnt see it.

There are different envoy setups. This method described here is for enphase envoy the metered version. :rofl:
I only have the panels and a non-metered envoy version. This reports only stuff about the panels, like production per inverter(W), total lifetime production(kWh), etc. The solar production measurement from this, can be directly fed into the new Energy management feature.

For the import/export of energy I use a cheap p1 cable to read my smart meter. DOH!!!

So, my learning moment here is that if you have an option to plug in your smartmeter, you dont need to create the sensors like to convert to kwh for import/export. These are already present by default. :slight_smile:

Just sharing my stupidity. Hopefully someone can feels less stupid because of this.

3 Likes

Sorry about that. It’s hard to cater for everyone and consider every combination. I only got my enphase envoy this year and wasn’t even asked if I didn’t want consumption/production monitoring.

Here is what I see when I go to envoy.local

Also, in my country, I don’t think we can even use p1 cables with our smart meters. I think it’s a European thing maybe

@del13r What kind of Envoy do you have?