Hello, I’m trying to use press and hold functions for the button but when I hold the button it keeps sending state on and state off while holding instead of state on when I hold and state off when I release.
Does anyone know what is the problem?
When I invert it works correct just the states are on after releasing and off while holding.
Code and logs and wiring.
[12:36:38][D][binary_sensor:036]: ‘button_1’: Sending state ON
[12:36:38][D][binary_sensor:036]: ‘button_1’: Sending state OFF
[12:36:38][D][binary_sensor:036]: ‘button_1’: Sending state ON
[12:36:39][D][binary_sensor:036]: ‘button_1’: Sending state OFF
[12:36:39][D][binary_sensor:036]: ‘button_1’: Sending state ON
[12:36:39][D][binary_sensor:036]: ‘button_1’: Sending state OFF
[12:36:39][D][binary_sensor:036]: ‘button_1’: Sending state ON
[12:36:40][D][binary_sensor:036]: ‘button_1’: Sending state OFF
[12:36:40][D][binary_sensor:036]: ‘button_1’: Sending state ON
[12:36:40][D][binary_sensor:036]: ‘button_1’: Sending state OFF
This happens while I’m holding
binary_sensor:
- platform: gpio
pin:
number: GPIO10
mode: INPUT
inverted: true
id: button_1
internal: true
filters:
- delayed_on: 20ms
- delayed_off: 20ms
on_multi_click:
- timing:
- ON for 40ms to 400ms
- OFF for at least 50ms
then:
- light.toggle: light_1
- logger.log: Button Pressed
- timing:
- ON for at least 1s
then:
- light.turn_off: light_1
- logger.log: Button Hold
Did you manage to fix this? I have the same exact problem
use ‘duty_cycle’, ‘on_click’ and ‘on_press’
F.e.
# Sensor to detect button push (via duty_cycle of 50hz mains signal)
- platform: duty_cycle
pin: GPIO13
internal: true
id: sensor_push_switch
name: "${node_id} Sensor Push Switch"
update_interval: 20ms
#Binary sensor (on/off) which reads duty_cyle sensor readings.
- platform: template
id: switch1
internal: true
name: "${node_id} Switch Binary Sensor"
# read duty_cycle, convert to on/off
lambda: |-
if (id(sensor_push_switch).state < 95.0) {
return true;
} else {
return false;
}
# Short Click - toggle light only
on_click:
max_length: 300ms
then:
light.toggle: light_main
# Generic On_Press - log press, toggle DIM Direction and reset press interval counter
on_press:
then:
- logger.log: "Switch 1 Press"
- lambda: |-
if (id(g_direction_1) == 0) {
id(g_direction_1) = 1;
} else {
id(g_direction_1) = 0;
}
id(g_counter_1) = 0;