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
70k stars 29.08k forks source link

Recorder broken, energy dashboard no data, unsupported operand type(s) for +: 'NoneType' and 'float' #115133

Open smoltron opened 3 months ago

smoltron commented 3 months ago

The problem

My HA has run flawlessly and without any errors logged. Now, after probably some 24.4. update, my energy dashboard stopped receiving data and after the latest update, the log is filling with unsupported operand type(s) for +: 'NoneType' and 'float'. I have done no changes in the system.

What version of Home Assistant Core has the issue?

core-2024.4.1

What was the last working version of Home Assistant Core?

core-2024.3.x

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

Maybe ESPHome that receives energy data, maybe MariaDb, difficult to know

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?


Typical log item:

Logger: homeassistant.components.recorder.core
Source: components/recorder/core.py:900
integration: Recorder (documentation, issues)
First occurred: 20:22:26 (3 occurrences)
Last logged: 20:30:10

Error while processing event CompileMissingStatisticsTask(): unsupported operand type(s) for +: 'NoneType' and 'float'
Error while processing event StatisticsTask(start=datetime.datetime(2024, 4, 7, 17, 20, tzinfo=datetime.timezone.utc), fire_events=True): unsupported operand type(s) for +: 'NoneType' and 'float'
Error while processing event StatisticsTask(start=datetime.datetime(2024, 4, 7, 17, 25, tzinfo=datetime.timezone.utc), fire_events=True): unsupported operand type(s) for +: 'NoneType' and 'float'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 900, in _guarded_process_one_task_or_event_or_recover
    self._process_one_task_or_event_or_recover(task)
  File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 920, in _process_one_task_or_event_or_recover
    return task.run(self)
           ^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/recorder/tasks.py", line 177, in run
    if statistics.compile_missing_statistics(instance):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/recorder/util.py", line 645, in wrapper
    return job(instance, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/recorder/statistics.py", line 471, in compile_missing_statistics
    modified_statistic_ids = _compile_statistics(
                             ^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/recorder/statistics.py", line 547, in _compile_statistics
    compiled: PlatformCompiledStatistics = platform_compile_statistics(
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/recorder.py", line 467, in compile_statistics
    last_stats = statistics.get_latest_short_term_statistics_with_session(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/recorder/statistics.py", line 1959, in get_latest_short_term_statistics_with_session
    return _sorted_statistics_to_dict(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/recorder/statistics.py", line 2128, in _sorted_statistics_to_dict
    "end": start_ts + table_duration_seconds,
           ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for +: 'NoneType' and 'float'
'''

### Additional information

_No response_
home-assistant[bot] commented 3 months ago

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

Code owner commands Code owners of `recorder` 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 recorder` 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)


recorder documentation recorder source (message by IssueLinks)

bdraco commented 3 months ago

duplicate of https://github.com/home-assistant/core/issues/112133

smoltron commented 3 months ago

I see that this is probably caused by a downgrade that I had to do because of an error in an upgrade. How can I fix this in MariaDb? I saw some solution for SQLite, but is it the same in MariaDb?

bdraco commented 3 months ago

The query for MariaDB/MySQL is in the code here

https://github.com/home-assistant/core/blob/05440ec04cd146035d4682ab8ac9de7c4e696b6c/homeassistant/components/recorder/migration.py#L1417

jonny190 commented 2 months ago

Hi all, I've got the same issue, I've tried manually running

UPDATE statistics
set start_ts=
IF(start is NULL or UNIX_TIMESTAMP(start) is NULL,0,
UNIX_TIMESTAMP(start) 
), 
created_ts=
UNIX_TIMESTAMP(created), 
last_reset_ts=
UNIX_TIMESTAMP(last_reset) 
where start_ts is NULL ;

and

UPDATE statistics_short_term
set start_ts=
IF(start is NULL or UNIX_TIMESTAMP(start) is NULL,0,
UNIX_TIMESTAMP(start) 
), 
created_ts=
UNIX_TIMESTAMP(created), 
last_reset_ts=
UNIX_TIMESTAMP(last_reset) 
where start_ts is NULL;

both returned 0 rows affected. Is there anything else I could try?

gerhardvilsecker commented 1 week ago

I have similar problems. No Energy Dashboard data since July 5th. Not possible to configure energy dashboard. Errormessage when trying to configure energy dashboard: Unknown error. Here is my relevant part of HAlog:

2024-07-05 09:15:10.375 ERROR (Recorder) [homeassistant.components.recorder.util] Error executing query File "/usr/src/homeassistant/homeassistant/components/recorder/util.py", line 137, in session_scope File "/usr/src/homeassistant/homeassistant/components/recorder/statistics.py", line 508, in compile_statistics File "/usr/src/homeassistant/homeassistant/components/recorder/statistics.py", line 559, in _compile_statistics File "/usr/src/homeassistant/homeassistant/components/sensor/recorder.py", line 400, in compile_statistics File "/usr/src/homeassistant/homeassistant/components/sensor/recorder.py", line 92, in _get_sensor_states File "/config/custom_components/places/recorder_history_prefilter/recorder_prefilter.py", line 123, in entity_filter return recorder_entity_filter(entity_id) 2024-07-05 09:15:10.379 ERROR (Recorder) [homeassistant.components.recorder.core] Error while processing event StatisticsTask(start=datetime.datetime(2024, 7, 5, 7, 10, tzinfo=datetime.timezone.utc), fire_events=True) File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 911, in _guarded_process_one_task_or_event_or_recover File "/usr/src/homeassistant/homeassistant/components/recorder/core.py", line 931, in _process_one_task_or_event_or_recover File "/usr/src/homeassistant/homeassistant/components/recorder/tasks.py", line 166, in run File "/usr/src/homeassistant/homeassistant/components/recorder/util.py", line 644, in wrapper File "/usr/src/homeassistant/homeassistant/components/recorder/statistics.py", line 508, in compile_statistics File "/usr/src/homeassistant/homeassistant/components/recorder/statistics.py", line 559, in _compile_statistics File "/usr/src/homeassistant/homeassistant/components/sensor/recorder.py", line 400, in compile_statistics File "/usr/src/homeassistant/homeassistant/components/sensor/recorder.py", line 92, in _get_sensor_states Seems to me that I have "lost" recorder ability...

Please advice what to do. I am on most curren HA version on raspberrypie

bdraco commented 1 week ago

places/recorder_history_prefilter

@gerhardvilsecker You have an similar problem to https://community.home-assistant.io/t/psa-2024-7-recorder-problems/746428 caused by the places integration

gerhardvilsecker commented 6 days ago

Thank you. Problem was due to places Integration. Update of places resolved my problem.

J. Nick Koston @.***> schrieb am Mi., 10. Juli 2024, 16:32:

places/recorder_history_prefilter

@gerhardvilsecker https://github.com/gerhardvilsecker You have an similar problem to https://community.home-assistant.io/t/psa-2024-7-recorder-problems/746428 caused by the places integration

— Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/115133#issuecomment-2220678885, or unsubscribe https://github.com/notifications/unsubscribe-auth/BEYXPZNRCESPKE47KDZCCJTZLVAXNAVCNFSM6AAAAABF3PXIS6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRQGY3TQOBYGU . You are receiving this because you were mentioned.Message ID: @.***>