Tell me via TTS when last motion was detected

Hi there, I am trying to have TTS service telling me when a last motion was detected.
I followed this suggestion Trigger TTS on motion and tell me how long since last (previous) motion was detected.
So I added this to the configuration.yaml

input_datetime:
last_motion:
name: last_motion
has_date: true
has_time: true

Entity “last_motion” shows me the correct information like 26 minutes ago with the date and year.
But when I ask the TTS service in my automation:

message: Last motion detected {{ state_attr(‘input_datetime.last_motion’, ‘timestamp’) }} ago
or
message: Last motion detected {{ relative_time(state_attr(‘input_datetime.last_motion’, ‘timestamp’)) }} ago

It tells me: 1678868604.01628 which I believe is the unix timestap.
I’m stuck here, don’t know how to translate this to xx minutes or hours ago
Read through similar posts here but still can’t figure it out.

Try this for a time with no date:

message: "Last motion detected {{ today_at(state('input_datetime.last_motion'))|relative_time }} ago."

Or this for a time with a date:

message: "Last motion detected {{ states('input_datetime.last_motion')|as_datetime|relative_time }} ago."

thanks a lot Tom

the first one gives me an error: Error rendering data template: UndefinedError: ‘state’ is undefined
where as the second works, its tells me 29 minutes ago but no date. Can live with that, thanks again