Combine hue dimmer automations

I am using my hue dimmer switch for controlling my sonos speakers.
When I press and hold button 1 on the remote a beep is played and the next 10 seconds a input_boolean is true
If I during this period press button 1-4 on the remote this selects one of my radio presets. At the moment this results in 5 automations (one for press + hold and four for presets). What I would like is for the preset automations to be combined to one automation using templater or a series of conditions in the action statement.
Below are two of the preset automations (configured using UI):

- id: badpre3
  alias: Bad preset 3
  description: ''
  trigger:
  - event_data:
      event: 3000
      id: bad_switch
    event_type: deconz_event
    platform: event
  condition:
  - condition: state
    entity_id: input_boolean.bad_choose_station
    state: 'on'
  action:
  - data:
      source: DR P6 Beat
    entity_id: media_player.badevaerelse
    service: media_player.select_source
  mode: single
- id: badpre4
  alias: Bad preset 4
  description: ''
  trigger:
  - event_data:
      event: 4000
      id: bad_switch
    event_type: deconz_event
    platform: event
  condition:
  - condition: state
    entity_id: input_boolean.bad_choose_station
    state: 'on'
  action:
  - data:
      source: The Voice
    entity_id: media_player.badevaerelse
    service: media_player.select_source
  mode: single

As you can see what I would actually like to have is that the source under data is filled based on the value of the event field under event_data

Welcome to the community!

Try this:

- id: badpre3
  alias: Bad preset handler
  description: ''
  trigger:
  - event_data:
      id: bad_switch
    event_type: deconz_event
    platform: event
  condition:
  - condition: state
    entity_id: input_boolean.bad_choose_station
    state: 'on'
  - condition: template
    value_template: >
      {% set valid_events = [ 3000, 4000 ] %}
      {{ trigger.event.data.event | int in valid_events }}
  action:
  - data_template:
      source: >
        {% set value = trigger.event.data.event | int %}
        {% set events = {
          3000: 'DR P6 Beat',
          4000: 'The Voice',
          } %}
        {{ events[value] }}
    entity_id: media_player.badevaerelse
    service: media_player.select_source

The condition template filters out all unwanted events. If you want to add a new event, just add it to the valid_events list.

The source template maps event numbers to source names. Then based on the incoming event, we choose the correct channel.

Thanks! The final automations ended up like this (i switched to the hue bridge combined with the hacs extension to increase polling time)

Automation to enable choosing station when holding button 1:

- id: repos_choose
  alias: Repos Radio Enable Choice
  description: ''
  trigger:
  - event_data:
      event: 1001
      id: repos_switch
    event_type: hue_event
    platform: event
  - device_id: 0a7884e33eb74fe78966ed6eb0327b98
    domain: hue
    platform: device
    subtype: turn_on
    type: remote_button_long_release
  condition: []
  action:
  - data: {}
    entity_id: input_boolean.repos_choose_station
    service: input_boolean.turn_on
  - data:
      media_content_id: http://10.0.1.11/media/beep.mp3
      media_content_type: music
    entity_id: media_player.repos_sonos
    service: media_player.play_media
  - delay: 00:00:10
  - data: {}
    entity_id: input_boolean.repos_choose_station
    service: input_boolean.turn_off
  mode: restart

Automation to choose station after holding on:

- id: '1596563679023'
  alias: Repos Radio Choose
  description: ''
  trigger:
  - event_data:
      id: repos_switch
    event_type: hue_event
    platform: event
  condition:
  - condition: state
    entity_id: input_boolean.repos_choose_station
    state: 'on'
  action:
data_template:
  source: |
    {% set value = trigger.event.data.event | int %} {% set events = {
      1002: 'DR P1',
      2002: 'DR P6 BEAT',
      3002: 'DR P8 JAZZ',
      4002: 'The Voice',
      } %}
    {{ events[value] }}
    entity_id: media_player.repos_sonos
    service: media_player.select_source
  - data: {}
    entity_id: input_boolean.repos_choose_station
    service: input_boolean.turn_off
  mode: single