Binary switch variants: timer, led by time, led by event

Hi,

I use Home Assistant 0.63 on Raspberry pi. I have watering valves connected to GPIO 5 and 12:

switch:
  - platform: rpi_gpio
    ports:
      5: Water trees
      12: Water lawn
input_number:
  slider1:
    name: Watering Run Time
    initial: 20
    min: 1
    max: 90
    step: 1
    unit_of_measurement: mins
    icon: mdi:timer

I am looking for following options to control the swtich:

  1. Add user-configurable timer: be able to turn on the switch for X minutes and then turn it off.
  2. Add time led valve control: turn it on every Tuesday on 20:00 and turn it off after 30 minutes.
  3. Add event-driven control: When outside temperature is greater than Y turn it on for 10 minutes.

I would pretty easy to add tasks to crontab to fire mqtt events and tie them with actions. However, I think this is an awkward way to use the HA.

For 1st problem (set timer) I found these examples:
https://home-assistant.io/cookbook/turn_on_light_for_10_minutes_when_motion_detected

and I got this code in automation.yaml:

- alias: Turn on garden watering
  trigger:
    platform: state
    entity_id: switch.watering.port.5
    to: 'on'
  action:
    service: homeassistant.turn_on
    entity_id: switch.watering.port.5

- alias: Turn off garden watering when timer ends
  trigger:
    platform: state
    entity_id: switch.watering.port.5
    to: 'off'
    for:
      minutes: {{ states.input_number.slider1.state | int }}
  action:
    service: homeassistant.turn_off
    entity_id: switch.watering.port.5

I get following error:

2018-03-06 21:42:25 ERROR (Thread-2) [homeassistant.util.yaml] invalid key: 
"OrderedDict([('states.input_number.slider1.state | int', None)])"
  in "/home/pi/.homeassistant/automations.yaml", line 36, column 0

Are there such switch components? Examples?
Please, point me, I can’t find this in the list of switches.

Thank you.

- alias: Turn on garden watering
  trigger:
    platform: state
    entity_id: switch.watering.port.5
    to: 'on'
  action:
    service: homeassistant.turn_on
    entity_id: switch.watering.port.5

- alias: Turn off garden watering when timer ends
  trigger:
    platform: state
    entity_id: switch.watering.port.5
    to: 'off'
    for:
      minutes: '{{ states.input_number.slider1.state | int }}'
  action:
    service: homeassistant.turn_off
    entity_id: switch.watering.port.5 

Have you tried like this?
Also your automation look inverse? The first automation waits for the switch.watering.port.5 turn on then turn it on? same goes for the second automation waits for the switch to turn off then turns it off again

Hi. I realize that something (everything?) wrong in my automation. It doesn’t work.
Since I fail to create automation for GPIO with yaml, I tried to create automation with frontend. The format it writes to yaml is different from documentation. And i still can’t put GPIO to timer.

- action:
  - data: {}
    service: homeassistant.turn_on
  entity_id: switch.water_lawn
  alias: New Automation
  condition: []
  id: '1520447310286'
  trigger:
  - entity_id: switch.water_lawn
    from: 'off'
    platform: state
    to: 'on'

Is there example or instructions how to put GPIOs to timer in HA? (with Yaml or GUI)

Thank you.

Got some progress. This works:

- id: turn_off_lawn_water
  alias: Turn off garden watering
  trigger:
  - entity_id: switch.water_lawn
    from: 'off'
    platform: state
    to: 'on'
    for:
      minutes:  1 #Templates don't work in 'for' :( "{{ states.input_number.slider1.state | int }}"
  action:
  - data: {}
    entity_id: switch.water_lawn
    service: homeassistant.turn_off
  - data:
      message: Water off after '{{ states.input_number.slider1.state | int }}' minute
    service: system_log.write
  - data:
      payload: "Water off after '{{ states.input_number.slider1.state | int }}' minute"
      topic: "shm/notification"
      retain: 0
    service: mqtt.publish

So far the problem is:
Templates don’t work in ‘for’ delay, in messages, and in MQTT payload.
I am seeking for a method to read value from slider and turn the GPIO off while time is gone.

I thought maybe add action of shell command execution with the time from slider.
The documentation about templates is really confusing: https://home-assistant.io/docs/automation/templating/#template

Is there a way to set timer from slider or from other element in User Interface?