How to set a input_number as a delay time

I try to use a input_number (input_number.temps_remplissage) to set up a delay in automation, to keep possibility to quick change de value on the dashboard…
I try something like this in template…

alias: test
- id: '1122334459999'
  alias: delaytest
  description: ''
  trigger:
  - entity_id: switch.relay_pression
    for:
      seconds: "{{ states('input_number.temps_remplissage') | int(0) }}"
    platform: state
    to: 'off'

I probably completly wrong but if someone have any clue…

1 Like

Please edit your post and format your pasted config as per point 11 here.

1 Like

seconds: "{{ states('input_number.temps_remplissage') | int }}"

Work well Thanks!
I was not too far…:sweat_smile:

In that case, it is possible to use delay in condition?
if gas detect turn off if not apply the delay than turn off…

alias: Remplissage
sequence:
  - type: turn_on
    device_id: 1617478ad435bc2fd127672deb518f**
    entity_id: switch.relay_purge
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - type: turn_on
    device_id: 1617478ad435bc2fd127672deb518f**
    entity_id: switch.relay_pression
    domain: switch
  - delay: '{{ states(''input_number.temps_sellage'') | int }}'
  - type: turn_off
    device_id: 1617478ad435bc2fd127672deb518f**
    entity_id: switch.relay_pression
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - type: turn_on
    device_id: 1617478ad435bc2fd127672deb518f**
    entity_id: switch.relay_bouchon
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - type: turn_on
    device_id: 1617478ad435bc2fd127672deb518f**
    entity_id: switch.relay_robinet
    domain: switch
  - condition: or
    conditions:
      - condition: template
        value_template: 'delay: ''{{ states(''''input_number.temps_remplissage'''') | int }}'''
      - type: is_gas
        condition: device
        device_id: 98c19ac6233744c19e931c0339424a**
        entity_id: binary_sensor.niveau_d_eau_reservoir
        domain: binary_sensor
        for:
          hours: 0
          minutes: 0
          seconds: 2
          milliseconds: 0
  - type: turn_off
    device_id: 98c19ac6233744c19e931c0339424a**
    entity_id: switch.relay_robinet
    domain: switch
mode: single
icon: mdi:water-pump

Use a state condition rather than a device condition and you can.

I don’t see how to put the delay in condition… :face_with_monocle:

You can use delay to suspend the execution of action (not to suspend the processing of a condition).

Whatever you use in condition is processed immediately after the trigger occurs. It doesn’t pause or wait for something else to happen before it proceeds to execute the action. Basically, everything within condition serves as a go/no-go filter to determine if it should or should not execute action.

Ok, but in my case it is the reverse that I am trying to obtain, I want to turn off a relay after a certain delay, unless the water level is reached before

I also try witout condition
but I have this message: ‘‘Message malformed: expected a dictionary @ data[‘sequence’][9][‘wait_for_trigger’][1]’’

alias: Remplissage
sequence:
  - type: turn_on
    device_id: 98c19ac6233744c19e931c0339424ac1
    entity_id: switch.relay_purge
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - type: turn_on
    device_id: 98c19ac6233744c19e931c0339424ac1
    entity_id: switch.relay_pression
    domain: switch
  - delay: '{{ states(''input_number.temps_sellage'') | int }}'
  - type: turn_off
    device_id: 98c19ac6233744c19e931c0339424ac1
    entity_id: switch.relay_pression
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - type: turn_on
    device_id: 98c19ac6233744c19e931c0339424ac1
    entity_id: switch.relay_bouchon
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - type: turn_on
    device_id: 98c19ac6233744c19e931c0339424ac1
    entity_id: switch.relay_robinet
    domain: switch
  - wait_for_trigger:
      - type: gas
        platform: device
        device_id: 98c19ac6233744c19e931c0339424ac1
        entity_id: binary_sensor.niveau_d_eau_bain
        domain: binary_sensor
        for:
          hours: 0
          minutes: 0
          seconds: 2
          milliseconds: 0
      - null
    timeout: {{ states(''input_number.temps_remplissage'') | int }}'
  - type: turn_off
    device_id: 98c19ac6233744c19e931c0339424ac1
    entity_id: switch.relay_robinet
    domain: switch
mode: single
icon: mdi:water-pump

The error message is referring to the second par

Items in a list are numbered starting with zero. So the first item is 0, the second is 1, etc. The error message refers to ['wait_for_trigger'][1] which means the second item in wait_for_trigger. What is the second item in your wait_for_template? It’s this invalid entry here:

      - null

Remove it.

In addition, the template for timeout is missing an initial single quote to match its terminating single quote. Add the missing single quote.

1 Like

:metal:Thats work now!!! :metal:

Glad to hear it.

You should mark tom_l’s post with the Solution tag because it answers the question in your original post. What I supplied answers your follow-up question and isn’t the solution to the original question.

1 Like