Strange behavior of trigger.event in automation

Hi folks,

running HA on version 0.102.2.

I have two enocean buttons (FT55) which are configured with the right IDs.

I wanted to have an automation that fires when an down button is pressed.

after some testing I came up with the below code as I don’t understant why the event trigger is firred for different datasets (up/down and push/relase) which in the event tracker show different data.

The data set in the event_data section is only valid for down pressed (not released, not up pressed/released) but it fires even for my second enocean swith with another id!

This automation

- id: '1575181929836'
  alias: enocean_action
  description: ''
  trigger:
  - event_data:
      data:
        id:
        - 254
        - 242
        - 255
        - 31
        onoff: 1
        pushed: 1
        which: 0
    event_type: button_pressed
    platform: event
  condition: []
  action:
      service: notify.telegram
      data_template:
        message: >-
          {% if ((trigger.event.data.pushed == 1) and (trigger.event.data.onoff == 1)) %} down pressed
          {% elif ((trigger.event.data.pushed == 0) and (trigger.event.data.onoff == 1)) %} down released
          {% elif ((trigger.event.data.pushed == 1) and (trigger.event.data.onoff == 0)) %} up pressed
          {% elif ((trigger.event.data.pushed == 0) and (trigger.event.data.onoff == 0)) %} up released
          {%endif %}

fires for this event

{
    "event_type": "button_pressed",
    "data": {
        "id": [
            254,
            242,
            245,
            71
        ],
        "pushed": 0,
        "which": 1,
        "onoff": 0
    },
    "origin": "LOCAL",
    "time_fired": "2019-12-01T07:40:34.309813+00:00",
    "context": {
        "id": "76425623b8ab4ad8b93f7b5eb39b0e28",
        "parent_id": null,
        "user_id": null
    }
}

I’m totally puzzled :woozy_face:

Thanks upfront for your help

I assume that the long id under “context” is the unique identifier of your switch. Try to incorporate this is your trigger. (Can’t help right now as I’m on the phone)

Hi Burningstone,

thanks for your fast reply.

I double checked in the event tracker and the id under “context” is different each time the event is fired. So this string would not be reproducable.

Hmm can you try to write the id like this? Not sure if it makes a difference

- event_data:
      data:
        id: [254, 242, 255, 31]
        onoff: 1
        pushed: 1
        which: 0
    event_type: button_pressed
    platform: event

with proper indentation of course

Tried that but no difference.

Maybe these posts can provide clues? Interestingly, they all use hex values to describe the FT55’s id.

Hi Taras,

thanks for the hints, I think I did almost the same as explained in the first post you mentioned.

My problem just is how to see which of the switches has fired (so the ones with different FT55 id).

At the moment the automation fires each time I press any button on any of my two switches. The result with pressed / released and up / down is working fine although I thought the trigger.event would check the data of the event and I would not have to double check with 4 if statements.

May be I just did not understand the trigger.event right.

I thought:

there is event 1(e.g. button_pressed) with data set [a, b,c, d] --> trigger only automation that has this data in the event_data block and is referring to a button_pressed event.

there is event 2 (also button_pressed) with data set [a, b, e, f] --> trigger only automation that has this data and is referring to a button_pressed event

At the moment it looks like the trigger is firing on button_pressed, what ever data set is coming.

So this would be just a great misinterpretation on my side and would explain the results as I see them.

So, what would be the right trigger for my intended use case then?
Or do I just have to write a lengthy if elif statement, possibly nested as seen in one of the threads Taras has mentioned?
If so, why do I have to give the event_data in the automation if it’s basically given to the trigger in the background???

Still not absolutely clear but willing to understand what the logic is that has to be used.

You have one too many “data”. Try this:

  trigger:
  - event_data:
      id:
      - 254
      - 242
      - 255
      - 31
      onoff: 1
      pushed: 1
      which: 0
    event_type: button_pressed
    platform: event

event_data in the trigger is actually data in the event. Yeah, confusing.

Also, the way the event trigger works is, whatever you specify, if it’s present in the event, then it must match. But it doesn’t have to be present. So since you (unknowingly) specified data.data...

Hi Phil,

you made my first Advent light shine bright! :stars:

Works like a charm.

You are really a Great Contributor!

Thanks
Ralf

1 Like