Home Assistant - Sense Integration Bug

Indeed ! It looks like the Home Assistant Sense integration delivers the data for the previous hour interval about 8 minutes into the next hour. Guessing that’s the cause.

I too am having the same issue. The reset happens at 12-1am and shows a negative value. I’m not sure if this has been happening since the “allow negative values in energy meter” was an added feature. Would be good to see if it is possible to toggle that feature.

Go to the yearly for a day.

Then go back to daily.

Still wrong, but at least the negative value at 12am-1am disappears.

Thanks for noticing that. Fixed here as well.

How did you fix :man_shrugging:t3:

There’s an open issue about it:

If someone knows a solution we could add the fix to the HA component

1 Like

Change the daily sensors to annual sensors. As was stated there is an open and unresolved issue being tracked with HA and I assume it should be fixed soon.

1 Like
2 Likes
2 Likes

Just FYI the fix for this is merged in and will be in the next release

4 Likes

Except it’s still not working properly. Nothing has changed in 5 months.

Not true. It’s working better now, but the way Sense provides data and the way HA stores data aren’t really compatible. Sense reports data at the end of an hour so it never really gets the last hour of data as it resets to the next day

1 Like

Here is how I solved this issue with HA a while ago. It may well be that with the latest it can also be done in a more direct manner. I have not yet gone there to test. I have also kept track of what sense reports at the end of the day (as noted always a few minutes after). Generally the difference between what I am reporting and what sense reports in its app are very close. My solar production is within 0.2 kWh with rare exceptions of about 0.4 and my difference between to_grid and from_grid is generally within 0.4-0.6 kWh. If, for some reason, your HA instance is down for a while there will be bigger inaccuracies.

For the configuration of the energy panel I use three sensors:

  • sensor.energy_from_grid
  • sensor.energy_to_grid
  • sensor.solar_energy_produced

These sensors are defined by me as Riemann integration sensors. They take wattage derived from sense data (which is almost realtime: sensor.energy_usage) as template sensors, and integrate it over time into kWh. The template sensors are:
net_power_from_grid:

# Sensor that returns instantaneous power (W) taken from grid (>= 0), or put to grid (< 0)
sensor:
  name: Net Power From Grid
  unique_id: net_power_from_grid
  device_class: power
  unit_of_measurement: W
    # Test both sensors exist
  availability: >-
    {{ true if states.sensor.energy_production and states.sensor.energy_usage }}
  state: >-
    {{ states('sensor.energy_usage') | float(0) - states('sensor.energy_production') | float(0) }}

power_from_grid.yaml:

# Sensor that returns instantaneous power (W) taken from grid (>= 0)
sensor:
  name: Power From Grid
  unique_id: power_from_grid
  device_class: power
  unit_of_measurement: W
  availability: >-
    {{ true if states.sensor.net_power_from_grid }}
  state: >-
    {{ max(states('sensor.net_power_from_grid') | float(0), 0) }}

power_to_grid.yaml:

# Sensor that returns instantaneous power (W) put to grid (>= 0), or 0 if not putting any
sensor:
  name: Power To Grid
  unique_id: power_to_grid
  device_class: power
  unit_of_measurement: W
  availability: >-
    {{ true if states.sensor.net_power_from_grid }}
  state: >-
    {{ max(-(states('sensor.net_power_from_grid') | float(0)), 0) }}

With those three in hand you can define the integration sensors:

energy_from_grid.yaml:

platform: integration
name: energy_from_grid
source: sensor.power_from_grid
method: left
round: 5
unit_prefix: k
unit_time: h

energy_to_grid.yaml:

platform: integration
name: energy_to_grid
source: sensor.power_to_grid
method: left
round: 5
unit_prefix: k
unit_time: h

and
solar_energy_produced.yaml.yaml:

platform: integration
name: solar_energy_produced
source: sensor.energy_production
round: 8
unit_prefix: k
unit_time: h
2 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.