-
-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for SONOFF SNZB-01 (#376)
* Add support for SONOFF SNZB-01 * add note for long press, bump versions to 2022.07.30 Co-authored-by: Matteo Agnoletto <[email protected]>
- Loading branch information
1 parent
ab6d6bd
commit a2756dc
Showing
10 changed files
with
364 additions
and
4 deletions.
There are no files selected for viewing
205 changes: 205 additions & 0 deletions
205
blueprints/controllers/sonoff_snzb01/sonoff_snzb01.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.30 | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.