Little code problem

Super simple I guess but…

I what to get a number value form HA an use it as delay. I have:

number:
  - platform: template
    id: duration
    name: "cat feeder duration"
    optimistic: true
    min_value: 1
    max_value: 60
    step: 1
    mode: box
    initial_value: 15 
interval:

  - interval: 60sec
    then:
      if:
        condition:
          - lambda: 'return id(start_time_hour).state == id(homeassistant_time).now().hour;'
        then:
          if:
            condition:
              - lambda: 'return id(start_time_minute).state == id(homeassistant_time).now().minute;'
            then:
              if:
                condition:
                  - lambda: 'return id(cat_feeder_enable).state;'
                then:
                  - switch.turn_on: relay_0
                  - delay: !lambda "return (id(duration).state);"
                  - switch.turn_off: relay_0

For some reason the delay is 0 but in the logs I can see is the correct value. If I use:

  - interval: 60sec
    then:
    - lambda: |-
        float dura = id(duration).state;
        ESP_LOGD("main", "Duration %f", dura);

i can see the correct value… I do not know what is wrong…

“When using a lambda call, you should return the delay value in milliseconds.”

It’s probably doing what it’s told :slight_smile:.

If you want to keep the input number as seconds, just multiply your lambda by 1000.

1 Like