home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
70.92k stars 29.58k forks source link

Statistics-graph not loading data #122065

Open sorted-bits opened 1 month ago

sorted-bits commented 1 month ago

The problem

In my Home Assistant installation, I have a weird issue with using a statistics-graph in combination with some of my utility meters.

I have the following configuration for a card in my dashboard:

chart_type: bar
period: day
type: statistics-graph
entities:
  - sensor.zwembadpomp_dagelijks
stat_types:
  - state
hide_legend: false
days_to_show: 30

The sensor.zwembadpomp_dagelijks is a utility meter, which I made. It uses an energy state for a smart-plug I am using, which is an always increasing value.

When I add this card to my dashboard, the following errors show up in my log, when I try to display the dashboard.

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/connection.py:229
integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 00:54:13 (65 occurrences)
Last logged: 12:19:28

[128796376501984] Error handling message: Unknown error (unknown_error) XXX from 10.210.0.1 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36)
[128796289557856] Error handling message: Unknown error (unknown_error) XXX from 10.210.0.1 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36)
[128796248154192] Error handling message: Unknown error (unknown_error) XXX from 10.210.0.1 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36)
[128796248154624] Error handling message: Unknown error (unknown_error) XXX from 10.210.0.1 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36)
[128796248150448] Error handling message: Unknown error (unknown_error) XXX from 10.210.0.1 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/connection.py", line 229, in async_handle
    handler(self.hass, self, schema(msg))
                             ^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
    return base_validate(path, iteritems(data), out)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 387, in validate_mapping
    cval = cvalue(key_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
    return base_validate(path, iteritems(data), out)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 387, in validate_mapping
    cval = cvalue(key_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 755, in __call__
    or 'value must be one of {}'.format(sorted(self.container)))
                                        ^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'str' and 'NoneType'

There are a couple of things, that I looked at:

I have the following configuration for a card in my dashboard:

chart_type: bar
period: day
type: statistics-graph
entities:
  - sensor.zwembadpomp_dagelijks
stat_types:
  - state
hide_legend: false
days_to_show: 30

The sensor.zwembadpomp_dagelijks is a utility meter, which I made. It uses an energy state for a smart-plug I am using, which is an always increasing value.

When I add this card to my dashboard, the following errors show up in my log, when I try to display the dashboard.

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/connection.py:229
integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 00:54:13 (65 occurrences)
Last logged: 12:19:28

[128796376501984] Error handling message: Unknown error (unknown_error) XXX from 10.210.0.1 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36)
[128796289557856] Error handling message: Unknown error (unknown_error) XXX from 10.210.0.1 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36)
[128796248154192] Error handling message: Unknown error (unknown_error) XXX from 10.210.0.1 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36)
[128796248154624] Error handling message: Unknown error (unknown_error) XXX from 10.210.0.1 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36)
[128796248150448] Error handling message: Unknown error (unknown_error) XXX from 10.210.0.1 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/connection.py", line 229, in async_handle
    handler(self.hass, self, schema(msg))
                             ^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
    return base_validate(path, iteritems(data), out)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 387, in validate_mapping
    cval = cvalue(key_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
    return base_validate(path, iteritems(data), out)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 387, in validate_mapping
    cval = cvalue(key_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 755, in __call__
    or 'value must be one of {}'.format(sorted(self.container)))
                                        ^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'str' and 'NoneType'

There are a couple of things, that I looked at:

What version of Home Assistant Core has the issue?

core-2024.7.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Home Assistant WebSocket API

Link to integration documentation on our website

https://www.home-assistant.io/integrations/websocket_api

Diagnostics information

No response

Example YAML snippet

chart_type: bar
period: day
type: statistics-graph
entities:
  - sensor.zwembadpomp_dagelijks
stat_types:
  - state
hide_legend: false
days_to_show: 30

Anything in the logs that might be useful for us?

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/connection.py:229
integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 00:54:13 (65 occurrences)
Last logged: 12:19:28

[128796376501984] Error handling message: Unknown error (unknown_error) XXX from 10.210.0.1 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36)
[128796289557856] Error handling message: Unknown error (unknown_error) XXX from 10.210.0.1 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36)
[128796248154192] Error handling message: Unknown error (unknown_error) XXX from 10.210.0.1 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36)
[128796248154624] Error handling message: Unknown error (unknown_error) XXX from 10.210.0.1 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36)
[128796248150448] Error handling message: Unknown error (unknown_error) XXX from 10.210.0.1 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/connection.py", line 229, in async_handle
    handler(self.hass, self, schema(msg))
                             ^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
    return base_validate(path, iteritems(data), out)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 387, in validate_mapping
    cval = cvalue(key_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 272, in __call__
    return self._compiled([], data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 595, in validate_dict
    return base_validate(path, iteritems(data), out)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 387, in validate_mapping
    cval = cvalue(key_path, value)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/schema_builder.py", line 818, in validate_callable
    return schema(data)
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 755, in __call__
    or 'value must be one of {}'.format(sorted(self.container)))
                                        ^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'str' and 'NoneType'

Additional information

No response

home-assistant[bot] commented 1 month ago

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (websocket_api) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `websocket_api` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign websocket_api` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


websocket_api documentation websocket_api source (message by IssueLinks)

rrooggiieerr commented 1 month ago

If you remove the statistics-graph from your dashboard, do you still get the error? I'm asking because it could be that something else on your dashboard might actually generate the error, break the connection en that being the cause of your graph not being rendered.

What's happening here is that a message fails to be generated because self.container can not be sorted. self.container contains str and NoneType values, and those don't support the < comparator.

  File "/usr/local/lib/python3.12/site-packages/voluptuous/validators.py", line 755, in __call__
    or 'value must be one of {}'.format(sorted(self.container)))
                                        ^^^^^^^^^^^^^^^^^^^^^^
TypeError: '<' not supported between instances of 'str' and 'NoneType'

Are you using conditional cards or the new visibility configuration of cards on your dashboard?

sorted-bits commented 1 month ago

Thanks for your reply, using an empty dashboard with just this statistics-graph causes the error to appear in the log as well, this is an example of the raw dashboard configuration:

views:
  - title: Home
    type: sections
    sections:
      - type: grid
        cards:
          - chart_type: bar
            period: day
            type: statistics-graph
            entities:
              - sensor.zwembadpomp_dagelijks
            stat_types:
              - state
            hide_legend: true
            days_to_show: 30

I am not using any conditional cards. Not on this dashboard or any to be honest. I am using this on a sections dashboard, but also adding it to an empty masonry dashboard causes the same error.

Removing the card from that dashboard stops the error from appearing in the logs. Adding it back in, immediately makes it appear in the logs again (and also, the card is not loading).

After restarting Home Assistant a couple of times, this message appeared in the logs:

WARNING (Recorder) [homeassistant.components.sensor.recorder] The unit of sensor.zwembadpomp_dagelijks (kWh) cannot be converted to the unit of previously compiled statistics (None). Generation of long term statistics will be suppressed unless the unit changes back to None or a compatible unit. Go to https://my.home-assistant.io/redirect/developer_statistics to fix this

Clicking the link allowed me to fix a bunch of non functional sensors (the ones causing errors). It seems I lost some data there, but at least the graph started loading!