ESPhome Number as Timer

previously I use the delay as a timer, every time I need to adjust this timer should upload new firmware like this

substitutions:
 Timer: "3min"

binary_sensor:
  - platform: template
    id: "Timer_OK"
    on_release:
      then:
        - binary_sensor.template.publish:
            id: "Timer_OK"
            state: OFF
        - delay: "$Timer"
        - binary_sensor.template.publish:
            id: "Timer_OK"
            state: ON

now I try to use number to adjust this timer

number:
  - platform: template
    name: "$DeviceName Timer"
    id: "Timer"
    optimistic: true
    restore_value: true
    min_value: 0
    max_value: 10
    step: 1
    lambda:

but I don’t have any idea how to link number value as time in minutes

like when select 1 mean 1min in dealy

thanks

Remove the substitution, replace it with a lambda call in your binary sensor action:

binary_sensor:
  - platform: template
    id: "Timer_OK"
    on_release:
      then:
        - binary_sensor.template.publish:
            id: "Timer_OK"
            state: OFF
        - delay: !lambda "return id(Timer).state;"
        - binary_sensor.template.publish:
            id: "Timer_OK"
            state: ON

Except of course you will nee to convert to string and append units. Someone will probably post the full code before I look it up :slight_smile:

1 Like

Actually the default is ms, so you could just:

        - delay: !lambda "return id(Timer).state * 1000 * 60;"

But I wouldn’t be surprised if you end up with a runtime error or a type mismatch.

Thanks @zoogara its work for me