Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Counter sensors are not restored after a restart #10994

Closed
romain38 opened this issue Dec 6, 2017 · 13 comments · Fixed by #17101
Closed

Counter sensors are not restored after a restart #10994

romain38 opened this issue Dec 6, 2017 · 13 comments · Fixed by #17101

Comments

@romain38
Copy link

romain38 commented Dec 6, 2017

Home Assistant release (hass --version):
0.59.2 / 0.60.0 / 0.61.1 / 0.70.0

Python release (python3 --version):
3.6.3

Component/platform:
Counter

Description of problem:
After each restart all counters values are lost.

Expected:
Previous counter values are restored.

Problem-relevant configuration.yaml entries and steps to reproduce:

counter:
  with_initial:
    initial: 10
    step: 1
  without_initial:
    step: 1
  1. Start Home-Assistant
  2. counter.with_initial is set to 10, counter.without_initial is set to 0
  3. Call counter.increment service for each counter
  4. counter.with_initial is set to 11, counter.without_initial is set to 1
  5. Restart Home-Assistant
  6. counter.with_initial is set to 10, counter.without_initial is set to 0
@romain38
Copy link
Author

romain38 commented Dec 6, 2017

Link from discussion on community forum: https://community.home-assistant.io/t/persistent-counters/33621/9

Regards,

Romain.

@ajfriesen
Copy link

I am running Hass.io on version 0.60.0 and the conter does not restore itself when I restart Home Assistant.

@willwhui

This comment has been minimized.

@ajfriesen
Copy link

Ok, I had some time at the weekend and did install a local dev environment for home assistant.
I added a counter without an initial value. Started home assistant in GUI mode. Incremented the counter. Restart. Checked the value which was wrong.
The counter definitely does not restore the state after a restart.

I tried to look through the code but my python is still at the very beginning.

@mbevilacqua
Copy link

Still an issue on 0.61.1

@grahampowell
Copy link

I noticed that even if you don't set an initial: value, it defaults back to zero. Could we use a template value for initial:? perhaps from an mqtt feed?

@balloobbot
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

@romain38
Copy link
Author

This issue is still present on the latest version (v0.70.0).

Regards,

Romain.

@mbevilacqua

This comment has been minimized.

@kozoke

This comment has been minimized.

2 similar comments
@DetroitEE

This comment has been minimized.

@donkristo

This comment has been minimized.

@mvn23
Copy link
Contributor

mvn23 commented Oct 2, 2018

Looks like the issue is in home-assistant/homeassistant/components/counter/__init__.py line 132:
self._state = state and state.state == state always evaluates to False rather than an integer value.
For me, replacing this line with self._state = state.state seems to fix the issue, but this has not been tested extensively. Maybe @fabaff can take a look at this suggestion?

Edit: already found one problem with this solution, state.state should be cast to an int when assigning to self._state

Another edit: Disregard this comment, there's a bit more to it. I may file a PR soon.

@mvn23 mvn23 mentioned this issue Oct 3, 2018
4 tasks
@ghost ghost added the in progress label Oct 3, 2018
@ghost ghost removed the in progress label Oct 3, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

11 participants