Instantly share code, notes, and snippets.
Last active
September 4, 2025 07:11
-
Star
1
(1)
You must be signed in to star a gist -
Fork
1
(1)
You must be signed in to fork a gist
-
Save rdeangel/bf0019c7d63023cd4decbba44044bc64 to your computer and use it in GitHub Desktop.
Zigbee2MQTT - Tuya 4-Button Switch (MQTT Subscribe Any - Filters Multiple Devices) - rdeangel
This file contains hidden or 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
blueprint: | |
name: Zigbee2MQTT - Tuya 4-Button Switch (MQTT Subscribe Any - Filters Multiple Devices) - rdeangel | |
description: "Blueprint Version: 11-01-25)\n | |
Blueprint Name: Zigbee2MQTT - Tuya 4-Button Switch (MQTT Subscribe Any - Filters Multiple Devices) - rdeangel\n\n | |
This blueprint subscribes to all Z2M Action topic `zigbee2mqtt/+/action` | |
and then filters the correct MQTT topic.\n | |
It takes multiple dropdown as the main filter condition to decide if the trigger should be considered for actions or ignored.\n | |
The fact that the automation triggers even when other mqtt devices actions are received it's not ideal, it does however | |
allow for multiple buttons to be driven by the same automation if that's what you are looking for.\n | |
Also If you want minor differences between the multiple defined buttons you can exclude certain actions within the automation using the `triggered by` conditions. | |
Please NOTE: if you don't need to mirror multiple buttons use the `device` trigger blueprint instead." | |
domain: automation | |
input: | |
mode: | |
name: Automation Modes | |
description: https://www.home-assistant.io/docs/automation/modes/ | |
default: parallel | |
selector: | |
select: | |
mode: dropdown | |
options: | |
- single | |
- restart | |
- queued | |
- parallel | |
multiple: false | |
custom_value: false | |
sort: false | |
zigbee_device: | |
name: Zigbee Devices - Tuya TS0044 4 Buttons (and alike) | |
description: Select the correct Zigbee devices to use. | |
selector: | |
device: | |
integration: mqtt | |
multiple: true | |
button_one_short_press: | |
name: Single Press - Button 1 | |
description: Action to run on Button 1 - Single Press | |
default: [] | |
selector: | |
action: {} | |
button_one_double_press: | |
name: Dougle Press - Button 1 | |
description: Action to run on Button 1 - Dougle Press | |
default: [] | |
selector: | |
action: {} | |
button_one_long_press: | |
name: Long Press - Button 1 | |
description: Action to run on Button 1 - Long Press | |
default: [] | |
selector: | |
action: {} | |
button_two_short_press: | |
name: Single Press - Button 2 | |
description: Action to run on Button 2 - Single Press | |
default: [] | |
selector: | |
action: {} | |
button_two_double_press: | |
name: Dougle Press - Button 2 | |
description: Action to run on Button 2 - Dougle Press | |
default: [] | |
selector: | |
action: {} | |
button_two_long_press: | |
name: Long Press - Button 2 | |
description: Action to run on Button 2 - Long Press | |
default: [] | |
selector: | |
action: {} | |
button_three_short_press: | |
name: Single Press - Button 3 | |
description: Action to run on Button 3 - Single Press | |
default: [] | |
selector: | |
action: {} | |
button_three_double_press: | |
name: Dougle Press - Button 3 | |
description: Action to run on Button 3 - Dougle Press | |
default: [] | |
selector: | |
action: {} | |
button_three_long_press: | |
name: Long Press - Button 3 | |
description: Action to run on Button 3 - Long Press | |
default: [] | |
selector: | |
action: {} | |
button_four_short_press: | |
name: Single Press - Button 4 | |
description: Action to run on Button 4 - Single Press | |
default: [] | |
selector: | |
action: {} | |
button_four_double_press: | |
name: Dougle Press - Button 4 | |
description: Action to run on Button 4 - Dougle Press | |
default: [] | |
selector: | |
action: {} | |
button_four_long_press: | |
name: Long Press - Button 4 | |
description: Action to run on Button 4 - Long Press | |
default: [] | |
selector: | |
action: {} | |
source_url: https://gist.github.com/rdeangel/bf0019c7d63023cd4decbba44044bc64 | |
mode: !input mode | |
max_exceeded: silent | |
trigger: | |
- platform: mqtt | |
topic: zigbee2mqtt/+/action | |
variables: | |
device_names: !input zigbee_device | |
expected_topics: > | |
{% for device_name in device_names %} | |
zigbee2mqtt/{{ device_attr(device_name, 'name') }}/action | | |
{% endfor %}null | |
condition: | |
- condition: template | |
value_template: "{{ trigger.topic in expected_topics }}" | |
action: | |
- variables: | |
command: "{{ trigger.payload }}" | |
- choose: | |
- conditions: | |
- "{{ command == '1_single' }}" | |
sequence: !input button_one_short_press | |
- conditions: | |
- "{{ command == '2_single' }}" | |
sequence: !input button_two_short_press | |
- conditions: | |
- "{{ command == '3_single' }}" | |
sequence: !input button_three_short_press | |
- conditions: | |
- "{{ command == '4_single' }}" | |
sequence: !input button_four_short_press | |
- conditions: | |
- "{{ command == '1_double' }}" | |
sequence: !input button_one_double_press | |
- conditions: | |
- "{{ command == '2_double' }}" | |
sequence: !input button_two_double_press | |
- conditions: | |
- "{{ command == '3_double' }}" | |
sequence: !input button_three_double_press | |
- conditions: | |
- "{{ command == '4_double' }}" | |
sequence: !input button_four_double_press | |
- conditions: | |
- "{{ command == '1_hold' }}" | |
sequence: !input button_one_long_press | |
- conditions: | |
- "{{ command == '2_hold' }}" | |
sequence: !input button_two_long_press | |
- conditions: | |
- "{{ command == '3_hold' }}" | |
sequence: !input button_three_long_press | |
- conditions: | |
- "{{ command == '4_hold' }}" | |
sequence: !input button_four_long_press |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment