Template for timer

Brief description of device or service

Option to template the Home Assistant timer service.

This does not seem to be possible at the moment. I started this topic in September, but so far, me and other community members did not find a satisfying solution for this.

Example

input_datetime:
  set_timer:
    name: "[Test] Zeit"
    has_date: false
    has_time: true

timer:
  template_timer:
    duration: "{{ states('input_datetime.set_timer').split(':')[0] | int }}:{{ states('input_datetime.set_timer').split(':')[1] | int }}:00"

When I set set_timer to 3:20, the equivalent to duration will be 3:20:00; this should be valied for a timer, correct? However, it does not work.

The workaround I have found is pretty disappointing: I create an input_select for different times (current one has times in 15 minutes intervals from 00:15:00 to 03:45:00). This works, but it is not very flexible).

automation:
  alias: What's wrong with this
  trigger:
    platform: state 
    entity_id: input_boolean.WHATEVER
    to: 'on' 
  action:
    service: timer.start
    data_template:
      entity_id: timer.WHATEVER
      duration: "{{ states('input_datetime.set_timer').split(':')[0] | int }}:{{ states('input_datetime.set_timer').split(':')[1] | int }}:00"

?

1 Like

Thank you! That solution works perfectly.

1 Like