Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SONOFF SNZB-01 #376

Merged
merged 2 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
205 changes: 205 additions & 0 deletions blueprints/controllers/sonoff_snzb01/sonoff_snzb01.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# Blueprint metadata
blueprint:
name: Controller - SONOFF SNZB-01 Wireless Switch
description: |
# Controller - SONOFF SNZB-01 Wireless Switch

Controller automation for executing any kind of action triggered by the provided SONOFF SNZB-01 Wireless Switch.
Supports deCONZ, ZHA, Zigbee2MQTT.

Automations created with this blueprint can be connected with one or more [Hooks](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/hooks) supported by this controller.
Hooks allow to easily create controller-based automations for interacting with media players, lights, covers and more.
See the list of [Hooks available for this controller](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/controllers/sonoff_snzb01#available-hooks) for additional details.

📕 Full documentation regarding this blueprint is available [here](https://epmatt.github.io/awesome-ha-blueprints/docs/blueprints/controllers/sonoff_snzb01).

🚀 This blueprint is part of the **[Awesome HA Blueprints](https://epmatt.github.io/awesome-ha-blueprints) project**.

ℹ️ Version 2022.07.22
source_url: https://github.com/EPMatt/awesome-ha-blueprints/blob/main/blueprints/controllers/sonoff_snzb01/sonoff_snzb01.yaml
domain: automation
input:
integration:
name: (Required) Integration
description: Integration used for connecting the remote with Home Assistant. Select one of the available values.
selector:
select:
options:
- deCONZ
- ZHA
- Zigbee2MQTT
controller_device:
name: (deCONZ, ZHA) Controller Device
description: The controller device to use for the automation. Choose a value only if the remote is integrated with deCONZ, ZHA.
default: ''
selector:
device:
controller_entity:
name: (Zigbee2MQTT) Controller Entity
description: The action sensor of the controller to use for the automation. Choose a value only if the remote is integrated with Zigbee2MQTT.
default: ''
selector:
entity:
domain: sensor
helper_last_controller_event:
name: (Required) Helper - Last Controller Event
description: Input Text used to store the last event fired by the controller. You will need to manually create a text input entity for this, please read the blueprint Additional Notes for more info.
default: ''
selector:
entity:
domain: input_text
# inputs for custom actions
action_button_short:
name: (Optional) Button short press
description: Action to run on short button press.
default: []
selector:
action:
action_button_long:
name: (Optional) Button long press
description: Action to run on long button press.
default: []
selector:
action:
action_button_double:
name: (Optional) Button double press
description: Action to run on double button press.
default: []
selector:
action:
# helpers used to properly recognize the remote button events
helper_debounce_delay:
name: (Optional) Helper - Debounce delay
description:
Delay used for debouncing RAW controller events, by default set to 0. A value of 0 disables the debouncing feature. Increase this value if you notice custom actions or linked Hooks running multiple times when interacting with the device. When the controller needs to be debounced,
usually a value of 100 is enough to remove all duplicate events.
default: 0
selector:
number:
min: 0
max: 1000
unit_of_measurement: milliseconds
mode: box
step: 10
# Automation schema
variables:
# convert input tags to variables, to be used in templates
integration: !input integration
helper_last_controller_event: !input helper_last_controller_event
helper_debounce_delay: !input helper_debounce_delay
# integration id used to select items in the action mapping
integration_id: '{{ integration | lower }}'
# mapping between actions and integrations
actions_mapping:
deconz:
button_short: ['1002']
button_long: ['1001']
button_double: ['1004']
zha:
button_short: [toggle]
button_long: ['off']
button_double: ['on']
zigbee2mqtt:
button_short: [single]
button_long: [long]
button_double: [double]
# pre-choose actions for buttons based on configured integration
# no need to perform this task at automation runtime
button_short: '{{ actions_mapping[integration_id]["button_short"] }}'
button_long: '{{ actions_mapping[integration_id]["button_long"] }}'
button_double: '{{ actions_mapping[integration_id]["button_double"] }}'
# build data to send within a controller event
controller_entity: !input controller_entity
controller_device: !input controller_device
controller_id: '{% if integration_id=="zigbee2mqtt" %}{{controller_entity}}{% else %}{{controller_device}}{% endif %}'
mode: restart
max_exceeded: silent
trigger:
# trigger for zigbee2mqtt
- platform: event
event_type: state_changed
event_data:
entity_id: !input controller_entity
# trigger for other integrations
- platform: event
event_type:
- deconz_event
- zha_event
event_data:
device_id: !input controller_device
condition:
- condition: and
conditions:
# check that the button event is not empty
- >-
{%- set trigger_action -%}
{%- if integration_id == "zigbee2mqtt" -%}
{{ trigger.event.data.new_state.state }}
{%- elif integration_id == "deconz" -%}
{{ trigger.event.data.event }}
{%- elif integration_id == "zha" -%}
{{ trigger.event.data.command }}{{"_" if trigger.event.data.args|length > 0}}{{ trigger.event.data.args|join("_") }}
{%- endif -%}
{%- endset -%}
{{ trigger_action not in ["","None"] }}
# only for zigbee2mqtt, check if the event is relative to a real state change, and not only some minor changes in the sensor attributes
# this is required since multiple state_changed events are fired for a single button press, with the result of the automation being triggered multiple times
- '{{ integration_id != "zigbee2mqtt" or trigger.event.data.new_state.state != trigger.event.data.old_state.state }}'
action:
# debouncing - when automation is triggered multiple times, the last automation run is the one which completes execution, due to mode restart
# therefore previous runs must wait for the debounce delay before executing any other action
# if the delay expires and the automation is still running it means it's the last run and execution can continue
- delay:
milliseconds: !input helper_debounce_delay
# extract button event from the trigger
# provide a single string value to check against
- variables:
trigger_action: >-
{%- if integration_id == "zigbee2mqtt" -%}
{{ trigger.event.data.new_state.state }}
{%- elif integration_id == "deconz" -%}
{{ trigger.event.data.event }}
{%- elif integration_id == "zha" -%}
{{ trigger.event.data.command }}{{"_" if trigger.event.data.args|length > 0}}{{ trigger.event.data.args|join("_") }}
{%- endif -%}
trigger_delta: '{{ (as_timestamp(now()) - as_timestamp((states(helper_last_controller_event) | from_json).last_triggered if helper_last_controller_event is not none and (states(helper_last_controller_event) | regex_match("^\{(\".*\": \".*\"(, )?)*\}$")) else "1970-01-01 00:00:00")) * 1000 }}'
# update helper
- service: input_text.set_value
data:
entity_id: !input helper_last_controller_event
value: '{{ {"trigger_action":trigger_action,"last_triggered":now()|string} | to_json }}'
# choose the sequence to run based on the received button event
- choose:
- conditions: '{{ trigger_action | string in button_short }}'
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: button_short
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_short
- conditions: '{{ trigger_action | string in button_long }}'
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: button_long
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_long
- conditions: '{{ trigger_action | string in button_double }}'
sequence:
# fire the event
- event: ahb_controller_event
event_data:
controller: '{{ controller_id }}'
action: button_double
# run the custom action
- choose:
- conditions: []
sequence: !input action_button_double
5 changes: 5 additions & 0 deletions blueprints/hooks/cover/cover.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ blueprint:
- IKEA E1743 TRÅDFRI On/Off Switch & Dimmer
- IKEA E1766 TRÅDFRI Open/Close Remote
- IKEA E1812 TRÅDFRI Shortcut button
- SONOFF SNZB-01 Wireless Switch
- Xiaomi WXCJKG11LM Aqara Opple 2 button remote
- Xiaomi WXCJKG12LM Aqara Opple 4 button remote
- Xiaomi WXCJKG12LM Aqara Opple 4 button remote (#2)
Expand Down Expand Up @@ -82,6 +83,10 @@ variables:
open_cover: button_short
stop_cover_all: button_long
close_cover: button_double
SONOFF SNZB-01 Wireless Switch:
open_cover: button_short
stop_cover_all: button_long
close_cover: button_double
Xiaomi WXCJKG11LM Aqara Opple 2 button remote:
open_cover: button_1_short
open_cover_tilt: button_1_long
Expand Down
4 changes: 4 additions & 0 deletions blueprints/hooks/light/light.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ blueprint:
- Philips 324131092621 Hue Dimmer switch
- Philips 8718699693985 Hue Smart Button
- Philips 929002398602 Hue Dimmer switch v2
- SONOFF SNZB-01 Wireless Switch
- Xiaomi WXCJKG11LM Aqara Opple 2 button remote
- Xiaomi WXCJKG12LM Aqara Opple 4 button remote
- Xiaomi WXCJKG12LM Aqara Opple 4 button remote (#2)
Expand Down Expand Up @@ -261,6 +262,9 @@ variables:
brightness_up_repeat: button_up_long
brightness_down: button_down_short
brightness_down_repeat: button_down_long
SONOFF SNZB-01 Wireless Switch:
toggle: button_short
color_up: button_double
Xiaomi WXCJKG11LM Aqara Opple 2 button remote:
turn_on: button_1_short
brightness_up_repeat: button_1_long
Expand Down
5 changes: 5 additions & 0 deletions blueprints/hooks/media_player/media_player.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ blueprint:
- Philips 324131092621 Hue Dimmer switch
- Philips 8718699693985 Hue Smart Button
- Philips 929002398602 Hue Dimmer switch v2
- SONOFF SNZB-01 Wireless Switch
- Xiaomi WXCJKG11LM Aqara Opple 2 button remote
- Xiaomi WXCJKG12LM Aqara Opple 4 button remote
- Xiaomi WXCJKG12LM Aqara Opple 4 button remote (#2)
Expand Down Expand Up @@ -161,6 +162,10 @@ variables:
volume_up_repeat: button_up_long
volume_down: button_down_short
volume_down_repeat: button_down_long
SONOFF SNZB-01 Wireless Switch:
play_pause: button_short
stop: button_long
next_track: button_double
Xiaomi WXCJKG11LM Aqara Opple 2 button remote:
volume_up: button_1_short
volume_up_repeat: button_1_long
Expand Down
3 changes: 2 additions & 1 deletion website/docs/blueprints/controllers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You can integrate Controllers with [Hooks](hooks) and create controller-based au

### Supported Controllers

Currently **15** devices are supported from **4** different vendors.
Currently **16** devices are supported from **4** different vendors.

_Can't find the controller you're looking for in this list? [Submit a new blueprint proposal for your controller here.](https://github.com/EPMatt/awesome-ha-blueprints/issues/new?assignees=&labels=blueprint%2Cnew%2Ccontroller&template=new-controller-support.md&title=New+Controller+-+)_

Expand All @@ -32,6 +32,7 @@ _Can't find the controller you're looking for in this list? [Submit a new bluepr
| Philips | [324131092621](/docs/blueprints/controllers/philips_324131092621) | Philips 324131092621 Hue Dimmer switch | deCONZ,ZHA,Zigbee2MQTT | <Image>![philips_324131092621](/img/controllers/philips_324131092621.png)</Image> |
| Philips | [8718699693985](/docs/blueprints/controllers/philips_8718699693985) | Philips 8718699693985 Hue Smart Button | deCONZ,ZHA | <Image>![philips_8718699693985](/img/controllers/philips_8718699693985.png)</Image> |
| Philips | [929002398602](/docs/blueprints/controllers/philips_929002398602) | Philips 929002398602 Hue Dimmer switch v2 | ZHA,Zigbee2MQTT | <Image>![philips_929002398602](/img/controllers/philips_929002398602.png)</Image> |
| SONOFF | [SNZB-01](/docs/blueprints/controllers/sonoff_snzb01) | SONOFF SNZB-01 Wireless Switch | deCONZ,ZHA,Zigbee2MQTT | <Image>![sonoff_snzb01](/img/controllers/sonoff_snzb01.png)</Image> |
| Xiaomi | [WXCJKG11LM](/docs/blueprints/controllers/xiaomi_wxcjkg11lm) | Xiaomi WXCJKG11LM Aqara Opple 2 button remote | deCONZ,ZHA,Zigbee2MQTT | <Image>![xiaomi_wxcjkg11lm](/img/controllers/xiaomi_wxcjkg11lm.png)</Image> |
| Xiaomi | [WXCJKG12LM](/docs/blueprints/controllers/xiaomi_wxcjkg12lm) | Xiaomi WXCJKG12LM Aqara Opple 4 button remote | deCONZ,ZHA,Zigbee2MQTT | <Image>![xiaomi_wxcjkg12lm](/img/controllers/xiaomi_wxcjkg12lm.png)</Image> |
| Xiaomi | [WXCJKG13LM](/docs/blueprints/controllers/xiaomi_wxcjkg13lm) | Xiaomi WXCJKG13LM Aqara Opple 6 button remote | deCONZ,ZHA,Zigbee2MQTT | <Image>![xiaomi_wxcjkg13lm](/img/controllers/xiaomi_wxcjkg13lm.png)</Image> |
Expand Down
Loading