Enphase Solar - Net Energy Sensor

Hi HA Community,

I’m stuck on trying to understand how to create a sensor that performs a calculation.
I have Enphase Solar system. The native Enphase Envoy integration is active and creates two sensors:


both report in Watts.


What I would like to achieve is to have a NET energy sensor. So that I can identify if I am sending back to grid (production is higher than consumption) or I am consuming from the grid (consumption is higher than production).

I presume this would not be a binary_sensor as it would need to report more than on/off.

Has anyone accomplished this and could help me understand how to achieve.

Thank you community.

You need to create template sensors. I have the below created, and I use them for the ‘Tesla style power wheel card’ among other things. The ones you are looking for are the second and third one.

  - platform: template
        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'
        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'
        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'
        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'
        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'
        value_template: '{{ ((states.sensor.envoy_today_s_energy_consumption.state | float * -1)) | round(1) }}'
        friendly_name: 'Today Energy Consumption'
        unit_of_measurement: 'Wh'
        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 %}

1 Like

And here is my config for the Tesla card if you wanted it:

      - type: 'custom:tesla-style-solar-power-card'
        style: |
          ha-card {
             --warning-color: var(--light-primary-color);
             --info-color: var(--primary-color);
             background-color: transparent;
             background: transparent;
        house_consumption_entity: sensor.envoy_current_energy_consumption
        grid_consumption_entity: sensor.envoy_current_importing
        grid_feed_in_entity: sensor.envoy_current_exporting
        solar_consumption_entity: sensor.envoy_house_consumption 
        solar_yield_entity: sensor.envoy_current_energy_production

Card found here: Custom Solar Power Card the Tesla Style (almost)

Wow. this is awesome. Kudos.
Thank you for sharing.

Ill give this a crack this afternoon/evening and let you know.

If you want a basic Net Power sensor, this is what I did in configuration.yaml

  - sensor:
      - name: Net Power
        state_class: measurement
        unit_of_measurement: W
        device_class: power
        icon: mdi:transmission-tower
        state: >
          {% set production = states('sensor.envoy_SERIALNUMBER_current_power_production') | int %}
          {% set consumption = states('sensor.envoy_SERIALNUMBER_current_power_consumption') | int %}
          {{ (production - consumption) }}

Which allowed me to do this

Here is how i setup the card

  - path: default_view
    title: Energy
    type: panel
      - type: vertical-stack
          - type: gauge
            min: 0
            max: 7500
            entity: sensor.envoy_SERIALNUMBER_current_energy_production
          - type: gauge
            max: 7500
            min: 0
            entity: sensor.net_power
          - type: gauge
            entity: sensor.envoy_SERIALNUMBER_current_energy_consumption
            min: 0
            max: 7500

For any newbies that want their Enphase Envoy to work with the new Energy feature in Home Assistant 2021.8 please see Enhpase Envoy on 2021.8 with new Energy feature