Trigger automation based on defined error in system log file

Hello together,

from time to time I have some errors in my system log file where I do not know if it is related really to the DB or if it is an disk error.
I wan’t to do a backup of my log file. This is working.
I have implemented this for a real shutdown, but when just crashing I have currently no solution when the UI is not responding. So I wan’t to backup in front.

But I was wondering if I can create a trigger in the automation when something is found in the system log file:

For example the “sqlite3” error in the description?

Thanks!

The log file is backed up on restart of HA.

Where can I find it?
All 3 log files which are available are always empty after a restart.

As mentioned I implemented a shell script for doing the backup to a different folder which is running fine.

I only need an trigger for an error in the log itself.

Or if it is backed up, I need to know where the backup logfile is placed.

Thanks.

Command-line sensor, where the command is something like:

grep -c "disk image is malformed" /config/home-assistant.log

Then your automation would trigger on a change to the state of that sensor, and send a notification if it increases:

trigger:
  - platform: state
    entity_id: sensor.disk_error_count
condition:
  - "{{ (trigger.to_state.state)|int(0) > (trigger.from_state.state)|int(0) }}"
action:
  # send the notification
1 Like

home-assistant.log becomes home-assistant.log.1

1 Like

@Troon Thanks for the code, I will try in addition.
@nickrout Thanks for the hint, I will check again, I am not pretty sure if this is also the case when there will be a crash.

This may be useful. In the 2024 version of HA Core, I use the following automation to restart an integration when a certain error pops up (search for the integration entity_id in the file .storage/core.config_entries in the config directory:

- alias: "91004 - Samsung FamilyHub Integration error"
  trigger:
    platform: event
    event_type: system_log_event
    event_data:
      level: ERROR
      logger: custom_components.samsung_familyhub_fridge.api
  condition:
    condition: template
    value_template: '{{ "Unexpected error fetching File ID refresher data:" in trigger.event.data.message[0] }}'
  action:
    service: homeassistant.reload_config_entry
    data:
      entry_id: ***