Converting Timestamp

Hi!
I’m trying to get my Alexa telling me the remaining time of my washing mashine’s job.
So far i did this as a script:

data_template:
  target:
    - " {%- for group in states.media_player | groupby('state') -%} {%- for entity in group.list -%} {%- if is_state_attr(entity.entity_id, 'last_called', true) %} {{ entity.entity_id }} {%- endif -%} {%- endfor -%} {%- endfor -%}"
  data:
    type: tts
    method: speak
  message: >
    {% set alexa_text_vor = [ "Die Waschmaschine dauert noch ",
                          "Die Waschmaschine braucht noch  ", 
                          "Die Waschmaschine läuft noch " ] | random %}
    {% set alexa_text_nach = [ "bis sie fertig ist.",
                          ".", 
                          "und meldet sich dann" ] | random %}
    {{ '{} {} {}'.format( alexa_text_vor,
    states('sensor.waschmaschine_washer_completion_time'), alexa_text_nach ) }} 
action: notify.alexa_media

Which returns 2025-10-25T13:42:21+00:00 e.g.

All i want is getting back the remaining time like “1 hour and 25 minutes left”.

Any ideas?

Thanks in advance!

Assuming it is localized… you can use the time_until() function.

data_template:
  target:
    - " {%- for group in states.media_player | groupby('state') -%} {%- for entity in group.list -%} {%- if is_state_attr(entity.entity_id, 'last_called', true) %} {{ entity.entity_id }} {%- endif -%} {%- endfor -%} {%- endfor -%}"
  data:
    type: tts
    method: speak
  message: >
    {% set alexa_text_vor = [ "Die Waschmaschine dauert noch ",
                          "Die Waschmaschine braucht noch  ", 
                          "Die Waschmaschine läuft noch " ] | random %}
    {% set alexa_text_nach = [ "bis sie fertig ist.",
                          ".", 
                          "und meldet sich dann" ] | random %}
    {% set until = time_until(as_datetime(states('sensor.waschmaschine_washer_completion_time')), 2) %}
    {{ '{} {} {}'.format( alexa_text_vor, until, alexa_text_nach ) }} 
action: notify.alexa_media
1 Like

Thanks for this solution!