ZHA - Xiaomi Mijia Round Wireless Switch (WXKG01LM) with HOLD - lumi.sensor_switch

This Blueprint allows you to configure an Xiaomi Mijia Round Wireless Switch (WXKG01LM) paired to the ZHA integration. The Zigbee ID for this button is “lumi.sensor_switch”.

This implementation supports a HOLD action. An other blue-print from user @carlosmesquita did lack the support of the hold action.

This blueprint is based on a automation i earlier published in: https://community.home-assistant.io/t/longpress-and-shortpress-script-automation-for-xiaomi-round-button-with-zha/229367

blueprint:
  name: ZHA - Mijia Wireless Remote Switch (WXKG01LM)
  description: Automate your Xiaomi Mijia Wireless Round Remote Switch using ZHA events.
  domain: automation
  input:
    mijia_round_switch:
      name: Mijia Wireless Round Switch
      description: Mijia Wireless Round Switch to use
      selector:
        device:
          integration: zha
          manufacturer: LUMI
          model: lumi.sensor_switch
    remote_button_short_press:
      name: Single Press short
      description: Action to run on single press
      default: []
      selector:
        action: {}
    holdtime:
      name: Holdtime for hold detection
      description: Time to wait until hold_press is activated
      default: 1
      selector:
        number:
          min: 0.0
          max: 10.0
          unit_of_measurement: seconds
          step: 1.0
          mode: slider
    remote_button_hold_press:
      name: Hold Press    
      description: Action to run on hold
      default: []
      selector:
         action: {}      
    remote_button_double_press:
      name: Double Press
      description: Action to run on double press
      default: []
      selector:
        action: {}
    remote_button_triple_press:
      name: Triple Press
      description: Action to run on triple press
      default: []
      selector:
        action: {}
    remote_button_quadruple_press:
      name: Quadruple Press
      description: Action to run on quadruple press
      default: []
      selector:
        action: {}
    remote_button_multiple_press:
      name: Multiple Press
      description: Action to run on multiple press
      default: []
      selector:
        action: {}    

mode: restart
max_exceeded: silent
trigger:
- platform: event
  event_type: zha_event
  event_data:
    device_id: !input 'mijia_round_switch'
    command: 'attribute_updated'
action:
- variables:
    attrname: '{{ trigger.event.data.args.attribute_name }}'
    value: '{{ trigger.event.data.args.value }}'   
- choose:
  - conditions:
    - '{{ attrname == ''on_off'' }}'
    - '{{ value == true }}' 
    sequence:
    
    - wait_for_trigger:
      - platform: event
        event_type: zha_event
        event_data:
          device_id: !input 'mijia_round_switch'
          command: 'attribute_updated'
          args:
            attribute_id: 0
            attribute_name: on_off
            value: false
      continue_on_timeout: true
      timeout: !input 'holdtime'  
    - choose:
      - conditions:
          - condition: template
            value_template: '{{ not wait.trigger }}'
        sequence: !input 'remote_button_hold_press'      
      default: !input 'remote_button_short_press'
        
 
  - conditions:
    - '{{ attrname == ''Unknown'' }}'
    - '{{ value == 2 }}'
    sequence: !input 'remote_button_double_press'
  - conditions:
    - '{{ attrname == ''Unknown'' }}'
    - '{{ value == 3 }}'
    sequence: !input 'remote_button_triple_press'
  - conditions:
    - '{{ attrname == ''Unknown'' }}'
    - '{{ value == 4 }}'
    sequence: !input 'remote_button_quadruple_press'
  - conditions:
    - '{{ attrname == ''Unknown'' }}'
    - '{{ value == 128 }}'
    sequence: !input 'remote_button_multiple_press'
7 Likes

Big thanks for that, now I finally can use long press on my many Xiaomi switches :+1:

Hi, Thanks a lot for the BluePrint!

I could import it and create the automation without problem but it throws an error and does not continue to execute. I cant find a reason for this behaviour …

Executed: November 19, 2021, 2:48:19 AM

Error: UndefinedError: ‘dict object’ has no attribute ‘event’