Automation based on log

I have tried a couple approaches to scrape log as an automation trigger. Neither seem to fire any pointers would be appreciated.
`

id: '1631227541159'

  alias: Zwave  Issue Notify (Duplicate)

  description: ''

  trigger:

  - platform: event

    event_type: system_log_event

  condition:

  - condition: template

    value_template: '''{{ "zwave_js_server.exceptions.Failed" in trigger.event.data.message[0]

      }}'''

  action:

  - service: notify.notifier_telegram

    data:

      message: Zwave Error 2

  mode: single'

`

- id: '1631313071772'

  alias: 'Zwave  Issue Notify2 '

  description: ''

  trigger:

  - platform: event

    event_type: system_log_event

    event_data:

      name: 'homeassistant.components.zwave_js:'

      level: ERROR

  condition: []

  action:

  - service: notify.notifier_telegram

    data:

      message: 'Zwave  Issue Notify2 '

  mode: single

Try this:

alias: example 555
trigger:
- platform: event
  event_type: system_log_event
condition: '{{ "zwave_js_server.exceptions.Failed" in trigger.event.data.exception }}'
action:
- service: notify.notifier_telegram
  data:
    message: 'Zwave Error 2'

Thanks that is not triggered either - I simplified to “Error” to get more hits fro CLI

grep -c “Error” /root/config/home-assistant.log

returns but nothing triggered

Did you configure the System Log integration to fire events?

fire_event string (Optional, default: false)

Whether events are fired (required when used for triggers).

I’m missing something here

system_log:
  fire_event: true
logger:
  default: info
  logs:
    zwave_js_server: error
    homeassistant.components.zwave_js: error

but the automation is still not firing.



- id: "1631466803658"

  alias: error  Notify (Duplicate) (Duplicate)

  description: ""

  trigger:

    - platform: event

      event_type: system_log_event

  condition:

    - condition: template

      value_template: '''{{ "Error" in trigger.event.data.exception }}'''

  action:

    - service: notify.notifier_telegram

      data:

        message: HA Error msg data

  mode: single

If you just added fire_event: true to configuration.yaml don’t forget that you have to restart Home Assistant to register the change you made.

Here’s an experiment I performed and you might want to try in order to confirm that the events are being generated.

Open two browser tabs, each one connected to your Home Assistant instance.

In one tab, go to Developer Tools > Events, enter system_log_event in “Event to subscribe to” then click “Listen to events”.

In the other tab, go to Developer Tools > Services, select “System Log: Write”, enter some text in “Message”, enable “Level”, select “error”, then click “Call Service”.

Switch back to the other tab and confirm that it displayed the details of the event like shown below:

In this example, you’ll notice the message I created is not in exception but in message. So if I wanted an automation’s action to check the event’s details, it would need to inspect trigger.event.data.message[0].

condition: "{{ 'testing' in trigger.event.data.message[0] }}"

In your case, it’s unclear to me where your zwave error message will be (in exception or in message) but if exception didn’t work then try message[0].

2 Likes

Thank you. This was super helpful - creating and recieving events via log is working fine.

Glad to hear it’s resolved.

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been solved. It helps users find answers to similar questions. For more information refer to guideline 21 in the FAQ.

Thanks for the help - final step for me was call with the quotes in the trigger condition - hard to test as manual operation skips the trigger + condition

Hi,

Just a question:
How to show debug logs after setting fire_event to true.

My response here might be useful: Trigger automation based on defined error in system log file - #7 by dajomas