Hello,
This is a blueprint for Tuya 4-button switch TS004F edition, for those using ZHA, in oposition to the blueprint proposed by @edememinov for Zigbee2MQTT here (Z2M - TS004F Tuya 4-Gang Switch blueprint).
→ EDITED on May 21st 2022:
All credits to @khvej8 who published this blueprint in the comments of the above blueprint for Z2M (https://community.home-assistant.io/t/z2m-ts004f-tuya-4-gang-switch-blueprint/314233/27) and to @Dunaar who shared with us a brilliant hack to solve an issue with this device after upgrading to HA 2022.4.3.
ATTENTION: Keep in mind that for this blueprint to work, you need to do a little manipulation on your switch as proposed by @Dunaar: press top-right button together with bottom-right button until bottom 4 (bottom left) blinks.
If you are trying to fix this automation after HA 2022.4.3 broke it, before applying the hack above, you will need to remove the existing TS0004 device and pair it again (press left-bottom button for 10s until 4 buttons flash).
This new version probably makes the following paragraph obsolete as now we have 12 events with ZHA!
Please note that currently in ZHA, it detect less events than the Z2M version (see the whole discussion here: https://github.com/zigpy/zha-device-handlers/pull/969).
Keep in mind that I’m by no means a TS004F or blueprint specialist. I’m creating this as an attempt to to import it straight as a blueprint.
blueprint:
name: ZHA - Tuya 4-Button Switch
description: Automate your Tuya 4-Button Switch using ZHA events.
domain: automation
input:
tuya_4button_switch:
name: Tuya 4-Button Switch
description: Tuya 4-Button Switch to use
selector:
device:
integration: zha
manufacturer: _TZ3000_xabckq1v
model: TS004F
button_1_click:
name: Button 1 click
description: Action to run on button upper-left single press
default: []
selector:
action: {}
button_1_double_click:
name: Button 1 double-click
description: Action to run on button upper-left double press
default: []
selector:
action: {}
button_1_long_press:
name: Button 1 long press
description: Action to run on button upper-left long press
default: []
selector:
action: {}
button_2_click:
name: Button 2 click
description: Action to run on button upper-right single press
default: []
selector:
action: {}
button_2_double_click:
name: Button 2 double-click
description: Action to run on button upper-right double press
default: []
selector:
action: {}
button_2_long_press:
name: Button 2 long press
description: Action to run on button upper-right long press
default: []
selector:
action: {}
button_3_click:
name: Button 3 click
description: Action to run on button lower-left single press
default: []
selector:
action: {}
button_3_double_click:
name: Button 3 double-click
description: Action to run on button lower-right double press
default: []
selector:
action: {}
button_3_long_press:
name: Button 3 long press
description: Action to run on button lower-left long press
default: []
selector:
action: {}
button_4_click:
name: Button 4 click
description: Action to run on button lower-right single press
default: []
selector:
action: {}
button_4_double_click:
name: Button 4 double-click
description: Action to run on button lower-right double press
default: []
selector:
action: {}
button_4_long_press:
name: Long Press Dim-down
description: Action to run on button lower-right long press
default: []
selector:
action: {}
mode: single
max_exceeded: silent
trigger:
- platform: event
event_type: zha_event
event_data:
device_id: !input 'tuya_4button_switch'
action:
- variables:
command: '{{ trigger.event.data.command }}'
endpoint_id: '{{ trigger.event.data.endpoint_id }}'
- choose:
- conditions: '{{ false }}'
sequence:
- service: notify.persistent_notification
data:
message: '{{ endpoint_id }}'
title: '{{ command }}'
- conditions: '{{ command == ''remote_button_short_press'' }}'
sequence:
- choose:
- conditions: '{{ endpoint_id == 1 }}'
sequence: !input 'button_1_click'
- conditions: '{{ endpoint_id == 2 }}'
sequence: !input 'button_2_click'
- conditions: '{{ endpoint_id == 3 }}'
sequence: !input 'button_3_click'
- conditions: '{{ endpoint_id == 4 }}'
sequence: !input 'button_4_click'
- conditions: '{{ command == ''remote_button_double_press'' }}'
sequence:
- choose:
- conditions: '{{ endpoint_id == 1 }}'
sequence: !input 'button_1_double_click'
- conditions: '{{ endpoint_id == 2 }}'
sequence: !input 'button_2_double_click'
- conditions: '{{ endpoint_id == 3 }}'
sequence: !input 'button_3_double_click'
- conditions: '{{ endpoint_id == 4 }}'
sequence: !input 'button_4_double_click'
- conditions: '{{ command == ''remote_button_long_press'' }}'
sequence:
- choose:
- conditions: '{{ endpoint_id == 1 }}'
sequence: !input 'button_1_long_press'
- conditions: '{{ endpoint_id == 2 }}'
sequence: !input 'button_2_long_press'
- conditions: '{{ endpoint_id == 3 }}'
sequence: !input 'button_3_long_press'
- conditions: '{{ endpoint_id == 4 }}'
sequence: !input 'button_4_long_press'