[HA][QNAP-DOCKER][HUE+XIAOMIV3+IKEA-TRADFRIBulbs] Automations for Aqara Switches

Tags: #<Tag:0x00007f326e479788> #<Tag:0x00007f326e478ba8> #<Tag:0x00007f326e478400> #<Tag:0x00007f326e49fa00>

Hello,

I’ve got a stable installation in Docker HOME ASSISTANT on my QNAP TS-251.
I use HUE Bridge to control the Tradfri Bulbs and a small set of HUE Bulbs. (Needed it especially for pairing the Theather lights with the Philips HUE TV light)
Then i Bought this XIAOMI GATEWAY3 zndmwg03lm (initially just to test it), which i hold for the moment on Chinese server (afraid to switch to Europe as from the iOS MiAPP will make the AQara switches un-pairable).
So there you go, on the XIAOMI, since it has Zigbee 3.0 and better BLE, i will be holding Mi 360 Camera, Aqara switches, Moving Sensors, Smoke detector, etc.

I have a bunch of WXKG03LM (Single) , WXKG07LM (double) & an QBKG22LM (Wall).
As HA HUE Integration accepts HUE Groups, i can control the group or the individual bulbs.

I need to create an automation (sort of trigger per device) on the Aqara Single switch in such way that the automation covers all the scenarios (Short, Long, Double, button_1_single, button_2_single).
For example: When i LONG PRESS on the single switch, the Bulbs (Either 3xeach bulb or a group of those 3 bulbs), these would dim to 50% and then dim back at 100% at next LONG press.

Could you please help me out?

LATER EDIT:
I found out that by configuring for example a simple Group of three lights and activating them in single Automation mode:

entity_id: sensor.0x158d0002ca0bf1_action
from: single
platform: state
then
data: {}
entity_id: light.office
service: light.toggle

It works well, while the below is a bit “unresponsive” - works few times.
(this is for a double switch)

entity_id: sensor.0x158d0005426548_action
platform: state
choose:
  - conditions:
      - condition: state
        entity_id: sensor.0x158d0005426548_action
        state: button_1_single
    sequence:
      - data: {}
        entity_id: light.living_masa
        service: light.toggle
  - conditions:
      - condition: state
        entity_id: sensor.0x158d0005426548_action
        state: button_2_single
    sequence:
      - data: {}
        entity_id: light.living_canapea
        service: light.toggle
default: []

I don’t seem to get how to configure these. Maybe with event or template but i don’t get it yet.