Recorder component - error saving events

Once a day, hassio stops recording states from multiple (maybe all) sensors, and logs the following errors.
How could I fix it, or find the root cause?
I can currently only resolve it by restarting hassio once a days…

Logger: homeassistant.components.recorder
Source: components/recorder/__init__.py:497
Integration: Recorder (documentation, issues)
First occurred: 4:12:18 AM (12832 occurrences)
Last logged: 8:58:13 AM

    Error saving events: Instance <States at 0xa9790028> is not present in this Session
    Error saving events: Instance <States at 0xa13706a0> is not present in this Session

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 442, in _commit_event_session_or_retry
    self._commit_event_session()
  File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 497, in _commit_event_session
    self.event_session.expunge(dbstate)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 1854, in expunge
    raise sa_exc.InvalidRequestError(
sqlalchemy.exc.InvalidRequestError: Instance <States at 0xa9790028> is not present in this Session


--------------------



Logger: homeassistant.components.recorder
Source: components/recorder/__init__.py:501
Integration: Recorder (documentation, issues)
First occurred: 4:12:18 AM (17042 occurrences)
Last logged: 8:58:13 AM

    Error executing query: (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id [SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: ((6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:58:00.500656', '2020-10-10 06:58:01.555406', 'ef53a6a80ac511eb982a77c2b2c71a40', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:55.456939', '2020-10-10 06:57:56.558088', 'ec520a7a0ac511eb9b608d40669909fc', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:50.418888', '2020-10-10 06:57:51.542324', 'e9514ebe0ac511eb8cb063722451d252', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:45.345269', '2020-10-10 06:57:46.446058', 'e64b20f70ac511ebaabf835f9c4a2e83', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:39.624204', '2020-10-10 06:57:41.375389', 'e2e22cf50ac511ebb2b3e9265649ee77', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:34.572935', '2020-10-10 06:57:36.302499', 'dfdf6a3b0ac511eb98885b395eda5386', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:29.506124', '2020-10-10 06:57:31.134954', 'dcda446a0ac511eb8b42c5eeeae89434', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:24.456126', '2020-10-10 06:57:26.119832', 'd9d7b3220ac511eba565919d55c72958', None, None) ... displaying 10 of 3357 total bound parameter sets ... (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:31.400829', '2020-10-10 02:13:35.767220', '3159bb900a9e11ebb30983dbf2517983', None, None), (6312943, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:26.358410', '2020-10-10 02:13:28.848336', '2e5850ea0a9e11ebab89e72efd37a28f', None, None))] (Background on this error at: http://sqlalche.me/e/13/gkpj)
    Error executing query: Instance <States at 0xa13706a0> is not present in this Session
    Error executing query: (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id [SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: ((6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:58:03.449812', '2020-10-10 06:58:04.551899', 'f115ab450ac511eb88cce5992e3d7b1c', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:58.396088', '2020-10-10 06:58:00.105202', 'ee12883a0ac511eb8e5da314412e0ab7', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:53.320885', '2020-10-10 06:57:55.125765', 'eb0c1e060ac511eb8f4087e260c91591', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:48.266694', '2020-10-10 06:57:50.115290', 'e808e6d20ac511eb84a33d7373e1d7bf', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:43.206839', '2020-10-10 06:57:44.553911', 'e504d6250ac511eb88235d20c7ecc311', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:38.154463', '2020-10-10 06:57:39.551163', 'e201e9880ac511eba9601f86c3f3a0a0', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:33.102248', '2020-10-10 06:57:34.537921', 'defeff840ac511ebbd1c2fa1600ce90e', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:28.047609', '2020-10-10 06:57:28.947393', 'dbfbba540ac511eb940cff60f31b441b', None, None) ... displaying 10 of 3303 total bound parameter sets ... (6312943, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:36.419652', '2020-10-10 02:13:38.152299', '345788e00a9e11ebbb7ea904f53ed3e9', None, None), (6312943, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:31.364619', '2020-10-10 02:13:35.766063', '3154348d0a9e11ebb466bf1a3f71715a', None, None))] (Background on this error at: http://sqlalche.me/e/13/gkpj)
    Error executing query: (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id [SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: ((6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:56:09.746359', '2020-10-10 06:56:10.023782', 'ad4fe86c0ac511ebb80ffdf916c75968', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:54:09.745440', '2020-10-10 06:54:10.024155', '65c9352a0ac511eb948f692f81210466', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:52:09.744124', '2020-10-10 06:52:10.828424', '1e42792d0ac511ebadd38967837d7f28', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:50:09.739975', '2020-10-10 06:50:10.014782', 'd6bb4b180ac411eb91af31b7a7236014', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:48:09.739333', '2020-10-10 06:48:10.027203', '8f34a11a0ac411eb9c81a9f4b2e2e54d', None, None), (6312945, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:46:09.737661', '2020-10-10 06:48:10.028929', '47add9120ac411ebabec032d76bcb03d', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:44:09.731320', '2020-10-10 06:44:17.063480', '002651000ac411eb8c6be76aef938435', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:42:09.729481', '2020-10-10 06:42:10.020661', 'b89f7dfd0ac311eba2dd77e9a35785a7', None, None) ... displaying 10 of 59 total bound parameter sets ... (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:39:49.022390', '2020-10-10 02:39:50.013937', 'ddafaa5f0aa111eb8b978dac243e26bf', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:19:49.021898', '2020-10-10 02:19:50.005855', '126e1e280a9f11eb83e01f283b9866f8', None, None))] (Background on this error at: http://sqlalche.me/e/13/gkpj)
    Error executing query: (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id [SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: ((6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:58:05.546187', '2020-10-10 06:58:07.169593', 'f2558d350ac511eb90a28dd434a5a67c', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:58:00.500656', '2020-10-10 06:58:01.555406', 'ef53a6a80ac511eb982a77c2b2c71a40', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:55.456939', '2020-10-10 06:57:56.558088', 'ec520a7a0ac511eb9b608d40669909fc', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:29.506124', '2020-10-10 06:57:31.134954', 'dcda446a0ac511eb8b42c5eeeae89434', None, None) ... displaying 10 of 3358 total bound parameter sets ... (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:31.400829', '2020-10-10 02:13:35.767220', '3159bb900a9e11ebb30983dbf2517983', None, None), (6312943, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:26.358410', '2020-10-10 02:13:28.848336', '2e5850ea0a9e11ebab89e72efd37a28f', None, None))] (Background on this error at: http://sqlalche.me/e/13/gkpj)



-----------------



Logger: homeassistant.components.recorder
Source: components/recorder/__init__.py:493
Integration: Recorder (documentation, issues)
First occurred: 4:13:43 AM (4189 occurrences)
Last logged: 8:58:12 AM

    Error saving events: (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id [SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: ((6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:58.396088', '2020-10-10 06:58:00.105202', 'ee12883a0ac511eb8e5da314412e0ab7', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:53.320885', '2020-10-10 06:57:55.125765', 'eb0c1e060ac511eb8f4087e260c91591', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:48.266694', '2020-10-10 06:57:50.115290', 'e808e6d20ac511eb84a33d7373e1d7bf', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:43.206839', '2020-10-10 06:57:44.553911', 'e504d6250ac511eb88235d20c7ecc311', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:38.154463', '2020-10-10 06:57:39.551163', 'e201e9880ac511eba9601f86c3f3a0a0', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:33.102248', '2020-10-10 06:57:34.537921', 'defeff840ac511ebbd1c2fa1600ce90e', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:28.047609', '2020-10-10 06:57:28.947393', 'dbfbba540ac511eb940cff60f31b441b', None, None), (6312945, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:22.960923', '2020-10-10 06:57:28.949232', 'd8f38e470ac511eb94aa41e4b444ef98', None, None) ... displaying 10 of 3302 total bound parameter sets ... (6312943, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:36.419652', '2020-10-10 02:13:38.152299', '345788e00a9e11ebbb7ea904f53ed3e9', None, None), (6312943, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:31.364619', '2020-10-10 02:13:35.766063', '3154348d0a9e11ebb466bf1a3f71715a', None, None))] (Background on this error at: http://sqlalche.me/e/13/gkpj)
    Error saving events: (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id [SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: ((6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:58:00.500656', '2020-10-10 06:58:01.555406', 'ef53a6a80ac511eb982a77c2b2c71a40', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:55.456939', '2020-10-10 06:57:56.558088', 'ec520a7a0ac511eb9b608d40669909fc', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:50.418888', '2020-10-10 06:57:51.542324', 'e9514ebe0ac511eb8cb063722451d252', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:45.345269', '2020-10-10 06:57:46.446058', 'e64b20f70ac511ebaabf835f9c4a2e83', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:39.624204', '2020-10-10 06:57:41.375389', 'e2e22cf50ac511ebb2b3e9265649ee77', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:34.572935', '2020-10-10 06:57:36.302499', 'dfdf6a3b0ac511eb98885b395eda5386', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:29.506124', '2020-10-10 06:57:31.134954', 'dcda446a0ac511eb8b42c5eeeae89434', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:24.456126', '2020-10-10 06:57:26.119832', 'd9d7b3220ac511eba565919d55c72958', None, None) ... displaying 10 of 3357 total bound parameter sets ... (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:31.400829', '2020-10-10 02:13:35.767220', '3159bb900a9e11ebb30983dbf2517983', None, None), (6312943, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:26.358410', '2020-10-10 02:13:28.848336', '2e5850ea0a9e11ebab89e72efd37a28f', None, None))] (Background on this error at: http://sqlalche.me/e/13/gkpj)
    Error saving events: (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id [SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: ((6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:58:03.449812', '2020-10-10 06:58:04.551899', 'f115ab450ac511eb88cce5992e3d7b1c', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:58.396088', '2020-10-10 06:58:00.105202', 'ee12883a0ac511eb8e5da314412e0ab7', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:53.320885', '2020-10-10 06:57:55.125765', 'eb0c1e060ac511eb8f4087e260c91591', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:48.266694', '2020-10-10 06:57:50.115290', 'e808e6d20ac511eb84a33d7373e1d7bf', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:43.206839', '2020-10-10 06:57:44.553911', 'e504d6250ac511eb88235d20c7ecc311', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:38.154463', '2020-10-10 06:57:39.551163', 'e201e9880ac511eba9601f86c3f3a0a0', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:33.102248', '2020-10-10 06:57:34.537921', 'defeff840ac511ebbd1c2fa1600ce90e', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:28.047609', '2020-10-10 06:57:28.947393', 'dbfbba540ac511eb940cff60f31b441b', None, None) ... displaying 10 of 3303 total bound parameter sets ... (6312943, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:36.419652', '2020-10-10 02:13:38.152299', '345788e00a9e11ebbb7ea904f53ed3e9', None, None), (6312943, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:31.364619', '2020-10-10 02:13:35.766063', '3154348d0a9e11ebb466bf1a3f71715a', None, None))] (Background on this error at: http://sqlalche.me/e/13/gkpj)
    Error saving events: (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id [SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: ((6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:56:09.746359', '2020-10-10 06:56:10.023782', 'ad4fe86c0ac511ebb80ffdf916c75968', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:54:09.745440', '2020-10-10 06:54:10.024155', '65c9352a0ac511eb948f692f81210466', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:52:09.744124', '2020-10-10 06:52:10.828424', '1e42792d0ac511ebadd38967837d7f28', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:50:09.739975', '2020-10-10 06:50:10.014782', 'd6bb4b180ac411eb91af31b7a7236014', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:48:09.739333', '2020-10-10 06:48:10.027203', '8f34a11a0ac411eb9c81a9f4b2e2e54d', None, None), (6312945, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:46:09.737661', '2020-10-10 06:48:10.028929', '47add9120ac411ebabec032d76bcb03d', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:44:09.731320', '2020-10-10 06:44:17.063480', '002651000ac411eb8c6be76aef938435', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:42:09.729481', '2020-10-10 06:42:10.020661', 'b89f7dfd0ac311eba2dd77e9a35785a7', None, None) ... displaying 10 of 59 total bound parameter sets ... (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:39:49.022390', '2020-10-10 02:39:50.013937', 'ddafaa5f0aa111eb8b978dac243e26bf', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:19:49.021898', '2020-10-10 02:19:50.005855', '126e1e280a9f11eb83e01f283b9866f8', None, None))] (Background on this error at: http://sqlalche.me/e/13/gkpj)
    Error saving events: (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id [SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: ((6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:58:05.546187', '2020-10-10 06:58:07.169593', 'f2558d350ac511eb90a28dd434a5a67c', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:58:00.500656', '2020-10-10 06:58:01.555406', 'ef53a6a80ac511eb982a77c2b2c71a40', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:55.456939', '2020-10-10 06:57:56.558088', 'ec520a7a0ac511eb9b608d40669909fc', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:50.418888', '2020-10-10 06:57:51.542324', 'e9514ebe0ac511eb8cb063722451d252', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:45.345269', '2020-10-10 06:57:46.446058', 'e64b20f70ac511ebaabf835f9c4a2e83', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:39.624204', '2020-10-10 06:57:41.375389', 'e2e22cf50ac511ebb2b3e9265649ee77', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:34.572935', '2020-10-10 06:57:36.302499', 'dfdf6a3b0ac511eb98885b395eda5386', None, None), (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:57:29.506124', '2020-10-10 06:57:31.134954', 'dcda446a0ac511eb8b42c5eeeae89434', None, None) ... displaying 10 of 3358 total bound parameter sets ... (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:31.400829', '2020-10-10 02:13:35.767220', '3159bb900a9e11ebb30983dbf2517983', None, None), (6312943, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:26.358410', '2020-10-10 02:13:28.848336', '2e5850ea0a9e11ebab89e72efd37a28f', None, None))] (Background on this error at: http://sqlalche.me/e/13/gkpj)

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1256, in _execute_context
    self.dialect.do_executemany(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 590, in do_executemany
    cursor.executemany(statement, parameters)
sqlite3.IntegrityError: UNIQUE constraint failed: events.event_id

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 442, in _commit_event_session_or_retry
    self._commit_event_session()
  File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 493, in _commit_event_session
    self.event_session.flush()
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 2523, in flush
    self._flush(objects)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 2664, in _flush
    transaction.rollback(_capture_exception=True)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.raise_(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
    raise exception
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 2624, in _flush
    flush_context.execute()
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 419, in execute
    n.execute_aggregate(self, set_)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 521, in execute_aggregate
    self.execute(uow)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 586, in execute
    persistence.save_obj(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 239, in save_obj
    _emit_insert_statements(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 1083, in _emit_insert_statements
    c = cached_connections[connection].execute(statement, multiparams)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
    return meth(self, multiparams, params)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement
    ret = self._execute_context(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
    self._handle_dbapi_exception(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1510, in _handle_dbapi_exception
    util.raise_(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
    raise exception
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1256, in _execute_context
    self.dialect.do_executemany(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 590, in do_executemany
    cursor.executemany(statement, parameters)
sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id
[SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)]
[parameters: ((6312943, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:36.419652', '2020-10-10 02:13:38.152299', '345788e00a9e11ebbb7ea904f53ed3e9', None, None), (6312943, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:31.364619', '2020-10-10 02:13:35.766063', '3154348d0a9e11ebb466bf1a3f71715a', None, None))]
(Background on this error at: http://sqlalche.me/e/13/gkpj)


--------------



Logger: homeassistant
Source: helpers/temperature.py:23
First occurred: October 9, 2020, 10:40:37 AM (1338 occurrences)
Last logged: 8:58:05 AM
Error doing job: Task exception was never retrieved

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 592, in _update_entity_states
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 283, in async_update_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 322, in _async_write_ha_state
    attr.update(self.state_attributes or {})
  File "/usr/src/homeassistant/homeassistant/components/water_heater/__init__.py", line 175, in state_attributes
    ATTR_TEMPERATURE: show_temp(
  File "/usr/src/homeassistant/homeassistant/helpers/temperature.py", line 23, in display_temp
    raise TypeError(f"Temperature is not a number: {temperature}")
TypeError: Temperature is not a number: error


--------------



Logger: homeassistant.components.recorder
Source: components/recorder/__init__.py:493
Integration: Recorder (documentation, issues)
First occurred: 4:13:35 AM (21 occurrences)
Last logged: 8:37:46 AM

    Error saving events: (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id [SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:28:48.102933', '2020-10-10 02:28:49.006548', '53bf600d0aa011ebaeaf9990c0d32896', None, None)] (Background on this error at: http://sqlalche.me/e/13/gkpj)
    Error saving events: (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id [SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 04:09:59.498296', '2020-10-10 04:10:00.010554', '7694c9b70aae11eb819c232a6eedb2a8', None, None)] (Background on this error at: http://sqlalche.me/e/13/gkpj)
    Error saving events: (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id [SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 05:15:56.368463', '2020-10-10 05:15:57.007129', 'ad0f3d830ab711eb804c65bee10abc30', None, None)] (Background on this error at: http://sqlalche.me/e/13/gkpj)
    Error saving events: (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id [SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 05:45:36.675239', '2020-10-10 05:45:37.396345', 'd23483db0abb11eb81bfbb7efc8bf494', None, None)] (Background on this error at: http://sqlalche.me/e/13/gkpj)
    Error saving events: (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id [SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: (6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 06:15:54.677013', '2020-10-10 06:15:55.007904', '0dd18c6e0ac011eba055736aa9328bdb', None, None)] (Background on this error at: http://sqlalche.me/e/13/gkpj)

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
    self.dialect.do_execute(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
    cursor.execute(statement, parameters)
sqlite3.IntegrityError: UNIQUE constraint failed: events.event_id

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 442, in _commit_event_session_or_retry
    self._commit_event_session()
  File "/usr/src/homeassistant/homeassistant/components/recorder/__init__.py", line 493, in _commit_event_session
    self.event_session.flush()
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 2523, in flush
    self._flush(objects)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 2664, in _flush
    transaction.rollback(_capture_exception=True)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.raise_(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
    raise exception
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 2624, in _flush
    flush_context.execute()
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 419, in execute
    n.execute_aggregate(self, set_)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 521, in execute_aggregate
    self.execute(uow)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 586, in execute
    persistence.save_obj(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 239, in save_obj
    _emit_insert_statements(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 1083, in _emit_insert_statements
    c = cached_connections[connection].execute(statement, multiparams)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1011, in execute
    return meth(self, multiparams, params)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 298, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1124, in _execute_clauseelement
    ret = self._execute_context(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1316, in _execute_context
    self._handle_dbapi_exception(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1510, in _handle_dbapi_exception
    util.raise_(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 182, in raise_
    raise exception
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1276, in _execute_context
    self.dialect.do_execute(
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 593, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.IntegrityError: (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id
[SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)]
[parameters: (6312943, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:26.358410', '2020-10-10 02:13:28.848336', '2e5850ea0a9e11ebab89e72efd37a28f', None, None)]
(Background on this error at: http://sqlalche.me/e/13/gkpj

-----------
Logger: homeassistant.components.recorder.util
Source: components/recorder/util.py:106
Integration: Recorder (documentation, issues)
First occurred: 4:14:22 AM (3 occurrences)
Last logged: 4:14:22 AM

    Error executing query: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely) (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id [SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: ((6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:31.400829', '2020-10-10 02:13:35.767220', '3159bb900a9e11ebb30983dbf2517983', None, None), (6312943, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:26.358410', '2020-10-10 02:13:28.848336', '2e5850ea0a9e11ebab89e72efd37a28f', None, None))] (Background on this error at: http://sqlalche.me/e/13/gkpj)
    Error executing query: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely) (sqlite3.IntegrityError) UNIQUE constraint failed: events.event_id [SQL: INSERT INTO events (event_id, event_type, event_data, origin, time_fired, created, context_id, context_user_id, context_parent_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)] [parameters: ((6312944, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:31.400829', '2020-10-10 02:13:35.767220', '3159bb900a9e11ebb30983dbf2517983', None, None), (6312943, 'state_changed', '{}', 'LOCAL', '2020-10-10 02:13:26.358410', '2020-10-10 02:13:28.848336', '2e5850ea0a9e11ebab89e72efd37a28f', None, None))] (Background on this error at: http://sqlalche.me/e/13/gkpj) (Background on this error at: http://sqlalche.me/e/13/7s2a)
``
1 Like
1 Like

If so, it’s introduced again in 0.116.2 which I recently upgraded to.

Hi. Do you still experience problems in 116.2? I have the same problem with db stop working at 04:12.
Problem stared after upgrading to 116.0. Doing an uprgade to 116.2 right now, hope it will work