Calculate fuel consumption from run time, update every 15 minutes


I have multiple history stats that track the run time of various fuel consumption engines( Heater, Generator, main engine). These history stats output run time every 24 hours then reset.

I also just made an automation below which I am running once a day just before the history stats are reset and it takes the run time per engine, multiplies it by the fuel consumption rate and gets a “estimate” of fuel consumed… this is then subtracted from a input number which is the total remaining fuel reducing it by the amount consumed in the past 24 hours.

I would like to get this to be updating every 15 minutes or hourly at most. Suggestions? I could create more history stats set them to reset every hour and repeat this process, but is there an easier way to just call directly from the automation?

Thanks in advance.

Automation code below:


 alias: Adjust Diesel Fuel Consumption Hourly
description: ""
  - platform: time
    at: "23:45:00"
  - condition: numeric_state
    entity_id: sensor.diesel_heat_active_today
    above: 0
  - condition: numeric_state
    entity_id: sensor.generator_active_today
    above: 0
  - condition: numeric_state
    entity_id: sensor.main_engine_active_today
    above: 0
  - service: input_number.set_value
      entity_id: input_number.eudora_diesel_remaining_estimate
      value: >-
        {{ (states("input_number.eudora_diesel_remaining_estimate") | float) - (
        (states("sensor.diesel_heat_active_today") | float * 0.45) +
        (states("sensor.generator_active_today") | float * 0.55) +
        (states("sensor.main_engine_active_today") | float * 1.7)  ) }}
mode: single

To be specific,

How can I get the amount of time X thing ran in the past hour, then I would just setup the automation to run every hour or every 15 minutes?

For code then I would simply replace “(states(“sensor.diesel_heat_active_today”)” with the new code.

Use reimann sum and utility meters. See this post.