Detecting logged errors

I’d like to trigger an automation when these system logs are reported by the DashCast integration. The automation will restart DashCast. Is that trigger possible?

2025-08-18 04:10:55.010 INFO (MainThread) [pychromecast.controllers] Receiver:Launching app 84912283
2025-08-18 04:10:55.010 INFO (MainThread) [homeassistant.components.script.nest_hub_2_cast] nest_hub_2_cast: Executing step call service
2025-08-18 04:10:55.010 INFO (MainThread) [homeassistant.components.script.nest_hub_2_cast] nest_hub_2_cast: Executing step call service
2025-08-18 04:10:55.011 WARNING (Thread-13) [pychromecast.socket_client] [(192.168.11.102):8009] Error writing to socket: [SSL: BAD_LENGTH] bad length (_ssl.c:2493)
2025-08-18 04:10:55.017 INFO (Thread-13) [pychromecast.controllers] Receiver:channel_disconnected

DashCast doesn’t report the error in any normal way (details here). The only reporting I can find is the logs.

You can use a command line sensor to check the log file, unfortunately that does a full scan of the file each time however - there may be more elegant solutions -

Assuming that you have a log file. Those have been removed and shenanigans are required to have one now.

1 Like

Petro have made a custom integration that recreates the log file feature.

It should then probably be possible to run a script with the tail command on it.

Thanks so much, @KruseLuds ! Below is the core of my solution.

When I start DashCast, I turn_on the switch.nest_hub_2_socket_state. That runs the full scan and stores the result in a small temp file. When the scan completes, HA updates the new switch state using the contents of the temp file: if the logs show a successful start then the switch becomes on, otherwise off. If the switch is off then I kill DashCast and start it again.

command_line:
  - switch:
      name: nest_hub_2_socket_state
      command_on: >
        grep -v components.command_line home-assistant.log | grep -A 1 'nest_hub_2_cast: Executing step call service' | tail -2 > /tmp/dashcast-nest_hub_2.log
#      command_off: >
#        grep -v components.command_line home-assistant.log | grep -A 1 'nest_hub_2_cast: Executing step call service' | tail -2 > /tmp/dashcast-nest_hub_2.log
      # Expect one line, the Executing line. If there's no Executing line then we haven't
      # started DashCast since the last restart. If there's a BAD_LENGTH line then we
      # started DashCast and it failed to start successfully. Either way, switch is off.
      command_state: >
        if [ $((`grep -E '(nest_hub_2_cast: Executing|BAD_LENGTH)' /tmp/dashcast-nest_hub_2.log | wc -l`)) != 1 ]; then exit 127; fi
      scan_interval: 3600  # HA updates the switch on turn_on. Don't really need further updates.

@Sir_Goodenough , I think you’re trying to give me a hint but it was a little too oblique.

In what way have log files been removed? I’m not on the very latest HA version. Is this a recent change?

It’s been replaced…

I’m not sure if this is what you’re after, but if you set fire_event: true under the system_log integration, you can then use log entries as event triggers in automations.

I assume this still works for 2025.11 as the documentation for this feature is still there.

1 Like

I see nobody responded to your other thread.

Why shouldn’t the subroutine that logs the error code not check for it and take the appropriate option? By the time it has been logged it is too late.

Can you check the length beforehand?

Are we fixing the wrong problem?

Thanks @reste_narquois . This looked great but it has a big caveat. It only triggers on errors and warnings and my logs are info level.

From the docs you linked, “Errors and warnings are posted as the event system_log_event…” and “level: Either WARNING or ERROR depending on severity.” (yes, they could have been more forthcoming about “no info logs”.)

My experiments agree with the docs. I could capture errors but not info level logs.

1 Like