That’s a separate issue and is due to ‘contact bounce’ caused by the physical button’s operation.
The usual “debouncing” technique is based on timing. You define a minimum time period between button presses such as 2 seconds and ignore all events that occur faster than 2 seconds.
For example, imagine after the first 1002 is received, more are generated every 0.25 seconds. We would ignore events 2 through 8 because they were all received within 2 seconds of the first one. We would accept only the one that arrives 2 (or more) seconds after the first one.
0.0 --- 0.25 --- 0.5 --- 0.75 --- 1.0 --- 1.25 --- 1.5 --- 1.75 --- 2.0
1 2 3 4 5 6 7 8 9
YES------NO-------NO------NO-------NO------NO-------NO------NO------YES
The challenge is where to get the timing information? I would suggest using the automation’s own last_changed
time but a fair bit of experimentation is needed to arrive at a working solution.
Another way to debounce it is to use a proxy such as an input_boolean
- When the first 1002 is received, it turns on an input_boolean.
- When additional 1002 events are received, each one also turns on the same input_boolean. However, the first time the input_boolean is turned on, additional attempts to turn it on effectively do nothing (the input_boolean has effectively debounced the stream of 1002 events).
Create the following input_boolean:
input_boolean.spot_midden
then try this automation:
- alias: 'Example 1'
id: example_1
mode: queued
trigger:
- platform: event
event_type: deconz_event
event_data:
id: rc_ef_3_0_142
event: 1002
- platform: state
entity_id: input_boolean.spot_midden
to: 'on'
- platform: state
entity_id: input_boolean.spot_midden
to: 'on'
for: '00:00:02'
action:
- choose:
- conditions: "{{ trigger.platform == 'event' and is_state('input_boolean.spot_midden', 'off') }}"
- service: input_boolean.turn_on
target:
entity_id: input_boolean.spot_midden
- conditions: "{{ trigger.for is defined and trigger.for != None }}"
sequence:
- service: input_boolean.turn_off
target:
entity_id: input_boolean.spot_midden
default:
- service: light.toggle
target:
entity_id: light.spot_midden
How it works:
- When triggered by the first 1002 event, it turns on
input_boolean.spot_midden
. Any additional 1002 events received within 2 seconds will be ignored because the input_boolean’s state is already on
.
- When
input_boolean.spot_midden
turns on
, it triggers the same automation which proceeds to toggle light.spot_midden
.
- After
input_boolean.spot_midden
is on
for 2 seconds, the automation forces it back to off
. Now it is ready to receive new 1002 events.