09-10-2024, 11:00 AM
The debounce filter ensures that the input signal is stable and ignores short, unintended changes (debounce is used to filter out the bouncing effect of mechanical buttons).
Code:
# Configuring a binary sensor (button or switch input)
binary_sensor:
- platform: gpio # Use the GPIO platform to read the input
name: "PCF8574 Input 7" # The name of the sensor, visible in platforms like Home Assistant
pin:
pcf8574: pcf8574_hub # Reference the PCF8574 hub ID defined earlier
number: 7 # The input will be read from pin number 7 on the PCF8574 chip
mode: INPUT # The pin mode is set as input
inverted: false # Whether the signal is inverted, false means it's not inverted
filters:
- debounce: 50ms # The debounce filter to delay by 50 milliseconds to handle button bounce
on_press:
- logger.log: "Button Pressed" # Logs "Button Pressed" when the button is pressed
on_release:
- logger.log: "Button Released" # Logs "Button Released" when the button is released