ZHA - Sonoff Zigbee Switch

Tags: #<Tag:0x00007f325b99e168> #<Tag:0x00007f325b99e078> #<Tag:0x00007f325b99df88>

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
6 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

1 Like

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

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.