Tracing entity state change back to triggering automation / script

So, occasionally, I encounter seemingly contradictory automation scenarios, where one light is turned off, and another turns it back on for an unexplained reason. I’m wondering if there’s a way to view the history of an entity with the entity or action that cause a state change so I can maybe trace it back to the automation/script name that may have triggered it. I am envisioning something along the lines of a reverse breadcrumb-like feature from the entity history view , but I’m open to any database query-based solution that achieves a similar effect. Any suggestions or guidance would be greatly appreciated.

Hi John Dyer,

Just checking, but you do realize that all automations and scripts store the last 5 traces that ran so you can see what happened. That number of 5 is a default, you can increase that on a script or automation if you need to.Also you can list scripts and automations in the order they ran, so if something odd happens, you can look at the one(s) that just ran.

I think he wants to work back from the other end.

The entity log book isn’t as helpful as it might be:

The top entry here contains loads of information; the third entry - well I can’t make head or tail of it. What actually happened was… someone spoke a custom sentence to the voice assistant and an intent turned on the socket. :thinking:

I get that, but was just making sure they knew about the traces. Sometimes the things some take for granted are missed by others and if it was initiated be an automation as they suspect, that might help track it down.