ZHA - Mijia Wireless Switch

Blueprint to support the Mijia Wireless Switch and allow it to perform up to five actions.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

The Mijia Wireless Switch supports:

  • Single press
  • Double press
  • Triple press
  • Quadruple press
  • Furious press (5 or more)

Blueprint screen:

Blueprint to import:

blueprint:
  name: ZHA - Mijia Wireless Switch
  description: 'Perform actions with the Mijia Wireless Switch.

    You can set functions for single press, double press, triple press, quadruple press and furious (5 or more presses). This allows you to assign, 
    e.g., a scene or anything else.'

  domain: automation
  input:
    remote:
      name: Remote
      description: LUMI Button to use
      selector:
        device:
          integration: zha
          manufacturer: LUMI
          model: lumi.sensor_switch
    single_press:
      name: Single press
      description: Action to run on single press
      default: []
      selector:
        action: {}
    double_press:
      name: Double press
      description: Action to run on double press
      default: []
      selector:
        action: {}
    triple_press:
      name: Triple press
      description: Action to run on triple press
      default: []
      selector:
        action: {}
    quadruple_press:
      name: Quadruple press
      description: Action to run on quadruple press
      default: []
      selector:
        action: {}
    furious_press:
      name: Furious press
      description: Action to run on furious press
      default: []
      selector:
        action: {}
  source_url: https://gist.github.com/seamus65/c35766e14c54594db8a7fd5b1fc0d971
mode: restart
max_exceeded: silent
trigger:
- platform: event
  event_type: zha_event
  event_data:
    device_id: !input 'remote'
action:
- variables:
    command: '{{ trigger.event.data.command }}'
    cluster_id: '{{ trigger.event.data.cluster_id }}'
    endpoint_id: '{{ trigger.event.data.endpoint_id }}'
    args: '{{ trigger.event.data.args.click_type }}'
- choose:
  - conditions:
    - '{{ command == "click" }}'
    - '{{ cluster_id == 6 }}'
    - '{{ endpoint_id == 1 }}'
    - '{{ args == "single" }}'
    sequence: !input 'single_press'
  - conditions:
    - '{{ command == "click" }}'
    - '{{ cluster_id == 6 }}'
    - '{{ endpoint_id == 1 }}'
    - '{{ args == "double" }}'
    sequence: !input 'double_press'
  - conditions:
    - '{{ command == "click" }}'
    - '{{ cluster_id == 6 }}'
    - '{{ endpoint_id == 1 }}'
    - '{{ args == "triple" }}'
    sequence: !input 'triple_press'
  - conditions:
    - '{{ command == "click" }}'
    - '{{ cluster_id == 6 }}'
    - '{{ endpoint_id == 1 }}'
    - '{{ args == "quadruple" }}'
    sequence: !input 'quadruple_press'
  - conditions:
    - '{{ command == "click" }}'
    - '{{ cluster_id == 6 }}'
    - '{{ endpoint_id == 1 }}'
    - '{{ args == "furious" }}'
    sequence: !input 'furious_press'

1 Like

Thanks for this! I would just suggest changing mode to “queued” instead of “restart”. Since the button sends a few other events right after the “single”, “double”, etc ones, a second automation will start right after the desired one, and with the “restart” mode the first automation is canceled. This is usually not an issue if the automation has a single action for each event, but if it has two actions, the second usually does not run.