Several Errors with Sensors in configurator.yaml

first time i set up Hass.io on a raspberry pie 4, and everything went great… i thought. then i saw the logs…
and they are filled with

Error executing query: (sqlite3.DatabaseError) database disk image is malformed [SQL: INSERT INTO events (event_type, event_data, origin, time_fired, created, context_id, context_user_id) VALUES (?, ?, ?, ?, ?, ?, ?)] [parameters: ('state_changed', '{"entity_id": "sensor.load_1m", "old_state": {"entity_id": "sensor.load_1m", "state": "0.1", "attributes": {"unit_of_measurement": " ", "friendly_nam ... (440 characters truncated) ... :00", "last_updated": "2020-01-22T19:40:57.017800+00:00", "context": {"id": "e899a311d1f4485c8ab190cef66d2310", "parent_id": null, "user_id": null}}}', 'LOCAL', '2020-01-22 19:40:57.017915', '2020-01-22 19:40:57.052834', 'e899a311d1f4485c8ab190cef66d2310', None)] (Background on this error at: http://sqlalche.me/e/4xp6)

8:40 PM components/recorder/util.py (ERROR)

Error saving event: <Event state_changed[L]: entity_id=sensor.memory_use, old_state=<state sensor.memory_use=325.9; unit_of_measurement=MiB, friendly_name=Memory use, icon=mdi:memory @ 2020-01-22T20:40:26.021472+01:00>, new_state=<state sensor.memory_use=325.1; unit_of_measurement=MiB, friendly_name=Memory use, icon=mdi:memory @ 2020-01-22T20:40:57.009903+01:00>>

8:40 PM components/recorder/__init__.py (ERROR)

Error executing query: (sqlite3.DatabaseError) database disk image is malformed [SQL: INSERT INTO events (event_type, event_data, origin, time_fired, created, context_id, context_user_id) VALUES (?, ?, ?, ?, ?, ?, ?)] [parameters: ('state_changed', '{"entity_id": "sensor.memory_use", "old_state": {"entity_id": "sensor.memory_use", "state": "325.9", "attributes": {"unit_of_measurement": "MiB", "fr ... (458 characters truncated) ... :00", "last_updated": "2020-01-22T19:40:57.009903+00:00", "context": {"id": "0f9d71c57ecc446fa1622838419337f6", "parent_id": null, "user_id": null}}}', 'LOCAL', '2020-01-22 19:40:57.010002', '2020-01-22 19:40:57.023599', '0f9d71c57ecc446fa1622838419337f6', None)] (Background on this error at: http://sqlalche.me/e/4xp6)

8:40 PM components/recorder/util.py (ERROR)

Error saving event: <Event state_changed[L]: entity_id=light.skafferi_2, old_state=<state light.skafferi_2=on; min_mireds=153, max_mireds=500, brightness=254, color_temp=366, friendly_name=skafferi, supported_features=43 @ 2020-01-22T20:37:31.080938+01:00>, new_state=<state light.skafferi_2=on; min_mireds=153, max_mireds=500, brightness=127, color_temp=366, friendly_name=skafferi, supported_features=43 @ 2020-01-22T20:37:31.080938+01:00>>

8:40 PM components/recorder/__init__.py (ERROR)

Error executing query: (sqlite3.DatabaseError) database disk image is malformed [SQL: INSERT INTO events (event_type, event_data, origin, time_fired, created, context_id, context_user_id) VALUES (?, ?, ?, ?, ?, ?, ?)] [parameters: ('state_changed', '{"entity_id": "light.skafferi_2", "old_state": {"entity_id": "light.skafferi_2", "state": "on", "attributes": {"min_mireds": 153, "max_mireds": 500, ... (545 characters truncated) ... :00", "last_updated": "2020-01-22T19:40:37.083629+00:00", "context": {"id": "48b1b315113341ffa923f89f67e2464c", "parent_id": null, "user_id": null}}}', 'LOCAL', '2020-01-22 19:40:37.083709', '2020-01-22 19:40:37.107232', '48b1b315113341ffa923f89f67e2464c', None)] (Background on this error at: http://sqlalche.me/e/4xp6)

i have sensors setup in configurator.yaml
and it looks like this

  - platform: systemmonitor
    resources:
      - type: disk_use_percent
        arg: /home
      - type: memory_free
      - type: memory_use
      - type: last_boot
      - type: processor_use
      - type: load_1m
      - type: swap_use
  - platform: command_line
    name: GPU Temperature
    command: "/opt/vc/bin/vcgencmd measure_temp"
    unit_of_measurement: "°C"
    value_template: '{{ value | replace("temp=", "") | replace("''C", "") }}'

    
  - platform: command_line
    name: CPU Temperature
    command: "cat /sys/class/thermal/thermal_zone0/temp"
    unit_of_measurement: "°C"
    value_template: '{{ value | multiply(0.001) | round(1) }}' 

don’t know what is wrong, and what is what really… i tried to take away all sensors, but that gave me problem reaching home assistant with cloud service…

Delete the database (home-assistant_v2.db) in your configuration directory and restart Home Assistant.

that worked great! thank you!
still learning, what was with that file?

The database stores all the state history for your entities. Sometimes, particularly with SQLite (the default database backend) the database becomes corrupted and prints those errors in the log. Would be a good idea to consider switching database backends (one example would be by using the MariaDB addon).

You should also consider setting up a whitelist/blacklist for the recorder integration to limit what history is actually recorded to the database:

The default is to record all history for all entities in a rolling 10-day window. Depending on how many entities you have (and how “chatty” they are), the database can grow to a pretty ridiculous size with the default settings.

1 Like