Time and date templates can get complicated quickly since there are so many ways the information is represented. It’s easy to lose sight of the goal and end up with something that kind-of works but is overly complicated or has a failure case that isn’t obvious at first.
If you just need a string in “HH_MM_SS" format, you could just do what I already proposed above with the addition of a replace()
to swap _
for the existing :
.
{{ ((now()- state_attr('automation.008', 'last_triggered')) | string).split('.')[0] | replace(':','_') }}
There are some great time-related macro collections available that can make coversions easier:
Easy Time Macros
Relative Time Plus
And there’s always the Epic Time Conversion Thread.