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:
Add user-configurable timer: be able to turn on the switch for X minutes and then turn it off.
Add time led valve control: turn it on every Tuesday on 20:00 and turn it off after 30 minutes.
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.
- 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)
- 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.