Hi, I’m struggling to identify the correct YAML syntax in a service timer.start block to set the duration from an input_datetime entity.
I’ve read all the related Documentation pages and searched the Community items, but not yet found the solution. I’ve tried using:
A)
which results in the error “Stopped because an error … offset input_datetime.test_time should be format ‘HH:MM’, ‘HH:MM:SS’ or ‘HH:MM:SS.F’ for dictionary value @ data[‘duration’]”
B) as A) but with duration line > duration: “{{input_datetime.test_time}}”
resulting in “Error rendering data template: Undefined error: ‘input_datetime’ is undefined”
C) as A) but with > duration: “{{ ‘input_datetime.test_time’ }}”
results in error same as A).
What is the correct YAML syntax to use for setting the duration from an input_datetime?
This is how I have done it for a bathroom fan: I have set it to 180 seconds but you could use an input number. Datetime will contain the string containing a time, date or date and time but is not a duration.
- id: '1612134477709'
alias: Half Bath Timer Activation
description: Activate the timer for the half bath
trigger:
- platform: state
entity_id: switch.half_bath_light
from: 'off'
to: 'on'
condition: []
action:
- service: timer.start
data:
duration: '180'
target:
entity_id: timer.halfbath_timer
mode: single
- id: 'Half Bath Fan Run'
alias: Half Bath Fan Run
description: Turn on Half bath fan if light was turned after after being on for
at least 3 minutes
trigger:
- platform: state
entity_id: switch.half_bath_light
from: 'on'
to: 'off'
condition:
- condition: state
entity_id: timer.halfbath_timer
state: idle
action:
- service: switch.turn_on
target:
entity_id: switch.half_bath_fan
- delay:
seconds: "{{ states('input_number.fan_runtime')| int(30) }}"
- service: switch.turn_off
target:
entity_id: switch.half_bath_fan
mode: single
The first starts a timer and the second automation turns on the fan if the timer is at or below 0.
Hi, and thanks for replying.
Your first part, as you say, uses "duration: ‘180’ ". I’ve tried it with the ‘180’ replaced by an input_number, but that still fails - seems to want something giving format ‘HH:MM’, ‘HH:MM:SS’.
An input_datetime with a Time value ought to be a duration, since it’s a ‘HH:MM:SS’ value.
Seems I’m missing the correct formatting syntax.
I don’t understand the jinja parts, if that’s what’s needed, and what {{ states(…) }} is doing. Cannot find that documented in HA Docs so far.
Somehow this as well as similar solutions just aren’t working for me. I keep getting the “Failed to call service timer/start. offset {{ states(‘input_datetime.aquarium_small_timer_input’) }} should be format ‘HH:MM’, ‘HH:MM:SS’ or ‘HH:MM:SS.F’ for dictionary value @ data[‘duration’]” error message even doing (as far as I know) exactly what @Didgeridrew described.
This is the code for the button that I’m trying to use to start the timer.
The issue is that you are trying to use templating in the action block of a Dashboard card. Most core cards do not accept templating at all, and even custom cards that do accept templating, often do not allow it in actions. The most reliable workaround is to move your action with templated logic into a script, then have the button action call the script.
There is also a relatively new custom feature for Tile cards that adds service calls and allows templating… you may be able to use that, but I haven’t experimented with it much yet.