ZHA - Sonoff Zigbee Switch

Blueprint to support the Sonoff Zigbee Switch using ZHA.

Supported actions:

  • Single Press
  • Double Press
  • Long Press

Thanks to sipimokus for the help.

Blueprint:

---
blueprint:
  name: Sonoff Zigbee Switch
  description: Automate the Sonoff Zigbee WB01
  domain: automation
  input:
    sonoff_button:
      name: Sonoff Switch
      selector:
        device:
          integration: zha
          manufacturer: eWeLink
          model: WB01
    toggle_action:
      name: Single Press
      description: Action to run on single press
      default: []
      selector:
        action: {}
    on_action:
      name: Double Press
      description: Action to run on double press
      default: []
      selector:
        action: {}
    off_action:
      name: Long Press
      description: Action to run on long press
      default: []
      selector:
        action: {}

mode: single
max_exceeded: silent

trigger:
- platform: event
  event_type: zha_event
  event_data:
    device_id: !input sonoff_button

variables:
  toggle_action: !input toggle_action
  on_action: !input on_action
  off_action: !input off_action

action:
- variables:
    command: '{{ trigger.event.data.command }}'
- choose:
  - conditions:
    - '{{ command == "toggle" }}'
    sequence: !input toggle_action
  - conditions:
    - '{{ command == "on" }}'
    sequence: !input on_action
  - conditions:
    - '{{ command == "off" }}'
    sequence: !input off_action
16 Likes

Thank you very much, it’s a cool Blueprint! :+1:
But it’s have a little problem with the default actions handling. I changed little bit the code and fixed it:

---
blueprint:
  name: Sonoff Zigbee Button
  description: Automate the Sonoff Zigbee WB01
  domain: automation
  input:
    sonoff_button:
      name: Sonoff Button
      selector:
        device:
          integration: zha
          manufacturer: eWeLink
          model: WB01
    toggle_action:
      name: Single Press
      description: Action to run on single press
      default: []
      selector:
        action: {}
    on_action:
      name: Double Press
      description: Action to run on double press
      default: []
      selector:
        action: {}
    off_action:
      name: Long Press
      description: Action to run on long press
      default: []
      selector:
        action: {}

mode: single
max_exceeded: silent

trigger:
- platform: event
  event_type: zha_event
  event_data:
    device_id: !input sonoff_button

variables:
  toggle_action: !input toggle_action
  on_action: !input on_action
  off_action: !input off_action

action:
- variables:
    command: '{{ trigger.event.data.command }}'
- choose:
  - conditions:
    - '{{ command == "toggle" }}'
    sequence: !input toggle_action
  - conditions:
    - '{{ command == "on" }}'
    sequence: !input on_action
  - conditions:
    - '{{ command == "off" }}'
    sequence: !input off_action

2 Likes

Nice one! I’ll update right away.

Hi, Thanks for this blueprint. It’s working good. I am a beginner and I just want your help.

For example, when I single press the button, it will switch on my rice cooker. And I want the rice cooker to switch off automatically after 50 mn. For that, I already have an automation with trigger. Here is the code:

platform: state
entity_id: switch.sonoff_cooker
to: 'on'
for: '0:00:50'

At the end, I have an action like this

service: switch.turn_off
data: {}
entity_id: switch.sonoff_cooker

I am trying to do the same thing with your blueprint. But there is no “trigger” option. Can you please help me to do this ?

Thanks

Hey :slight_smile: I’m glad the blueprint is working for you.

I’m really not an expert on automation, but to achieve what you want I would probably do it all in the one action. Turn on the cooker, then set a delay of 50 mins, then turn it off.

  action:
  # TURN ON
  - service: switch.turn_on
    data: {}
    entity_id: switch.rice_cooker

  # WAIT 50m
  - delay: '00:50:00'

  # TURN OFF
  - service: switch.turn_off
    data: {}
    entity_id: switch.rice_cooker
1 Like

Thanks for sharing, Have just used this so tidy up an automation.
:clap: :clap:

Hi Gary,

Sorry for the late reply. Tried your solution and it’s working good. :slight_smile:

Thanks a lot.

Hello,

I have sonoff zigbee SNZB-01.
I tried adding your blueprint to to the blueprint folder. But when I restart HA, I get automation error, and the whole automation section dissapears unless I delete the blueprint.
HELP!

Hello Everyone !

First, thanks for this blueprint which exactly what i’m looking for.
I have a sonoff switch which seems to be correctly recognize by HA :
image

But when i try to create an automation with the blueprint, i’m not able to select the switch.
It tells me that i do not have a Sonoff Zigbee Switch :

Do you have any idea of the reason why ?
Thank you for any help you could provide.

I think that the reason why i’m not seeing any devices is due to the fact that i’m using Foscom Deconz as an integration and not ZHA. :frowning_face:
But i don’t know which label i have to use instead of “zha” for the “integration”.
Problem solved by replacing “ZHA” par “deconz”.

Hello, I have thaty one but connected via mqtt, how can I use you blueprint? Thank you2021-03-28_04-30-00

Do I have to have a Sonoff bridge or a Sonoff dongle for the Sonoff Zigbee Switch to work with ZHA or can I use my existing ZHA setup with a Nortek GoControl HUSBZB-1 controller?

Hello GaryKrige, I’m brand new here and have no idea about the whole blueprint topic yet. Is it ok if I use your blueprint as a template for another device because I can not find any suitable template for the “Osram Switch Mini” here. Thanks

If for some reason your device name, (like mine) is WB-01 instead of WB01.

Use this`

1 Like

Message malformed: Missing input sonoff_button

hey man i get that error after trying to save the blueprint in my HA. What should I do next?

Hi @garykrige Thanks for creating this.

I’m using the single press to trigger an automation like the rice cooker one above (turn on, delay, turn off). But it seems like while that action is running (which because of the delay is quite long), the other two modes (double press, long press) don’t work. Is this what’s supposed to happen? And if so, is there any way to change it?

Thank you for the blueprint, this is awesome and works great !!

Thank you for this, it works really well.
Do you think it’s possible to make it so that a single button press will change the brightness of a light globe depending on the current brightness/state?

Not sure if it’s a good idea, but I’d like to experiment with 2 control options:

  • Make it so that a single press turn it ON at 100% brightness if it is currently OFF (toggle mode turns it on at the whatever brightness was set when it was switched off)
  • make it so that successive button presses will step through ON, 66%, 33%, OFF

I’m having trouble getting my head around the automation in home assistant.

I’m here just to give my thanks for your work! :smiley:

you guys are awesome!! thank you very very much - works perfectly!!