Template in lovelace to start timer

Hello everyone, some time ago the button in Lovelace worked for me, but it seems something went wrong with the latest updates and now I see an error when executing it

          - type: custom:button-card
            entity: timer.socket_1
            name: timer
            tap_action:
              action: call-service
              service_data:
                entity_id: timer.socket_1
              service: timer.start
              data:
                duration: 00:{{ states.input_number.socket_1_timer.state | int }}:00

Failed to call service timer/start. offset 00:{{ states.input_number.socket_1_timer.state | int }}:00 should be format 'HH:MM', 'HH:MM:SS' or 'HH:MM:SS.F' for dictionary value @ data['duration']

The same template works fine in Automations or Developer tools

action:
      - service: timer.start
        data:
          duration: 00:{{ states.input_number.socket_1_timer.state | int }}:00
        target:
          entity_id: timer.socket_1

Can anyone help me to find a mistake?

Templates are not supported in card actions, move your templating/logic to a script and call the script from the card action.

EDIT: See Below

True for core cards but it’s a custom card.

From memory the custom button card uses JavaScriot, not jinja.

Edit: yeah it has to be JavaScript, https://github.com/custom-cards/button-card#templates-support and I’m still not certain if the action supports it.

Thank you! I found the solution through simple automation rule after start timer

            tap_action:
              action: call-service
              service: timer.start
              data:
                entity_id: timer.socket_1
alias: "timer"
trigger:
  - platform: event
    event_type: timer.started
    event_data:
      entity_id: timer.socket_1
condition: []
action:
      - service: timer.start
        data:
          duration: 00:{{ states.input_number.socket_1_timer.state | int }}:00
        target:
          entity_id: timer.socket_1
mode: single

Thanks Tom, I had scrolled down just far enough that the type: line was not visible… :man_facepalming:

Custom Button does allow templates in actions:

image

You do have to use the annoying JS templates as mentioned. The templates seem to do some kind of auto-conversion for numeric states, but it will work as follows:

type: custom:button-card
entity: timer.socket_1
name: timer
tap_action:
  action: call-service
  service: timer.start
  service_data:
    entity_id: timer.socket_1
    duration: >
      [[[ return `00:${Math.floor(states['input_number.socket_1_timer'].state)}:00`;]]]
1 Like