I have a gpio input defined as a binary sensor and is driven by a LM393 comparator. I’d like to trigger this input with a pulse from a HA dashboard button. Can this be accomplished thru the yaml config. or by using a gpio switch output fed back electronically to the binary input pin?
I realized my approach was incorrect. what I needed was to create a script entry in the yaml file and also a Button template. Now I can execute the script by either the binary_sensor or the button. Adding the Button to the yaml also makes it available in HA.
Here’s the code I ended up with.
binary_sensor:
- platform: gpio
id: gpio21
name: Water Sensor
publish_initial_state: True
pin:
number: 21
mode:
input: True
pullup: False
pulldown: True
filters:
- delayed_on: 30ms
on_press:
then:
- script.execute: drain_tank
button:
- platform: template
name: "Start Draining"
on_press:
- script.execute: drain_tank
script:
- id: drain_tank
mode: single
then:
- switch.turn_on: gpio2
- switch.turn_on: gpio16
- delay: 5s
- switch.turn_on: gpio17
- delay: !lambda "return id(glob_drain_delay) * 60000;"
- switch.turn_off: gpio2
- switch.turn_off: gpio17
- switch.turn_off: gpio16
1 Like