Looking for a front end solution to kick off a timer and add/subtract time to it while the timer is going. Couldn’t find one readily available, so I am trying to create my own quickly.
This seems to work just fine out of the developer tools>services
service: timer.start
target:
entity_id: timer.maddie_quiettime
data:
duration: >
{% set FinishDate = states.timer.maddie_quiettime.attributes.finishes_at %}
{% set RemainingRuntimeSeconds = as_timestamp(FinishDate) - now().timestamp() %}
00:00:{{ RemainingRuntimeSeconds | int + 120 | int}}
But when I try to incorporate it into the front end via custom button card, it throws an error when I try to (re)start the timer with a template to control duration.
Failed to call service timer/start. offset (% set FinishDate = states.timer.maddie_quiettime.attributes.finishes_at %} {% set RemainingRuntimeSeconds = as_timestamp(FinishDate) - now().timestamp() %) 00:00:({ RemainingRuntimeSeconds | int + 120 | int}} should be format ‘HH:MM’, ‘HH:MM:SS’ or 'HH:MM:SS.F for dictionary value @ data['duration]
It works as intended, and is somewhat elegant since I at least don’t need multiple helper scripts. But still feel like I shouldn’t need one at all. Still curious why its a formatting problem. Does custom button card really not allow for templating of actions?
It does seem to suggest that, but Custom button card doesn’t use Jinja templates, so you would need to figure out how to do it using the Javascript-style templating used in the card.
The closest thing to templated actions I have seen an example of is defining custom actions.
Most cards do not allow templating the actions. Even those that allow templating everywhere else rarely allow it for actions. There’s a custom feature for Tile cards that adds Jinja-like templating that I think can be used in the actions, but I haven’t played around with it much yet.
You are using button cards inside the button card and from my experience templating doesn’t work well on the stacked button (custom fields) The good news is the stacked card doesn’t necessarily need to be a button card. I use a Mushroom Chip card when in this scenario. For yours I used a Mushroom template card.