Total Average Daily Power Consumption

Im looking to see if its possible to create a sensor that gives me the average daily power consumption but updates when a new day starts… i hope i have explained this??

So for example if I manually calculate my average daily Power consumption its 14.83, but lets say I use more today, i would then expect that number to slightly increase.

Do you have a sensor that records your daily energy consumption measured in kWh or Wh?

The average for yesterday is easy enough:

template:
  - trigger:
      - platform: time
        at: "23:59:58" # misses 2 seconds of consumption in 24 hours (which is insignificant), but ensures the calculation is done before the daily sensor is reset.
    sensor: 
      name: Average Daily Consumption Yesterday
      unit_of_measurement: "kW" # or W depending on your daily energy sensor
      device_class: power
      state_class: measurement
      state: "{{ (states('sensor.daily_energy_consumption')|float(0) / 24 )|round(2) }}"
      availability: "{{ states('sensor.daily_energy_consumption')|is_number }}"

If you want one for the current day that is a bit trickier, as you have to work out how many hours have been in the day so far, including fractions of hours.

template:
  - sensor: 
      name: Average Daily Consumption Today
      unit_of_measurement: "kW" # or W depending on your daily energy sensor
      device_class: power
      state_class: measurement
      state: >
        {% set hrs = [ now().hour + now().minute/60, 0.01]|max %} {# this template only updates every minute so we don't have to worry about seconds, we do have to worry about it being zero though #}
        {{ (states('sensor.daily_energy_consumption')|float(0) / hrs )|round(2) }}
      availability: "{{ states('sensor.daily_energy_consumption')|is_number and (now().hour + now().minute/60) > 0 }}"

Hey Tom

Thanks for this. Im not sure this is what im after, but i could be wrong.

I did a quick simple math
I have used 1943kwh over 133 days since i started recording. This = 14.60kwh daily average.
Lets say i use 50kwh today which brings my total to 1993kwh
My daily average just went up = 14.87

Thats what im trying to achieve?

kw is not a measure of energy. Did you mean KWh?

Dividing KWh by h gives you kW (the h’s cancel)

So what you actually have is 1943kWh / (133*24h) = 0.608 kW average power draw.

Yes i meant Kwh sorry

Why would I convert it like that??

All I want is the average daily Kwh consumed

Regardless of what’s on the end. if I calculate my average daily power consumption based on what my energy dashboard shows me I have consumed in total so far it’s 14.60 as the average…

How do I get that but so it updates and takes into account the day just gone by?

Use a utility meter with a daily cycle.

That just gives me daily not the average of the total.

I’ll keep searching

What is the average of the total for a day?

You need to be much clearer about what you want.

I’m pretty sure I was

I tried to explain 2 different ways…

1 Like

Hey there @cloudbr34k, did you ever figure out how to get this daily mean average of usage? I’m seeking this myself and have some thoughts, though not a full plan yet.

I have the start of an idea. I already used a built-in “Helper” (Energy Meter) to show today’s usage, and it keeps track of history. So it’s just a matter of extracting those days and doing the math. The Statistics - Home Assistant integration has some average functions that would work easily enough—it’s just a matter of fetching the daily values to feed in. I have no clue on that front, so far! I’m sure I’ll get there, but if you have had luck in the past 7 months, it’d save me a lot of time!

PS: I found your request pretty easy to understand. It was described okay initially, but became very easy to understand after you provided more detail. Maybe the moderator just has a slight language barrier? Though, you also provided math, so IDK! Anyway, just wanted to give you credit there.)

Thanks!

1 Like

Did you solve it? I’m looking for the same thing right now.

So here are my sensor templates

# Template sensor to calculate the date of inverter installation
- platform: template
  sensors:
    fronius_installation_date:
      friendly_name: "fronius installation date"
      value_template: "{{ (as_timestamp(now()) - as_timestamp('2020-08-15')) / 86400 | int }}"
# Template sensor to calculate the date of smart meter installation
- platform: template
  sensors:
    fronius_smart_meter_installation_date:
      friendly_name: "fronius smart meter installation date"
      value_template: "{{ (as_timestamp(now()) - as_timestamp('2022-03-22')) / 86400 | int }}"

# Template sensor to calculate the ongoing daily average solar produced
- platform: template
  sensors:
    fronius_ongoing_daily_average_solar_produced:
      friendly_name: "Fronius Ongoing Average Daily Solar Produced"
      unit_of_measurement: "kWh"
      value_template: >
        {% if states('sensor.fronius_installation_date') | int > 0 %}
          {{ (states('sensor.symo_10_0_3_m_1_energy_total') | float / states('sensor.fronius_installation_date') | int) | round(0) }}
        {% else %}
          0
        {% endif %}

# Template sensor to calculate the ongoing daily average energy consumed
- platform: template
  sensors:
    fronius_ongoing_daily_average_energy_consumed:
      friendly_name: "Fronius Ongoing Average Daily Energy Consumed"
      unit_of_measurement: "kWh"
      value_template: >
        {% if states('sensor.fronius_smart_meter_installation_date') | int > 0 %}
          {{ (states('sensor.smart_meter_energy_real_consumed') | float / states('sensor.fronius_smart_meter_installation_date') | int) | round(0) }}
        {% else %}
          0
        {% endif %}
# Template sensor to calculate the ongoing daily average energy produced
- platform: template
  sensors:
    fronius_ongoing_daily_average_energy_produced:
      friendly_name: "Fronius Ongoing Average Daily Energy Produced"
      unit_of_measurement: "kWh"
      value_template: >
        {% if states('sensor.fronius_smart_meter_installation_date') | int > 0 %}
          {{ (states('sensor.smart_meter_energy_real_produced') | float / states('sensor.fronius_smart_meter_installation_date') | int) | round(0) }}
        {% else %}
          0
        {% endif %}
1 Like

Here’s how I calculate the amount of energy used to heat water over a rolling window of 15 days:

sensor:
  - platform: statistics
    unique_id: hot_water_energy_total_over_15d
    entity_id: sensor.hot_water_energy_meter # <- value only ever increases (e.g. utility meter with no cycle)
    name: "Hot water energy over the last 15 days"
    state_characteristic: change
    max_age:
      days: 15

The same approach applies to a rainfall sensor, for example. The important thing is that the state of the source sensor (entity_id) is monotonically increasing.

To get the average only requires one more sensor to divide by the size of the rolling window, 15 days in my example.

template:
  - sensor:
      - unique_id: hot_water_energy_average_over_15d
        device_class: energy
        unit_of_measurement: 'kWh'
        state: |
          {% set total_kwh = states('sensor.hot_water_energy_total_over_15d') | float %}
          {% set days = 15 * max(state_attr('sensor.hot_water_energy_total_over_15d', 'age_coverage_ratio'), 0.0001) %}
          {{ (total_kwh / days) | round(2) }}
1 Like