I have 3 power sensors.
template:
- 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_SN_current_power_production') | int(0) %}
{% if value <= 5 -%}
0
{% elif is_state('sun.sun','below_horizon') %}
0
{%- else -%}
{{ value }}
{%- endif %}
- sensor:
name: Grid Import Power
state_class: measurement
icon: mdi:transmission-tower
unit_of_measurement: W
device_class: power
state: >
{{ [0, states('sensor.envoy_SN_current_power_consumption') | int(0) - states('sensor.solar_power_corrected') | 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.solar_power_corrected') | int(0) - states('sensor.envoy_SN_current_power_consumption') | int(0) ] | max }}
then I have 3 matching integration sensors that record how much energy.
sensor:
- platform: integration
name: Solar Energy Corrected
source: sensor.solar_power_corrected
method: left
unit_prefix: k
unit_time: h
- platform: integration
name: Grid Import Energy
source: sensor.grid_import_power
method: left
unit_prefix: k
unit_time: h
- platform: integration
name: Grid Export Energy
source: sensor.grid_export_power
method: left
unit_prefix: k
unit_time: h