Help on getting Energy usage in a simple way, reducing DB size

I have a problem, everything is working as expected, however I does not seem like optimal method/setup.

What I would like is a simple sensor showing energy usage pr day. I already achive this by having a template sensor like this:

- trigger:
  - platform: time
    at: 
      - "00:05:00"
  - platform: homeassistant
    event: start
  sensor:
  - name: "Utility El Daily total"
    state: >
      {{ state_attr('sensor.utility_el_maler_daily', 'last_period') | float(0) }}

Based on this sensor I use statestics to create a average number over the last 7 days, and another template to generate a “yearly cost of power, based on last 7 days” and a small graph showing the useage pr day.

I have this information on my main dashboard page, hence the wife will notice. I know I can get the same information form the energy pages, however then it will not be on the main page.

Now the problem. Of the total space in my DB, a total of 29% is used by the utility sensor created to make the above. Mainly because it triggeres a lot, like every 5 seconds.

I use this configuration.

utility_el_maler_daily:
  source: sensor.develco_zhemi101_f21a021b_smartenergy_metering_summation_delivered
  cycle: daily

I woulkd like to reduce this space, used for the utility sensor. I only use it to get a total daily number:-) Seems like a lot of information to get this simple information.

I can see “Energy dashboard” have the “knowledge” about daily usage, as It make nice graphs with this information if you choose monthly view. Any way to get this information out?

Im open for good ideas?

add:

    device_class: energy
    state_class: measurement

And use statistics card

then reduce days in purge database

I am just have a test sensor in Watts

Hi Nikito, not entirely what I was looking for. Can still not use it in templates.

Hi All, Have decided to go a different route, as I can not find a simple solution. Here is my working new setup to get measures pr minute. It will also work on a daily basis, however I can first see the result in 2 days:-)

First create a template (in template section), once pr minute (will work with whatever timing)

- trigger:
  - platform: time_pattern
    minutes: /1   ## One measurement pr minute
  sensor:
  - name: "Utility El usage Minut increasingtotal temp-number"
    state: >
      {{ states('sensor.develco_zhemi101_f21a021b_smartenergy_metering_summation_delivered') }}

To calculate the change between the readings, use statestics template (goes under sensor)

- platform: statistics
  entity_id: sensor.utility_el_usage_minut_increasingtotal_temp_number
  name: Utility El usage pr minut History temp-number
  state_characteristic: change
  precision: 3
  sampling_size: 2  
  max_age:
    days: 2

In the end, create a new sensor with the value calculations in other templates.

    utility_el_minut_usage:
      friendly_name: "El forbrug pr minut"
      unit_of_measurement: "kW"
      value_template: "{{ states('sensor.utility_el_usage_pr_minut_history_temp_number') | float(0) }}"

Now I just need to delete the old utility measurement.

1 Like

Nice! Glad you found a workaround. I just put my daily and monthly statistics in a flat text file and exclude them all from recorder.

It’s frustrating that HA trows everything into one database, and that there is no way to exclude the energy monitoring stuff if you’re not using it. A while ago I put in a feature request to allow individual entities to be set for different purge durations, which I think would be a step in the right direction. (Feel free to up-vote if you agree!) Adding all the energy monitoring only made the load on the DB worse.

Have already, some time ago, woted for tha:-).

1 Like