Im using home assistant with Deconz. One of the devices I want to use for an automation is a heiman hs1rc-ef keyfob. The device is visible in HA, but the buttons are not configured. However, When I go to developer option and listen for events, I can see the events like this:
Aaaaaah thanks! It is working! That is a nice start to do some other stuf with it.
One problem: When I press the button once, it repeats the signal 3 or 4 times… So in the action part, I use switch a light to on or of, it goes on, off, on, off, on, off… Any suggestions?
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.
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.
Thanks for this detailed information A LOT!! I will give it a try.
Only one thing to mention: When I listen to events under developer tools, and I press the button, only 1 event is registrated. Because the event runs multiple times, can there also be another reason for this behavior?