Try convert input number to time format

Hi, I use home assistant and try convert an input number to time format.
I can convert the number to minutes but I don’t succeed with the time.
I receive unknow to my timer_countdown_hour sensor.
Who can help me to correct my code?

my input_number variable is timer_countdown

- platform: template
    sensors:
     timer_int:
      value_template: "{{ states('input_number.timer_countdown') | int }}"
     timer_countdown_min:
      value_template: "{{ states('input_number.timer_countdown') | int %60}}"

    # what is the correct way to do this operation ?
     timer_countdown_hour:
      value_template: "{{ states('sensor.timer_int') - states('sensor.timer_countdown_min') / 60 }}"

What are you ultimately trying to do? I ask because your minutes and hours calculations (ignoring the syntax, etc. issues) don’t look right in the first place.

Thanks for your reply,
I want use a countdown timer that the user can choice how many minutes.
take the number and convert it to HH:MM.
I was searching and try multiple way but it’s not working, also I don’t exactly anderstand the syntax how use it :thinking:

adjust timer

Try:

{{ states('input_number.timer_countdown')|int|multiply(60)|timestamp_custom('%H:%M', false) }}
1 Like

Thanks it’s showing me the time.
I want use it to my timer, it’s possible to implement it to the timer configuration yaml?
like

timer:
  water_heater:
    duration: "{{states('sensor.timer_countdown_hour')}}:00"

No, you can’t use a template when configuring the timer. Also, BTW, the duration can be in seconds, or in one of many different formats (including HH:MM, HH:MM:SS, etc.)

What you would do is use input_number.timer_countdown when you start the timer using the timer.start service. E.g.:

- service: timer.start
  entity_id: timer.XXX
  data_template:
    duration:
      minutes: "{{ states('input_number.timer_countdown')|int }}"

No need to use a template sensor.

1 Like

Thanks :slight_smile:
It take me a few minutes to understand what to do.
It’s working

1 Like

I tried

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) }}"

but am getting error:

voluptuous.error.MultipleInvalid: offset {{ states('input_number.irrigation_set_time') | multiply(1) | timestamp_custom('%H:%M:%S',False) }} should be format 'HH:MM' or 'HH:MM:SS' for dictionary value @ data['duration']

I also tried:

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

but I get an error:

Failed to call service timer/start. expected int for dictionary value @ data['duration']['seconds']

When I run the template in the Template Editor I do get HH:MM:SS format and in the 2nd option an integer !?!?

What could me the problem?

Please post the entire automation or script.