Mean sensor of the Last Value of the day


can someone please point me in the right direction. I am trying to create a “Mean Sensor” which gives me the mean of the Last value of (multiple) days.

I have a water meter installed which counts the water use and a utility meter to cut this into daily chunks. So far so good.

What i want is the mean of the last values.
So if on day 1 the last reading was 200 Liters and
on day 2 it was 100 Liters i want it to say 150 Liters. (ignoring all the values throughout the day)

The “normal” mean changes with every reading etc. . I looked into “statistics” and think there might be something there, but can’t seem to find out.

Any help is appreciated. Thanks!

1 Like

Create a triggered template sensor that records each day’s maximum.

  - trigger:
      - platform: time
        at: "23:59:59"
      - name: "Daily water maximum"
        state: '{{ states('sensor.daily_water_use') }}"

Then feed that to the statistics sensor to get your mean for what ever period you want, e.g. one week:

  - platform: statistics
    name: "Weekly Mean Daily Water Use"
    entity_id: sensor.daily_water_maximum
    state_characteristic: mean
      hours: 168
1 Like

Is there a way to get the trigger to work on the last day of each month instead of end of day?

Assuming you mean at the end of the last day of the month, and with the time sensor installed, this trigger should do it:

  - trigger:
      - platform: template
        value_template: >-
          {{ now().date() ==
             and states('sensor.time') == '23:59' }}

Excellent. Many thanks.

Thank you very much, Tom!
Will try this out today :slight_smile:

1 Like