How to delay depending on sensor state in a blueprint

I have an integration which calculates the duration of an irrigation. I would like to use this duration for a delay action. After some hours on searching I didn’t find a solution. All I get is:

Message malformed: expected float for dictionary value @ data[‘action’][1][‘delay’][‘seconds’]

This is my test sensor:

blueprint:
  name: Standard Irrigation
  description: Standard irrigation for one or more zones
  domain: automation
  input:
    irrigation_switch:
      name: Irrigation Switch
      description: Switch, tap or valve to turn on and off
      selector:
        entity:
          filter:
            - domain: input_boolean
    duration:
      name: duration
      description: duration to irrigate
      selector:
        entity:
          filter:
            - device_class: duration

variables:
  my_duration: !input duration

alias: Standard Irrigation
description: "Standard irrigation for one or more zones"

trigger:
  - platform: state
    entity_id:
      - input_boolean.irrigation
condition:
  - condition: numeric_state
    entity_id: !input duration
    above: 0
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: !input irrigation_switch

  - delay:
      seconds: '{{states(\"my_duration\")}}'

  - service: switch.turn_off
    data: {}
    target:
      entity_id:
        - !input irrigation_switch
mode: single

Please read the category descriptions. This is not a community guide. Moved.


Community Guides

The Community Guides section is a place to share guides/tutorials with our community.


Configuration

Questions about configuring Home Assistant to automate your house.


1 Like

I found the solution. It’s

delay: '{{ states(my_duration) }}'