Make traces persist longer, or make how long they last configurable

Really like using the trace functions to debug why things don’t work properly but the time they persist just doesn’t make it practical to use unless you are in front of the PC when the automation executes.

I’d like to be able to make the traces persist longer, even half hour would be great. At the moment I have a misbehaving automation that only runs when I arrive home (there are a lot more things than that) and it is not practical to re-create by simulating me leaving/arriving whilst in front of the PC.

By the time I get in the door, and get to the PC 2-3 minutes have elapsed, and by then, “Chosen trace is no longer available”. Haven’t managed to catch this automation once, the trace is always gone.

Currently only the last 4 or 5 traces are kept. But they are kept until HA is restarted.
There is a feature in the new release 2021.05 that allows you to configure the number of traces you want to keep (on a per automation)

Sounds good, thanks for the heads up. I’ve got a lot that run upon returning home so its probably being overwritten.

Was about to post a feature request for this too. How does one configure the number of saved traces?

I would like to know how to as well.

It was in one of the release notes, you are supposed to put this in the automation or script.

  trace:
      stored_traces: 1

I have however found it to be ineffective. The ‘show trace’ button simply doesnt show up when you look in the logbook.

Edit: it does work, just not how I expected.

The traces stored from the Automations tab in the Configuration page shows it storing traces of automations that both were and weren’t triggered due to the conditions not being met. I assume it would only store the successful executions not the failed ones. I’ve got automations that run based on every motion event in my house (so can be every few seconds), and only pass under very specific conditions (occurs maybe every few minutes). Explains why stored_traces = 10 would result in the successful execution being quickly deleted, as the failed ones are quickly replacing it and when I go and try and check the trace of a successful execution just minutes after execution, I get trace not found.

3 Likes

Seems like this is here now…
Is it working for everyone?

—> UPDATE…
It worked for me but after a HA Core Restart. Reloading automations didn’t do it. This was on an Automation Blueprint I use for my Magic cube. Those thing spits out abut 4 null triggers to get one good one, which the conditions screen, but they all cause traces.Now I have 10 to search thru for it. AWESOME!!

How do these things get closed?

I too have an automation that gets triggered frequently (once per minute) and my history of traces gets wiped out in a few minutes. I’m mainly concerned with SUCCESSFUL executions, but those are erased before I even have a chance to look at them.

Maybe store two categories of trace, both of which have a history. Success and Failure.

I guess this has since been implemented. I haven’t tried it yet, but it’s documented here: Troubleshooting Automations - Home Assistant

One work around for this is to have the time-based part of the automation call a script.

Then you get separate traces for the script.

But yeah it could certainly be a better user experience. Why is 5 the default even?

Related to this request - Home assistant seems happy to evict traces even if they are still running. This is very confusing if you have long-running automations (possibly by accident).

Conside this scenario:

  1. I write a duff automation than run every minute
  2. 15 minutes later light in my house comes on.
  3. I go into HASS, it says “tiggered by automation X”
  4. I look at the traces for automation X, but it just shows the last 5 minutes of traces where nothing happend.
  5. WTH?!?!

I’ve raised this as: Home assistant deletes traces from running automations · Issue #117133 · home-assistant/core · GitHub

Possible fixes:

  • Use a time based history (keep traces for up to 6 hours and in any case always keep the last 5)
  • Make the cache based on some sort of priority
  • Don’t trace very dull runs, or don’t count them towards the cache limit

Dull runs could be things such as “Stopped because only a single execution is allowed”, or runs that don’t get past “wait” steps.

[@emontnemery ] you seem to have written most of the trace stuff. Any thoughts on whether this is a reasonable issue? of if any of these fixes would be viable?

1 Like

You can adjust the number of traces, but perhaps this would be a good motivation to not write automations like that?

Obviously I’m not intending to write bad automations - but it happens! :smiley:

In my case I was simply trying to use the 2nd most popular blueprint on the exchange: Wake-up light alarm with sunrise effect

Seems like HASS could use a wait-trigger / run-this-continuously type pattern for automations - but that’s a separate issue.

1 Like

This use case is one where it starts to get a bit near ok to use time patterns. But for a wakeup light that is on for maybe half an hour (don’t know, just guessing) it is triggering uselessly for the other 23.5 hours.

The only thing I miss from my previous home automation system is a transition helper (quite similar to a timer helper). With that you can set up a repetition count and a duration. It is like a temporary time trigger, that you can set off when you want and ends when the sequence is done. It could also be an option on the current timer to send intermediate events.

I’d consider writing one myself, were it not I do not know Python yet. I lack the time to even get ready to start writing one, let alone support it the coming years.