Need help with data template

I am creating a script that will add ‘n’ seconds to a timer. I am passing these variables so that I can make use of this script in my automation. But it is not working. Can someone help? Thanks in advance.

alias: Add to Timer
mode: single
icon: mdi:camera-timer
fields:
  timername:
    description: Timer to Add to
  addseconds:
    description: Seconds to Add
sequence:
  - service: timer.pause
    data_template:
      entity_id: "{{ timername }}"
  - service: timer.start
    data_template:
      duration: >-
        {% set r = "{{ state_attr(timername, 'remaining') ~ '-0000' }}" %} {%
        set t = strptime(r, '%H:%M:%S%f%z') %} {{ (as_timestamp(t) + addseconds)
        | timestamp_custom('%H:%M:%S', false) }}
      entity_id: "{{ timername }}"

Error:
Failed to call service script.add_to_timer. Error rendering data template: ValueError: Template error: strptime got invalid input ‘{{ state_attr(timername, ‘remaining’) ~ ‘-0000’ }}’ when rendering template ‘{% set r = “{{ state_attr(timername, ‘remaining’) ~ ‘-0000’ }}” %} {% set t = strptime(r, ‘%H:%M:%S%f%z’) %} {{ (as_timestamp(t) + addseconds) | timestamp_custom(’%H:%M:%S’, false) }}’ but no default was specified

Well you set r to the literal string {{ state_attr(timername, 'remaining') ~ '-0000' }}. And then yea when you asked it to parse the date time value out it yelled at you because that string is definitely not a timestamp.

I think you meant to do this to set r?

{% set r = state_attr(timername, 'remaining') ~ '-0000' %} 

Just get rid of the extra double brackets and quotes in there, it makes sense otherwise.

Also just an FYI you can just put data. You haven’t needed to use data_template to use a template for about 2 years (since this 2020 WTH)

1 Like

Thanks, that fixed it.