How to add this button press as trigger?

Hi,

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:

{
“event_type”: “deconz_event”,
“data”: {
“id”: “rc_ef_3_0_142”,
“unique_id”: “ec:1b:bd:ff:fe:0f:a7:7d”,
“event”: 1002,
“device_id”: “73037549fd4840747f976d22cc21dafe”
},
“origin”: “LOCAL”,
“time_fired”: “2021-04-19T20:30:06.498267+00:00”,
“context”: {
“id”: “754eb1fcb34cd0f67af481118a6e4571”,
“parent_id”: null,
“user_id”: null
}
}

I want to know how I can use this imput as a trigger for an automation… Do I have to copy this info to a config file in order to use it as a trigger?

Your automation can use an Event Trigger.

For example (change the action to whatever you want):

- alias: 'Example 1'
  trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      id: rc_ef_3_0_142
      event: 1002
  action:
  - service: notify.persistent_notification
    data:
      title: Heiman Keyfob
      message: Button event 1002

EDIT

Correction. Forgot to include the trigger: option!

Hi, thanks for your help… I tried some stuff, but still cannot get it done…

When I totally copy and pasta your code into automations.yaml, i am getting an error:

bad indentation of a sequence entry at line 2, column 3:
- platform: event
^

I tried t modify it a bit myself,but nothing change. I also tried some other code like this: Wich is not working aswell:

  • id: ‘1618899828547’
    alias: Nieuwe automatisering
    description: ‘’
    trigger:
    • platform: event
      event_type: ‘’
      event_data:
      event_type: deconz_event
      event_data:
      id: rc_ef_3_0_142
      event: 1002
      condition: []
      action:
    • type: toggle
      device_id: 50a7afac89eb111c5206e3169961858d
      entity_id: light.spot_midden
      domain: light
      mode: single

I made this with the automation plugin. But again, not working… What is going wrong?

My apologies, I made a silly mistake and failed to include the trigger: option!

I have corrected the example posted above. Here is a version that toggles a light.

- alias: 'Example 1'
  id: example_1
  trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      id: rc_ef_3_0_142
      event: 1002
  action:
  - service: light.toggle
    target:
      entity_id: light.spot_midden

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.

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.
1 Like

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?

These are contradictory observations; I have no idea which one is actually happening.

Haha, I’m sorry. That is a bit confusing indeed!

The last one is thrue! With the first one I mean: The action is triggered 3 or 4 times… And I have no idea why that is…

The last part I figured out later… I thought, Let’s take a lot there to see how many events are received. And that is just one…

EDIT: Sorry sorry sorry, the event itself is also received multiple times. But there is some delay. So I will try your solution.