Automation, combining automations for switch functions

HI All,

I am a newbee to HA and is trying to setup Automations.
I have an IKEA switches that I use for turning on/off a lampe.

I have seperate automation for turning on the lamp and one for turning off the lamp.
But, can’t this be combined in one Automation?
(via conditions for example?).

Below is example of what I am trying to do.
But, I cant setup the conditions to execute action dependant in which button pressed, ON or OFF.
There might be a way…
Can someone point me in the right direction?

- id: '1618515482976'
  alias: Lampe Martin
  description: ''
  trigger:
  - device_id: 533bd0b614494a29081169efee573939
    domain: deconz
    platform: device
    type: remote_button_short_press
    subtype: turn_off
  - device_id: 533bd0b614494a29081169efee573939
    domain: deconz
    platform: device
    type: remote_button_short_press
    subtype: turn_on
  condition: []
  action:
  - type: turn_off
    device_id: 0045d759b294332fc1e784e6e0b091d8
    entity_id: light.color_temperature_light_5
    domain: light
  mode: single

Thanks,
Martin.

Please go to developer console>events and then listen to zha_events. Then press the button to turn on and off. You should see seing event logs there, Please share it. We will need that to make this automation.

Thanks, great tip.!
Maybe I should inform that I am using a conbee (deconz)… :wink:

I started to listen to deconz_event… but did not get any input right away when activating the Switch.
After 2 restarts of the server, input began to show up.
Here is what I got for a short press:

{
    "event_type": "deconz_event",
    "data": {
        "id": "sw_01",
        "unique_id": "84:71:27:ff:fe:be:9d:eb",
        "event": 1002,
        "device_id": "533bd0b614494a29081169efee573939"
    },
    "origin": "LOCAL",
    "time_fired": "2021-04-17T10:31:15.793199+00:00",
    "context": {
        "id": "42626a09a443643e352a58e20808d594",
        "parent_id": null,
        "user_id": null
    }
}

From this event you can combine the automation. The key part of the log is event which for this log is 1002 meaning single hold release. This varies with each type of button action and can be seen below.
image

You can use the vent type trigger can be the same but actions should be template in nature. Please check out below yaml.

- id: '1618515482976'
  alias: Lampe Martin
  description: ''
  trigger:
  - device_id: 533bd0b614494a29081169efee573939
    domain: deconz
    platform: device
    type: remote_button_short_press
    subtype: turn_off
  - device_id: 533bd0b614494a29081169efee573939
    domain: deconz
    platform: device
    type: remote_button_short_press
    subtype: turn_on
  condition: []
  action:
  - choose:
    - conditions:
      - condition: template
        value_template: '{{ trigger.event.data.event == 1000 }}'
      sequence:
      - service: light.turn_on
        target:
          entity_id: light.color_temperature_light_5
    - conditions:
      - condition: template
        value_template: '{{ trigger.event.data.event == 1002 }}'
      sequence:
      - service: light.turn_off
        target:
          entity_id: light.color_temperature_light_5
    default: []
  mode: single