KoljaWindeler / energy_calc

A custom integration for Homeassistant that provides an overview about solar power usage
4 stars 2 forks source link

Stats Resetting at 4pm local time #2

Closed jmunowitch closed 1 year ago

jmunowitch commented 1 year ago

I stubbled upon the repo as the solution to my HA energy problems! I am excited because it solves a significant challenge to using the HA energy dashboard

Once setting this up, the energy dashboard worked great! Until I noticed the data seems to be resetting at 4pm local time (America/Los_Angeles):

image

I am a bit baffled why this is happening. My uneducated guess is timezones... but I have no real evidence of this.

template:
  - sensor:
      - name: "Grid To Home"
        state: "{{state_attr('sensor.energy_calc', 'Grid_to_home_[kWh]')}}"
        device_class: energy
        state_class: total 
        unit_of_measurement: "kWh"
  - sensor:
      - name: "Solar To Grid"
        state: "{{state_attr('sensor.energy_calc', 'Solar_to_grid_[kWh]')}}"
        device_class: energy
        state_class: total_increasing 
        unit_of_measurement: "kWh"

in config_entries:

      {
        "entry_id": "55773e0064dd5541edd8ab10811111bc",
        "version": 1,
        "domain": "energy_calc",
        "title": "energy_calc",
        "data": {
          "name": "Home Power",
          "icon": "mdi:weather-sunny",
          "gen_id": "sensor.solaredge_current_power",
          "net_id": "sensor.home_123_1min"
        },

Solar is coming in through the solaredge integration and the power is coming from the ha-emporia-vue integration.

Any help in figuring out why the stats are resetting at 4pm local time would be great!

jmunowitch commented 1 year ago

After some more futzing around, I was able to fix this!

Both of the sensor templates needed to have state_class set to total_increasing:

      - name: "Grid To Home"
        unique_id: 'Grid To Home'
        state: "{{state_attr('sensor.energy_calc', 'Grid_to_home_[kWh]')}}"
        device_class: energy
        state_class: total_increasing
        unit_of_measurement: "kWh"
  - sensor:
      - name: "Solar To Grid"
        unique_id: 'Solar To Grid'
        state: "{{state_attr('sensor.energy_calc', 'Solar_to_grid_[kWh]')}}"
        device_class: energy
        state_class: total_increasing
        unit_of_measurement: "kWh"
KoljaWindeler commented 1 year ago

Hi, im currently on vacation but will have a look once I'm back. But timezones will be the issue for sure. I live in Germany and your 4pm is my midnight..

KoljaWindeler commented 1 year ago

I guess this needs to be replaced with "local timezone" https://github.com/KoljaWindeler/energy_calc/blob/30dc7567f00ca67028eed41da09aaf761f739d4b/custom_components/energy_calc/sensor.py#L119