Skip to content

Instantly share code, notes, and snippets.

@itayavra
Last active June 12, 2025 18:01
Show Gist options
  • Select an option

  • Save itayavra/763aef34c920dcb9d5afee3c95f40513 to your computer and use it in GitHub Desktop.

Select an option

Save itayavra/763aef34c920dcb9d5afee3c95f40513 to your computer and use it in GitHub Desktop.
Automate your Tuya with two buttons (TS0021)
blueprint:
name: ZHA - Tuya with two buttons (TS0021)
description: Automate your Tuya with two buttons (TS0021).
domain: automation
input:
tuya_button:
name: Target Tuya button device
selector:
device:
integration: zha
model: TS0021
multiple: false
button_1_short_press:
name: Button 1 - Short (single) press
description: Actions to perform on a short press of button 1.
default: []
selector:
action: {}
button_1_double_press:
name: Button 1 - Double press
description: Actions to perform on a double press of button 1.
default: []
selector:
action: {}
button_1_long_press:
name: Button 1 - Long press
description: Actions to perform on a long press of button 1.
default: []
selector:
action: {}
button_2_short_press:
name: Button 2 - Short (single) press
description: Actions to perform on a short press of button 2.
default: []
selector:
action: {}
button_2_double_press:
name: Button 2 - Double press
description: Actions to perform on a double press of button 2.
default: []
selector:
action: {}
button_2_long_press:
name: Button 2 - Long press
description: Actions to perform on a long press of button 2.
default: []
selector:
action: {}
source_url: https://gist.github.com/itayavra/0439859f8d5f90b440dd3672efd29a6b
mode: restart
trigger:
- platform: event
event_type: zha_event
event_data:
device_id: !input tuya_button
args:
attribute_id: btn_1_pressed
value: 0
id: button_1_short_press_trigger
- platform: event
event_type: zha_event
event_data:
device_id: !input tuya_button
args:
attribute_id: btn_1_pressed
value: 1
id: button_1_double_press_trigger
- platform: event
event_type: zha_event
event_data:
device_id: !input tuya_button
args:
attribute_id: btn_1_pressed
value: 2
id: button_1_long_press_trigger
- platform: event
event_type: zha_event
event_data:
device_id: !input tuya_button
args:
attribute_id: btn_2_pressed
value: 0
id: button_2_short_press_trigger
- platform: event
event_type: zha_event
event_data:
device_id: !input tuya_button
args:
attribute_id: btn_2_pressed
value: 1
id: button_2_double_press_trigger
- platform: event
event_type: zha_event
event_data:
device_id: !input tuya_button
args:
attribute_id: btn_2_pressed
value: 2
id: button_2_long_press_trigger
action:
- choose:
- conditions: '{{ trigger.id == ''button_1_short_press_trigger'' }}'
sequence: !input button_1_short_press
- conditions: '{{ trigger.id == ''button_1_double_press_trigger'' }}'
sequence: !input button_1_double_press
- conditions: '{{ trigger.id == ''button_1_long_press_trigger'' }}'
sequence: !input button_1_long_press
- conditions: '{{ trigger.id == ''button_2_short_press_trigger'' }}'
sequence: !input button_2_short_press
- conditions: '{{ trigger.id == ''button_2_double_press_trigger'' }}'
sequence: !input button_2_double_press
- conditions: '{{ trigger.id == ''button_2_long_press_trigger'' }}'
sequence: !input button_2_long_press
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment