How to reset a collecting sensor helper daily at a fixed time

Hi,

I have two issues with tbe collecting sensor in Home Assistant Core 2022.5.4

  1. created a collecting sensor helper via the UI. But once created I can not see or edit all parameters set during creation anymore. I didn’t figure out what the offset line in the UI means, when setin repeat to daily the offset still has the unit days.

Via the developers menue entity tab I get a Yaml overview that looks like this:

state_class: total_increasing
source: sensor.regenmesser_rainabs
status: collecting
last_period: '10.50'
meter_period: daily
cron pattern: 31 7 * * *
last_reset: '2022-05-20T22:00:00.022962+00:00'
unit_of_measurement: mm
icon: mdi:counter
friendly_name: Regenmenge 24h seit 7:31
  1. I can’t figure out how to reset the counter daily at 7:31:00 am. The cron pattern listed above does not work. Having a look at the source the cron pattern does not support seconds.

I tried:
31 7 * * *
31 7/24 * * *
00 31 7/24 ? * * *

I noticed that when a count event occurs the cron pattern gets overwritten to 0 0 * * *

Any hints how to reset the collecting sensor helper daily with an offset to midnight?

If this doesn’t work:

0 30 07 ? * *

Then you can use an automation to reset it:

trigger:
  - platform: time
    at: '07:30:00'
action:
  - service: utility_meter.reset
    entity_id: utility_meter.your_utility_meter_here

You’ll have to use a cycle longer than a day as that will also reset at midnight.

Hi Tom,
thanks for the very fast response. I did some tests with an energy meter wihich is triggering with high frequency.

Every time a count event occurs the cron pattern gets over written by a value determined from the meter_period parameter. For exampe quarterly_hour results in 0/15 * * * * or daily in 0 0 * * *. The cron pattern definitely does not support seconds. But nevertheless it makes no sense to set it manually because it gets overwritten with every count event. When having no period set the cron pattern gets deleted with every count event.

I will set meter_period to none and go with your automation suggested.

Thanks a lot.

Unfortunately the automation did not work as expected, because the collecting entity is created as sensor. The service utility_meter.reset does not work with sensors. I had to use calibrate instead.

Then a script to call looks lihe this

sequence:
  - service: utility_meter.calibrate
    data:
      value: '0'
    target:
      entity_id: sensor.regenmenge_automation
mode: single
alias: Regenmenge Automation zurücksetzen
icon: mdi:null
1 Like

I have the same problem as DonKracho. .reset is not working for my utility_meters, (because they are generated as sensors?) or in general. Is this expected behavior and I should file an issue?

I have a similiar issue with a power meter sensor I had to create from current x voltage to then build another sensor based power over time as a Riemann Integral sensor I now have to reset and can not.

I am not sure what your code has to be used but I could not get that into my script section.

alias: Reset
sequence:
  - service: utility_meter.calibrate
    data:
      value: '0'
    target:
      entity_id: sensor.pv_balkon_energy_today
mode: single
icon: mdi:null

Where do I have to put this code , script or automation ?

Thanks a lot

FOR ALL THOSE WHO ARE STRUGGLING TO RESET A COUNTER MANUALLY

New Years day and my yearly counter has not reset for what ever reason while
daily and monthly have resetted properly,
weekly has not cause it is not a new monday so that was right

But my yearly counter sensor.verbrauch_gesamt_4_jahr did not reset

To solve that and reset I have used this calibration an set a trigger time at 14:00:00 to a value of 4.95
Make sure to use the . as decimal separator and not the “,” as used in german speaking countries and a lot of others.

Create an automation and switch to yaml mode (upper right menu) to paste this code

My alias starts with “-” to stay on top of the list till I have tested it enough and give that a proper name, so adjust your alias.

It is reseting my yearly counter called sensor.verbrauch_gesamt_4_jahr which is based on a Riemann Sum integral.

Once that has been saved then turn the automation on and adjust the trigger time a minute ahead in the future, use TAB to jump to the next and then you get the “save” button.
After saving turn the automation on and wait till it has run, check the data

AND DO NOT FORGET TO DEACTIVATE THIS AUTOMATION
till next time it will be needed.

If you forget that you get a daily reset at 16:00:00 to the same value.

alias: "- kWh Reset Riemann Jahr -"
description: ""
triggers:
  - trigger: time
    at: "16:00:00"
conditions: []
actions:
  - action: utility_meter.calibrate
    metadata: {}
    data:
      value: "4.95"
    target:
      entity_id: sensor.verbrauch_gesamt_4_jahr
mode: single

You don’t need to write an automation to do that. You can just use Developer Tools → Actions if you only want to run the action once.

1 Like

Thanks a lot.
I am not sure yet if I will need that next year again.

I do not know why the counter has not been reset - I have started that 3 months ago and I do not believe that this counter will be reset after 1 year so in 9 months or next new year.