I’ve got a SunPower system integrated into Home Assistant, and it’s correctly reporting both the power produced by the solar panels and the power consumed by the home. It is not reporting the power exported to the grid, though, for some reason not yet understood that value is always zero even though the system has exported power every day for the past two weeks.
At the moment I have the production sensor included in the energy dashboard twice (once as production and once as export) just to get something useful:
As you can see, this means the ‘Self-consumed solar energy’ sensor is always zero.
I’d like to compute the ‘kWh to Grid’ value from the existing sensors, and I attempted to create a template sensor to do that, but I don’t think this will work as the underlying sensors are total_increasing and doing math on their values seems odd.
- sensor:
- name: Energy to Grid
unique_id: energy_to_grid
icon: mdi:transmission-tower-export
state_class: total_increasing
device_class: energy
unit_of_measurement: kWh
state: '{{ [0, states("sensor.lifetime_power")|float - states("sensor.lifetime_power_2")|float] | max }}'
I haven’t actually tried this template sensor yet because I don’t want garbage values to go into my history, so I figured I’d ask for guidance here first to see if I’m on the right track.
I do also have ‘instantaneous’ sensors from the integration which I could use to create a total_increasing sensor if that’s more useful.
I ended up solving this problem for my installation, although I’m not thrilled about the result because it means that I’ll lose data if HA is restarted or stops running (since it is doing the instantaneous-to-integrated summations itself).
I’ve got two template sensors that look like this:
- sensor:
- name: Power to Grid 3
unique_id: power_to_grid_3
icon: mdi:transmission-tower-export
state_class: measurement
device_class: power
unit_of_measurement: kW
state: '{{ [0, states("sensor.production_meter_power")|float - states("sensor.consumption_meter_power")|float] | max }}'
- name: Power from Grid 3
unique_id: power_from_grid_3
icon: mdi:transmission-tower-import
state_class: measurement
device_class: power
unit_of_measurement: kW
state: '{{ [0, states("sensor.consumption_meter_power")|float - states("sensor.production_meter_power")|float] | max }}'
These compute the instantaneous power flowing to/from the grid, using the underlying sensors from the PV solar supervisor device (part of a SunPower installation).
I also have two integration sensors that look like this:
- platform: integration
name: Energy to Grid 3
unique_id: energy_to_grid_3
source: sensor.power_to_grid_3
method: left
round: 2
unit_time: h
- platform: integration
name: Energy from Grid 3
unique_id: energy_from_grid_3
source: sensor.power_from_grid_3
method: left
round: 2
unit_time: h
These are selected as the “Return to Grid” and “Grid Consumption” sensors (respectively) in the Energy Dashboard configuration, along with the solar production energy sensor. The result is that the Energy Dashboard produces a fairly accurate representation of the power flows in our system.
I’m still not thrilled about the potential for data loss here, so I’m going to think about putting something on an Arduino to just do this one small part of the data gathering/transformation and then feed that into HA. Then at least I can do maintenance on the HA system without interruption of data input.