Error when configuring timing duration using template

I am trying to use a the timer.start service in a script. The duration should be configured using an input.number entity “irrigation_set_time”.

  • I tried using both the time format HH:MM:SS and the seconds - both return errors.

HH:MM:SS code:

service: timer.start
data_template:
        entity_id: irrigation_timer_cycle_duration
        duration: "{{ states('input_number.irrigation_set_time') | int | timestamp_custom('%H:%M:%S',false) }}"

error:

Failed to call service timer/start. offset {{ states('input_number.irrigation_set_time') | int | timestamp_custom('%H:%M:%S',False) }} should be format 'HH:MM' or 'HH:MM:SS' for dictionary value @ data['duration']

Integer code:

service: timer.start
data_template:
  entity_id: irrigation_timer_cycle_duration
  duration:
    seconds: "{{ states('input_number.irrigation_set_time') | int }}"

error:

Failed to call service timer/start. expected int for dictionary value @ data['duration']['seconds']
  • The same errors appear when I run the service and data_template using the “Service” menu in “Development Tools”.
  • I tried the template {{ }} code in “Template Editor” (under “Development Tools”) and it returned the correct format in both cases (HH:MM:SS format and integer respectivley)

What is puzzling it that I tried running the same HH:MM:SS code using the delay function and it worked OK.

delay: "{{ states('input_number.irrigation_set_time') | int | timestamp_custom('%H:%M:%S',false) }}"

What could me the problem? Using latest HA 0.108.3

Your entity_id is wrong in all your attempts.

You’re missing the domain

Also, what units is your input_number? Minutes? Seconds?

Sorry, the extracted code was from older codes (where I did indeed get the entity_id error).
The entity_id is correct

timer.irrigation_timer_cycle_duration

the units from the input.number are seconds.
As I wrote when using delay the convertion works.

try this then, duration can be the duration in seconds or the “HH:MM:SS” notation. Your first template should have worked. But if it’s not, this should.

service: timer.start
data_template:
  entity_id: timer.irrigation_timer_cycle_duration
  duration: "{{ states('input_number.irrigation_set_time') | int }}"

Tried it again using the Development Tool/Service.
Getting the same error - expecting time format

image

Failed to call service timer/start. offset {{ states('input_number.irrigation_set_time') | int | timestamp_custom('%H:%M:%S',False) }} should be format 'HH:MM' or 'HH:MM:SS' for dictionary value @ data['duration']

If I put an integer number (for example 60) instead of the template it works.

You can’t template in the development tool/service. It only accepts data. If this is what you have been doing, this would be your problem.

EDIT: To clarify, you can only do live tests with templates or the template editor.

Screen Shot 2020-04-14 at 17.14.29 (2)

Message for notifications of all types goes through different code than a normal attribute. I thought I unsubscribed to your chirping?

Maybe you should open a Feature Request for this?

1 Like

The friendliest community, I see.

I wouldn’t be this way if you didn’t continuously do this. There was no reason to make that post. Any veteran here knows that the message field accepts templates the data or data_template field. It’s the exception to the rule. So why even bring it up? All it’s going to do is confuse beginners. But noooo, that’s not the @AhmadK way. He needs to belittle people at every corner whenever he can. Now do you understand why I have such a disdain for you?

I consider many here to be friends, there are also people who are unknown yet who help regardless, all in all most are worthy of my respect and gratitude.
Though my Venn diagram is far from complete.