question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`history_stats` doesn't allow `state_class` for statistics tracking

See original GitHub issue

Reopening #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:open
  • Created 10 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
chatzikocommented, Dec 2, 2022

history_stats sensors automatically set state_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 have state_class = total_increasing.

0reactions
krystof-kcommented, Dec 30, 2022

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 for state_class: total and the history_stats uses just measurement. So I had to bypass it by creating a second template sensor with state_class: total.

E.g.:

sensor:
  - platform: history_stats
    name: Kotel 1 doba hoření celková statistika
    type: time
    entity_id: sensor.kotel_1
    state: Hoří
    start: "{{ 0 }}"
    end: "{{ now() }}"
template:
  - sensor:
      - name: Kotel 1 doba hoření celková
        state: "{{ states('sensor.kotel_1_doba_horeni_celkova_statistika') }}"
        state_class: total
        device_class: duration
        unit_of_measurement: h
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found