`history_stats` doesn't allow `state_class` for statistics tracking
See original GitHub issueReopening #66995 (by @rct). I don’t understand what is the sense of locking issue comments.
Still valid for 2022.11.3.
The problem
The history_stats integration doesn’t allow state_class to be defined. This prevents history_stats sensors from being used as statistics.
Tested against 2022.2.9, error from check configuration:
Invalid config for [sensor.history_stats]: [state_class] is an invalid option for [sensor.history_stats]. Check: sensor.history_stats->state_class. (See ?, line ?).
What version of Home Assistant Core has the issue?
core-2022.2.9
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant Supervised
Integration causing the issue
history_stats
Link to integration documentation on our website
https://www.home-assistant.io/integrations/history_stats/
Diagnostics information
No response
Example YAML snippet
sensor: platform: history_stats name: lyrichk_runtime entity_id: binary_sensor.lyrichk_running state: 'on' type: time start: '{{ now().replace(hour=0, minute=0, second=0) }}' end: '{{ now() }}' # as of 2022.2.9 - this isn't (yet) valid for history_stats state_class: measurement
Anything in the logs that might be useful for us?
No response
Additional information
No response
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
history_stats doesn't allow state_class for statistics tracking
The history_stats integration doesn't allow state_class to be defined. This prevents history_stats sensors from being used as statistics. Tested ...
Read more >History statistics component - Home Assistant Community
state : The state you want to track. name: What to display on the frontend ... I think it's a great idea; I'd...
Read more >Use History Stats in Home Assistant for insights ... - YouTube
In this video, I just scratch the surface of historical stats using the history stats platform in Home Assistant. I visualize the data...
Read more >Home Assistant How To - get more Statistics from sensors
Getting more statistics from your existing sensors and binary sensors is very easy with Home Assistant built-in component - Statistics.
Read more >Towards a smarter Home Assistant - CGomesu
yaml file and therefore, it allows users to keep summary statistics for longer than the recorder configuration allows to keep data in the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
history_stats
sensors automatically setstate_class = measurement
, so statistics are available.However,
state_class
cannot be changed to something else in the config. It would be useful to be able to change it. For instance a sensor tracking how much time a thermostat was on today would make sense to havestate_class = total_increasing
.Sorry, I wasn’t completely clear. The issue was different. I needed to use it within the statistic card (not graph) and use the
stat_type: change
, which works only forstate_class: total
and thehistory_stats
uses justmeasurement
. So I had to bypass it by creating a second template sensor withstate_class: total
.E.g.: