The problem is that something is wrong in the transition from string to datetime.
I don’t have the date part so I only used the time part in the template: ‘%H:%M:%S.%f’
now()- state_attr('automation.008', 'last_triggered') returns a timedelta object, not a time string. If you want a string you have to add a string filter.
Then you could just use string slicing to remove the milliseconds.
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 :.