Input_slider value used in automation for a delayed switch off doesn't work

Folks,
I created an input_slider to define the minutes I wanna wait before I switch of my sonos on my bathroom. Just to keep it easy.

nachspielzeit:
    name: Nachspielzeit (min)
    icon: mdi:timer
    initial: 10
    min: 0
    max: 59
    step: 1

When I try to add this value to my trigger

##################################################################
# Needed Ressources
# sensor.vision_zp3111_multisensor_4in1_burglar_10_10
#
# notify.my_pushbullet
# media_player.bad
##################################################################
alias: "No Motion Notification im Bad"
trigger:
  platform: state
  entity_id: sensor.vision_zp3111_multisensor_4in1_burglar_10_10
  from: '8'
  to: '0'
  for:
    minutes: '{{ states.input_slider.nachspielzeit.state | int }}'
#    minutes: 5
action:
  - service: media_player.turn_off
    entity_id: media_player.bad
#  - service: notify.my_pushbullet
#    data:
#      message: "Motion im Bad beendet - Switch off Media Player"

can anybody help how to get it solved.

hass --script check_config

says:
2017-06-15 22:45:48 INFO (MainThread) [homeassistant.setup] Setting up notify
2017-06-15 22:45:49 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: expected int for dictionary value @ data[ā€˜triggerā€™][0][ā€˜forā€™][ā€˜minutesā€™]. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/automation/

Pretty sure ā€˜for:ā€™ doesnā€™t support templates. Take a look here, seems like a very similar case with some work-arounds.

I use input_sliders too for time delays. The way I get around the ā€œforā€ not being able to use templates is call a script and use a template in the delay action. It does require you to make a new automation to cancel the script if motion is detected. Let me know if youā€™re stuck and I can post an example later when Iā€™m at my computer.

can you show a expample script

Hereā€™s an automation I use to turn off the basement lights if thereā€™s no motion in x minutes (which it gets from the input_slider. It calls a script and uses that delay time. If motion is detected while the script is in itā€™s delay period, the second automation turns the script off, thereby cancelling the automation to turn off the lights.

Hereā€™s the automations (you donā€™t need to use the conditions, I just built some input_booleans as options):

  - alias: 'Basement Lights Timer Start'
    trigger:
      platform: state
      entity_id: binary_sensor.in_the_basement_occupancy
      from: 'on'
      to: 'off'
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: input_boolean.basement_motion
          state: 'on'
        - condition: state
          entity_id: input_boolean.guest_mode_basement
          state: 'off'
    action:
      service: script.turn_on
      entity_id: script.basement_motion
  - alias: 'Basement Lights Timer Cancel'
    trigger:
      platform: state
      entity_id: binary_sensor.in_the_basement_occupancy
      from: 'off'
      to: 'on'
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: input_boolean.basement_motion
          state: 'on'
        - condition: state
          entity_id: input_boolean.guest_mode_basement
          state: 'off'
    action:
      service: script.turn_off
      entity_id: script.basement_motion  

And the script:

  basement_motion:
    sequence:
      - delay: >-
          {% set duration = states.input_slider.basement_motion.state | int * 60 %}
          {% if duration > 0 %}
            {% set duration = duration - 1 %}
          {% endif %}
          {% set seconds = duration % 60 %}
          {% set minutes = (duration / 60)|int % 60 %}
          {% set hours = (duration / 3600)|int %}
          {{ [hours, minutes, seconds]|join(':') }}
      - service: light.turn_off
        data_template:
          entity_id:
            - light.basement_1
            - light.basement_2
            - light.basement_floor_lamp
1 Like