Timer event for Light Transition - Time format conversion

Hello,

I would like to use timers (the value of the duration) as input for my lights transition. As such, I can have visual feedback with one of the multiple cards in the GUI of the time my Automation will still be running.
The challenge is that the timer.duration has the format H:MM:SS while the Lights Transition requires a value in seconds (integer).

I can easily capture the value of the Timer in a variable with:

{% set var_timerduration = state_attr('timer.sleep_routine_living_room_duration_timer','duration') %}

but can seem to use this value in the Light Turn of Transition.

- service: light.turn_off
    data:
      transition: var_timerduration
    target:
      entity_id:
        - light.living_room_lights

Anybody a tip to transform this variable in seconds?

  - service: light.turn_off
    data:
      transition: "{{ (state_attr('timer.sleep_routine_living_room_duration_timer', 'duration') | as_timedelta).total_seconds() }}"
    target:
      entity_id:
        - light.living_room_lights

That works, thank you!

1 Like

Thank you again for this tip! Still trying to fully understand time conversions in yaml but this has opened quite some new possibilities for me.