History API and automation trigger times

I use the History API ( /api/history/period) in one of my custom cards (home-feed-card) to allow the the history of an entity to be displayed in the feed. I am trying to add support for the triggered time of automations (last_triggered) attribute. This works fine when not using the history but, when the history is used, the History API only seems to include updates to the automation, which affect the last_changed attribute. Is there any way to get a list of all the times an automation was triggered either from the History API or from some other API?

1 Like

I had the same issue. Turns out I could get what I needed from /api/logbook. Load up the logbook page in the UI and play around with the params with dev tools on and you can see how to use it.

I am also having the same issues, though for all objects in HASS. The last_changed and last_updated timestamps are both equal to the time I specify in the API call.

For example if I make a call to this:

/api/history/period/2020-02-04T22:41:00

all timestamps in the returned JSON are 22:41:00. If I call /states however, the timestamps are correct. What gives?!

Welcome @DingosKidneys - do you have any links to the logbook API endpoint? The logbook times out for me when I try to load it in the UI.

Sure.

/api/logbook/2020-02-04T22:41:00?period=30&entity=automation

I don’t know how stable or official that endpoint is. It would be better if we could use the history api. But it worked for me for now.

The problem I found with that is that the entity filtering doesn’t really work as expected. Looking at the code, it applies the entity filter only to items in the logbook where last_updated is the same as last_changed (which isn’t the case with automations) and also includes all items with a null state id (which includes automations) regardless of the filter. This means that you can’t just filter the logbook to return just a single automation without pulling the all the data and then filtering afterwards (which can be quite slow).