ZHA Sonoff Button (press, double press, hold actions)

This is for programming Sonoff’s SNZB-01 button

Select the button you wish to setup and then select the actions you want performed for each of the 3 button actions. Single press is required, double and hold can optionally be defined.

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

blueprint:
  name: Sonoff Zigbee Button
  description: Setup actions for three functions of the SONOFF Zigbee button with
    Press, Double Press, and Hold.
  domain: automation
  input:
    button_id:
      name: Button
      description: The button to configure.
      selector:
        device:
          manufacturer: eWeLink
          model: WB01
    press_action:
      name: Press Action
      description: Action to perform on Press.
      default: []
      selector:
        action: {}
    double_press_action:
      name: Double Press Action
      description: Action to perform on Double Press.
      default: []
      selector:
        action: {}
    hold_action:
      name: Hold Action
      description: Action to perform on Hold.
      default: []
      selector:
        action: {}
  source_url: https://github.com/apollo1220/blueprints/blob/main/sonoff_zigbee_button.yaml
variables:
  button_id: !input 'button_id'
  press_action: !input 'press_action'
  double_press_action: !input 'double_press_action'
  hold_action: !input 'hold_action'
trigger:
- platform: event
  event_type: zha_event
  event_data:
    device_id: !input 'button_id'
action:
- choose:
  - conditions:
    - condition: template
      value_template: '{{ trigger.event.data.command == "toggle" }}'
    sequence: !input 'press_action'
  - conditions:
    - condition: template
      value_template: '{{ trigger.event.data.command == "on" }}'
    sequence: !input 'double_press_action'
  - conditions:
    - condition: template
      value_template: '{{ trigger.event.data.command == "off" }}'
    sequence: !input 'hold_action'

Edit: Made double and hold optional

15 Likes

Thank you my friend. Your Blueprint makes controlling multiple buttons super simple. :+1:

Would you be able to make the actions so that they aren’t all required. Don’t need to have all three actions for everything. Thank you.

Great idea. I’ll look into it

Done. Updated the blueprint making double and hold actions optional.

1 Like

Unsure of how to proceed to setup Double Press Actions now?

1 Like

Merged your PR and updated code in original post

The Blueprint worked like a charm out of the box. Thanks for sharing!!!

1 Like

Hello, is it possible to adapt it for deconz?
Thank you

I use deconz through ZHA and this is working for that. I’m not familiar with the deconz integration, but if you want to fork the blueprint and adapt it, feel free.

Hi
I’ve trying to use this Blueprint and so far I manged to get 1 Sonoff button working.
Is there anyway to use this Blueprint with other Zigbee Single Buttons like the IKEA Tradfri type E1812 or Xiaomi Mi Wireless Switch?
Thanks in adavance
All the Best

The button_id input is limited to only the Sonoff button. If you want to modify the blueprint locally to remove that restriction you can, it’s just the manufacturer and model specified there. But I can’t guarantee it will work with other buttons as they may have different event setups for their button presses.

I’ve imported this blueprint, but i’m not able to setup the button, it says: no matching devices found (in the pull down)

What to do?

It will only find Sonoff SNZB-01 buttons which have been connected through ZHA. Is that the case for the device you are trying to setup?

in my case it is via zigbee2mqtt. This is not supported?

Correct. Only through ZHA is supported by this blueprint. It is triggered by the zha_event which would not be fired by zigbee2mqtt, so it would never register a button press. (That’s why ZHA is in the title and tagged :relaxed:)

I’m a newbie, so i’m not familair wiht ZHA and the difference between zigbee2mqtt. But thanks anyway :slight_smile:

Thank you for your input. The Sonoff buttons are working great. I will try to modify the Ikea and Xiaomi buttons. Thank you for your contributions. All the Best.

1 Like

Hello, sorry for my English.
i tried to use your project but i can’t see any devices.
I have 2 touch sonoff which are regularly recognized by home assistant as sensors but I can’t see them in the project.
what should i do to see them?

Are they connected to home assistant using ZHA? Because only the ZHA integration is supported by this blueprint.

Secondly you mention sonoff touch, maybe that’s just bad english, but if it really is a touch sensitive Sonoff device then this wouldn’t pick it up because it is specifically looking for the button. Specifically the SNZB-01.