Automation with templates and "choose" action

Arg. Though I had a rather steep learning curve when switching from OpenHAB to HA, I now get to the limits of my understanding of HA. I try to use automations for Zigbee remote controls, and I don’t want to fill up everything with single automations for every single keypress of the remote.

So I thought I’d try to learn about templating. But, frankly, the documentation really sucks in this case. It seems to me as if knowledge of Yaml, Jinja and all those concepts is taken for granted and I’m missing a step-by-step guide to the ideas and concepts behind HA.

So I thought I’d ask the forum.

If I make one automation per keypress, it is simple:

id: '9593528121445'
  alias: 'Remote Light 1 +'
  trigger:
  - event_data:
      event: 11002
      unique_id: xx:aa:9d:00:01:8b:ee:f3
    event_type: deconz_event
    platform: event

and then the “action:”, as I like it.

Now I’d like to start the automation only with the “unique_id:”, which identifies the remote, and use the “event” field, which describes, which button was pressed on this remote (and how), to “choose” between several actions. That means, that every keypress of a single remote is handled within one automation.

HA now has a “choose:” action. And I played around with “trigger.event” and “trigger.event.data” in order to differentiate between the keypresses. However, it does not work. And I don’t find any example which fits my needs. I don’t know if to use only trigger.event or states() or state_attr() or something else. I don’t know what exactly the {{ and {% constructs mean. And I don’t find an introduction to this concepts, only a bunch of examples, which, however, don’t seem to work when I try to adapt them to my needs.

So, can anybody point me to an example how I “choose” within an automation depending on the data attribute “event” of the triggering event? Thanks in advance!

I tried to solve this problem for couple days.

First I listened for the event in the ‘developers tab’. i started to listen on ‘deconz_event’ type.

Something like this was generated for me:

{
    "event_type": "deconz_event",
    "data": {
        "id": "switch_1",
        "unique_id": "00:15:8d:00:04:26:11:5e",
        "event": 1002
    },
    "origin": "LOCAL",
    "time_fired": "2020-11-05T09:53:03.376369+00:00",
    "context": {
        "id": "9ed28e548858776d44226905a297c9b8",
        "parent_id": null,
        "user_id": null
    }
}

Next I tried to play with {{ trigger.event.data.event }} which worked as intended.

Now my automation looks like:

alias: lights automation
trigger:
  - platform: event
    event_type: deconz_event
    event_data:
      id: switch_1
condition: []
action:
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ trigger.event.data.event == 1002 }}'
      sequence: 
        - service: light.toggle
          entity_id: light.first_light
    - conditions: 
      - condition: template
        value_template: '{{ trigger.event.data.event == 2002 }}'
      sequence: 
        - service: light.toggle
          entity_id: light.second_light
mode: single