Template with different Text from remaining time

Hello,
hope i´m right and the topic is ok:

I´m using this template for my remaining time from my washer sensor as a TTS message:

    {% set ct = states('sensor.waschmaschine_washer_completion_time') |    
    as_datetime %}
    {{ 'Gerät ist ausgeschaltet' if now() > ct 
   else
   (ct - now()).total_seconds() | timestamp_custom('Die Waschmaschine ist in %-H    
    Stunden und %-M Minuten fertig.', false) }}

It works, but i need something like that:

if (ct - now()).total_seconds() < 2-H| timestamp_custom('Die Waschmaschine ist in %-H Stunde und %-M Minuten fertig.', false) }}
if (ct - now()).total_seconds() < 1-H| timestamp_custom('Die Waschmaschine ist in %-M Minuten fertig.', false) }}

If its under 2 hours the template will show “Stunde” instead “Stunden” and if its unter 1 hour only the minutes should shown.

Can somebody help me with it?

{% set ct = states('sensor.waschmaschine_washer_completion_time') | as_datetime %}
{% if now() > ct %}
  Gerät ist ausgeschaltet
{% else %}
  {% set t = (ct - now()).total_seconds() %}
  {% set msg = 
    { t >= 7200: '%-H Stunden und %-M',
      3600 <= t < 7200: '%-H Stund und %-M',
      t < 3600: '%-M' } %}
  Die Waschmaschine ist in {{ t | timestamp_custom(msg.get(true), false) }} Minuten fertig.
{% endif %}

EDIT

Correction. Added missing ( to calculation for the variable named t.

thank you, there is an error with t = ct - now()), missed an ( before ct

1 Like