Help on input_number slider needed: set a switch to off after x minutes from slider value

Hello,

already searched the forums and also found some input, but still have issues to get it running.
Running latest Hass.io and lovelayce (yaml mode).

What i want to do: my water irrigation starts by either a) a switch turned to on or b) if in automation mode, at a specific time. Works so far.

What i want to achieve is to set the switch to off again after a specified time using a slider.
Seems to be a problem in the automation, if i uncomment it the code check runs.

Definition of slider and time (from within a package):

input_datetime:
  bewaesserung_on:
    name: Startzeit
    has_date: false
    has_time: true

input_boolean:
  auto_bewaesserung:
    name: Automatik (täglich)
    icon: mdi:auto-fix

input_number:
  bewaesserung_dauer:
    name: Slider
    min: 10
    max: 60
    step: 10

The automation:

automation:

### Gartenbewaesserung starten
- alias: bewaesserung_start
  trigger:
    - platform: template
      value_template: '{{ states.sensor.time.state == (states.input_datetime.bewaesserung_on.attributes.timestamp | int | timestamp_custom("%H:%M", False)) }}'
  condition:
    condition: state
    entity_id: input_boolean.auto_bewaesserung
    state: 'on'
  action:
    service: homeassistant.turn_on
    entity_id:
      - switch.switch_wasser
      
### Bewaesserung stoppen
- alias: bewaesserung_stoppen
  trigger:
    platform: state
    entity_id: switch.switch_wasser
    to: 'on'
  action:
    - delay: '00:{{ states.input_number.bewaesserung_dauer.state | int }}:00'
    - service: homeassistant.turn_off
    - entity_id: switch.switch_wasser

Thanks for pointing me into the right direction.
/ Ralf

  action:
    - delay: '00:{{ states.input_number.bewaesserung_dauer.state | int }}:00'
    - service: homeassistant.turn_off
    - entity_id: switch.switch_wasser

to

  action:
    - delay: '00:{{ states.input_number.bewaesserung_dauer.state | int }}:00'
    - service: switch.turn_off
      entity_id: switch.switch_wasser

Just a few thoughts to maybe simplify things a bit.

The trigger in your first automation could be:

  trigger:
    - platform: template
      value_template: "{{ states('sensor.time') ~ ':00' == states('input_datetime.bewaesserung_on') }}"

And the action can be:

  action:
    service: homeassistant.turn_on
    entity_id: switch.switch_wasser

Delays can also take a number of seconds, so it could be:

    - delay: "{{states('input_number.bewaesserung_dauer')|float * 60 }}"

But the reason the second automation wasn’t working is there should not be a dash before entity_id in the action.

Thanks very much for the hint!
One dash too much can cause trouble… :wink:

/ Ralf