Delay length controlled by home assistant sensor

I want to use the delay function in an automation but I would like that delay to be controlled be a home assistant sensor. This is my current code:

   - then: 
         - if:
              condition:
                lambda: |-
                  return id(feed_interval).state > 0
              then:
                - wait_until:
                    condition:
                      - binary_sensor.is_off: feeder_running
                - switch.turn_off: feeder_on
                - delay: id(feed_interval).state
                - switch.turn_on_induction: feeder_on 

Is there a way to make this work? I have givent the home assistant sensor a device_class of duration but so far no luck

I got this working. This was the solution if anyone is interested.

      - then: 
          - if:
              condition:
                lambda: |-
                  return id(feed_interval).state > 0;
              then:
                - wait_until:
                    condition:
                      - binary_sensor.is_off: feeder_running
                - switch.turn_off: feeder_on
                - delay: !lambda 'return (id(feed_interval).state * 60000);'
                - switch.turn_on: feeder_on
1 Like

Yes - the only way to pass a value is lambda and it must be in milliseconds - I am assuming your feed_interval was in minutes?

Just context for anyone who sees your solution and wonders why 60000. :slight_smile: