Start a counter (number of days) since a reset

Hello

is they a way to Start a counter (number of days) base on a reset

i have a fuel tank, i would like to know how much day’s i am day was pass since i reset the counter

Tks

1 Like

Sure you can do that. Just go to helpers and create a counter. Then use an automation that increments it once a day like this:

automation:
  - id: my_counter_incrementer
    trigger:
      platform: time
      at: '00:00'
    action:
      service: counter.increment
      data:
        entity_id: counter.my_counter

You can use the counter.reset service to reset it to 0 which can be called either manually from the UI or from an automation (if you have a way to detect when your tank has been refueled).

That being said, you don’t technically need a counter here. You can do this without an automation at all if you use a DateTime helper (you add it from the same page I linked at the top). Whenever you refill your tank just set it to the current date. Then you can show the time since you last filled up in the UI by dropping something like this in a markdown card:

type: markdown
content: >-
  Last refilled gas {{ states('input_datetime.refilled_gas') | as_datetime | relative_time }} ago

Looks like this:
Screen Shot 2022-03-29 at 7.38.31 PM

1 Like

Hi

i fact it more a timer that would like

Let say… i reset my fuel tank to full then a timer should start… a entity should show the time day:hours since i reset my fuel tank.

this information will be useful to know the duration since when i refill my tank

Tks

1 Like

If you have the time you reset it, subtract that time from now()