How to get sum from (long term) statistic sensor

I have a sensor that takes the current energy price and multiplies it with a sensor that tracks how much energy i have avoided to import because of a solar system.
The Sensor created looks like this:

    - name: "Solar Energy Cost Saved Today"
      unique_id: solar_energy_cost_saved
      icon: mdi:cash
      unit_of_measurement: '€'
      device_class: monetary
      state_class: total_increasing
      state: >
        {{ (states('input_number.strompreis_import')|float(0) * states('sensor.energy_usage_avoided_daily')|float(0)) | round(2) }}

In the Database it creates statistic entry looking like this:

When i create a statistic card in lovelace i can see the sum graph.
How can i get the sum value for this sensor in a template or a normal row entity ?

You can get anything from a database with the sql sensor.

Mhh, okay it looks like it would be possible even if it feels very hacky to me. There should be a more “official” way of getting the sum of a statistic sensor ?

Thanks for replying!

1 Like

Looking again, if the state is total_increasing, you shouldn’t need to total it. The state is the total.

Unfortunately that’s not the case:

  • The sensor’s value may reset to 0, and its value can only increase: state class total_increasing. Examples: energy consumption aligned with a billing cycle, e.g. monthly, an energy meter resetting to 0 every time it’s disconnected

I stand corrected.