#Use button to either start or extend a timer

1 messages · Page 1 of 1 (latest)

torpid siren
#

Hi, I want to implement a button that either starts a timer with 15 min, or will extend it by another 15 min, if it is already running.
I tested it out in the template playground, but can't get it to work on the dashboard.

show_name: true
show_icon: true
type: button
entity: timer.luftungstufe3
name: Verlängere Stufe 3 um 15 min
tap_action:
action: perform-action
perform_action: timer.start
data:
duration: >-
{%- if is_state("timer.luftungstufe3","active") -%}{{-
(as_datetime(state_attr("timer.luftungstufe3","finishes_at")) - now() +
timedelta(minutes=15.0) ).total_seconds() | timestamp_custom("%H:%M:%S",
false) -}}{%- else -%}"00:15:00"{%- endif -%}
target:
entity_id: timer.luftungstufe3
This will just result in
{
"code": "invalid_format",
"message": "offset {%- if is_state("timer.luftungstufe3","active") -%}{{- (as_datetime(state_attr("timer.luftungstufe3","finishes_at")) - now() + timedelta(minutes=15.0) ).total_seconds() | timestamp_custom("%H:%M:%S", false) -}}{%- else -%}"00:15:00"{%- endif -%} should be format 'HH:MM', 'HH:MM:SS' or 'HH:MM:SS.F' for dictionary value @ data['duration']"
}
Above duration validates to "00:15:00" (not active) | "00:29:33" (active with 14:33 remaning) just fine as template!
But I can't even put {{ "00:15:00" }} there. It is all failing.

Any ideas?

nocturne token
#

Call a script from the tap action instead. Templates are not supported in actions by the frontend. https://community.home-assistant.io/t/using-template-value-in-action-data-not-working/922315/1

plush spear
#

Similar question posted here: https://discord.com/channels/330944238910963714/1500701099768811560
Also,

The timer.start action starts or restarts a timer with the provided duration. If no duration is given, it will either restart with its initial value, or continue a paused timer with the remaining duration. If a new duration is provided, this will be the duration for the timer until it finishes or is canceled, which then will reset the duration back to the original configured value.
Adding time to an already running timer is tricky but it looks like your template would work. (Just not within a Button card.) You can probably make it work with a custom:button-card but you would have to rewrite the template in JavaScript instead of Jinja.