Persistent Counters?

Does anyone know of a way to pull off a persistent counter that will pick up where it left off in the case of a reboot of HA? The only idea I can think of (with my limited familiarity with HA) is using the “counter” component that somehow links to some sort of non-volatile memory such as a simple .txt file, writing the current value to the file on a periodic basis and pulling from it to set its initial value after a reboot. Can anyone confirm that this is possible and/or provide any pointers on how to accomplish that?

I think there are a couple in share your projects.

Cool, let me know when you finish your post with some contributing information.

You can use this

1 Like

The counter supports restoring the state on startup already or at least it should according to the unit tests.

It doesn’t as far as I can tell. Nothing in the official documentation about that feature, either. Curious, where did you get the idea it would support that? Sure would be nice.

Thanks! The variable component looks pretty good, since they added that “restore” attribute. I’ll give it a shot.

Because I created the component and wrote the unit tests.

1 Like

Hmm, then I’m surprised you’re wrong. Think support for this can be added soon?

Hi,

Same problem for me with 0.59.2 version (and previous).
I’ve opened an issue: https://github.com/home-assistant/home-assistant/issues/10994.

Regards,

Romain.

I agree this would be nice. I want to track when to buy new filters etc based on use. So counting things over a long period.

@fabaff, I’ve been trying to use the restore feature and its not working for me either

Looks like the config_schema uses an Optional field with a default value, so there is always an _initial in there for the async_added_to_hass check.
In fact, the unit tests are asserting that a counter without config with a last state of 11, gets resetted to 0 (https://github.com/home-assistant/home-assistant/blob/master/tests/components/counter/test_init.py#L175)

1 Like

I just had asked on Discord but then found this post.
Running Hass.io on version 0.60.0 and the conter does not restore after a restart.

I am looking for a way to set a countdown timer (which can be continued after the hass reboot).
After some searching work, I think maybe I can use component recorder and component input_number to achieve my goal.
Will try it later.
:thinking: