Displaying "last_triggered" in minutes

I am trying to set up a conditional card that only shows up if my TV timer script is running and shows how many minutes are left on the timer. Everything is working perfectly fine, except the “last-triggered” attribute unhelpfully shows the full date and time of the last trigger ( think November 21, 2023, 8:09:17). Most infuriating is that when you actually click on the script entity, it shows the “last_triggered” attribute in the “minutes ago” format instead of this monstrosity that shows up on the dashboard.

Anybody have any idea if it is possible to convert the unit so it shows how many minutes ago this happened? I tried various workarounds involving creating new and different kinds of helpers, but no luck so far.

Code:

cards:

  • type: conditional
    conditions:
    • condition: state
      entity: script.tv_timer_30m
      state: ‘on’
      card:
      type: entity
      entity: script.tv_timer_30m
      name: TV Timer Is On
      attribute: last_triggered

Front end converts it into readable value so sometimes you see it as last triggered in 2 seconds ago sometimes it is hours, so depends on the value.

If you are just interested in minutes without dynamic approach, you can define a template;

{{ (now() - state_attr('automation.time_dependents', 'last_triggered')).total_seconds()/60 }}

Please be sure that you automation has been triggered once other way around this will fail

1 Like