How to configure automation with multiple triggers for different actions

Hi all,

I have an Aqara button that turns on a group of switches with a single press, a different group with a double press and then turns everything off with a long press. Right now, I have that as three separate automations. Is there an effective way to combine everything into one? Here is what I currently have:

Short Press:

alias: Turn on 3D Printer (no heat)
description: ""
trigger:
  - device_id: dec601203483cee899e6e3540238735b
    domain: zha
    platform: device
    type: remote_button_short_press
    subtype: remote_button_short_press
condition: []
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.3d_printer_no_heat
mode: single

Double Press:

alias: Turn on 3D Printer (with heat)
description: ""
trigger:
  - device_id: dec601203483cee899e6e3540238735b
    domain: zha
    platform: device
    type: remote_button_double_press
    subtype: remote_button_double_press
condition: []
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.3d_printer_with_heat
mode: single

Long Press:

alias: Turn Off 3D Printer
description: ""
trigger:
  - device_id: dec601203483cee899e6e3540238735b
    domain: zha
    platform: device
    type: remote_button_long_release
    subtype: remote_button_long_release
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.3d_printer_with_heat
mode: single

Thank you!

Yes. Set a different Trigger ID for each trigger, then use a “Choose” action with a condition for each trigger ID.

You may need to change the mode depending on how you would want to accommodate if the automation could receive multiple triggers in rapid sequence.

alias: Turn on 3D Printer (no heat)
description: ""
trigger:
  - device_id: dec601203483cee899e6e3540238735b
    domain: zha
    platform: device
    type: remote_button_short_press
    subtype: remote_button_short_press
    variables:
      cmd: 'on'
      entity: 'no_heat'
  - device_id: dec601203483cee899e6e3540238735b
    domain: zha
    platform: device
    type: remote_button_double_press
    subtype: remote_button_double_press
    variables:
      cmd: 'on'
      entity: 'with_heat'
  - device_id: dec601203483cee899e6e3540238735b
    domain: zha
    platform: device
    type: remote_button_long_release
    subtype: remote_button_long_release
    variables:
      cmd: 'off'
      entity: 'with_heat'
condition: []
action:
  - service: 'switch.turn_{{ cmd }}'
    data: {}
    target:
      entity_id: 'switch.3d_printer_{{ entity}}'
mode: single

EDIT

Correction. Added missing subtype option to Device Triggers.

1 Like

Thank you so much! One question - when I go to save it, I get the following error:

Message malformed: required key not provided @ data['subtype']

Not sure what that means…

Thanks!

In @123 example only the first trigger has a subtype:

The last two triggers are missing this.

That’s due to my mistake; while copy-pasting from your examples I failed to include the subtype option in the second and third Device Triggers. I have corrected the example posted above.