The Tuya Zigbee 4 button (4 gang) light switches are great, except I didn't see a blueprint that worked with ZHA directly. I was only able to find scripts/blueprints that are set up to work via MQTT and the like ... except that's not the tools/tech that I was using, AND the ZHA integration worked perfectly out of the box.
Therefore, I took the wonderful blueprints created by some smart and dedicated people and fixed it up a bit, plus changed it to use ZHA.
Below you will find the script pasted directly, plus a link to my GIST.
GIST link: https://gist.github.com/PiotrKrzyzek/bbe831c42f4fa2f833f0c4fcfc6ea8d6
Home Assistant Blueprint YALM
blueprint:
name: ZHA - Tuya 4-Button Scene Switch
description: Automate your Tuya 4-Button Scene Switch via ZHA.
domain: automation
input:
switch:
name: Tuya Zigbee Switch
description: Tuya 4-Button Scene Switch to use
selector:
device:
integration: zha
model: TS0044
single_press_1:
name: Single Press - Button 1
description: Action to run on button 1 (upper-left) single press
default: []
selector:
action: {}
long_press_1:
name: Hold - Button 1
description: Action to run on button 1 (upper-left) single press
default: []
selector:
action: {}
double_press_1:
name: Double Press - Button 1
description: Action to run on button 1 (upper-left) single press
default: []
selector:
action: {}
single_press_2:
name: Single Press - Button 2
description: Action to run on button 2 (lower-right) single press
default: []
selector:
action: {}
long_press_2:
name: Hold - Button 2
description: Action to run on button 2 (upper-right) single press
default: []
selector:
action: {}
double_press_2:
name: Double Press - Button 2
description: Action to run on button 2 (upper-right) single press
default: []
selector:
action: {}
single_press_3:
name: Single Press - Button 3
description: Action to run on button 3 (lower-left) single press
default: []
selector:
action: {}
long_press_3:
name: Hold - Button 3
description: Action to run on button 3 (lower-left) long press
default: []
selector:
action: {}
double_press_3:
name: Double Press - Button 3
description: Action to run on button 3 (lower-left) long press
default: []
selector:
action: {}
single_press_4:
name: Single Press - Button 4
description: Action to run on button 4 (lower-right) single press
default: []
selector:
action: {}
long_press_4:
name: Hold - Button 4
description: Action to run on button 4 (lower-right) long press
default: []
selector:
action: {}
double_press_4:
name: Double Press - Button 4
description: Action to run on button 4 (lower-right) long press
default: []
selector:
action: {}
source_url: https://gist.githubusercontent.com/PiotrKrzyzek/bbe831c42f4fa2f833f0c4fcfc6ea8d6/raw/98799f1b96f31d24ebf9cebed10b68ab0f506470/tuya_4gang_zha_blueprint9.yaml
mode: parallel
max_exceeded: silent
trigger:
- platform: event
event_type: zha_event
event_data:
device_id: !input switch
action:
- variables:
command: '{{ trigger.event.data.command }}'
cluster_id: '{{ trigger.event.data.cluster_id }}'
endpoint_id: '{{ trigger.event.data.endpoint_id }}'
- choose:
- conditions:
- '{{ command == ''remote_button_short_press'' }}'
- '{{ cluster_id == 6 }}'
- '{{ endpoint_id == 1 }}'
sequence: !input single_press_1
- conditions:
- '{{ command == ''remote_button_short_press'' }}'
- '{{ cluster_id == 6 }}'
- '{{ endpoint_id == 2 }}'
sequence: !input single_press_2
- conditions:
- '{{ command == ''remote_button_short_press'' }}'
- '{{ cluster_id == 6 }}'
- '{{ endpoint_id == 3 }}'
sequence: !input single_press_3
- conditions:
- '{{ command == ''remote_button_short_press'' }}'
- '{{ cluster_id == 6 }}'
- '{{ endpoint_id == 4 }}'
sequence: !input single_press_4
- conditions:
- '{{ command == ''remote_button_double_press'' }}'
- '{{ cluster_id == 6 }}'
- '{{ endpoint_id == 1 }}'
sequence: !input double_press_1
- conditions:
- '{{ command == ''remote_button_double_press'' }}'
- '{{ cluster_id == 6 }}'
- '{{ endpoint_id == 2 }}'
sequence: !input double_press_2
- conditions:
- '{{ command == ''remote_button_double_press'' }}'
- '{{ cluster_id == 6 }}'
- '{{ endpoint_id == 3 }}'
sequence: !input double_press_3
- conditions:
- '{{ command == ''remote_button_double_press'' }}'
- '{{ cluster_id == 6 }}'
- '{{ endpoint_id == 4 }}'
sequence: !input double_press_4
- conditions:
- '{{ command == ''remote_button_long_press'' }}'
- '{{ cluster_id == 6 }}'
- '{{ endpoint_id == 1 }}'
sequence: !input long_press_1
- conditions:
- '{{ command == ''remote_button_long_press'' }}'
- '{{ cluster_id == 6 }}'
- '{{ endpoint_id == 2 }}'
sequence: !input long_press_2
- conditions:
- '{{ command == ''remote_button_long_press'' }}'
- '{{ cluster_id == 6 }}'
- '{{ endpoint_id == 3 }}'
sequence: !input long_press_3
- conditions:
- '{{ command == ''remote_button_long_press'' }}'
- '{{ cluster_id == 6 }}'
- '{{ endpoint_id == 4 }}'
sequence: !input long_press_4
Disclaimers & Additional Info
I did not write the original blueprint I got this from. If you search online for a Home Assistant Tuya 4 gang light switch blueprint, a rather popular one shows up; though that one uses sensors and mqtt events.
Device model setting
To help keep the menu's clean, the blueprint only pulls ZHA devices that are of model number TS0044
. This is ~line 12. Feel free to either change this for your model number or simply remove it.
If your devices aren't showing up in the blueprint
First and foremost, make sure your ZHA integration is both setup & working in Home Assistant AND you have your devices paired & connected through ZHA and Home Assistant.
The item to try would be to remove the model
line.
Changes I made to the blueprint
Overall, other than changing it to work with ZHA I made the following changes:
- Use Parallel mode instead of single. That way, multiple things can run at once 'just in case'.
- Some tiny wording tweaks
- Ensured actions are organized by button rather than by click type
How to install the blueprint
Home Assistant Blueprint button
Manual Installation
Go to the raw
Gist, download the file, then upload it into the blueprints folder, and inside the automations folder for your Home Assistant setup. I use the Home Assistant OS setup, to my path was:
/homeassistant/blueprints/automations/<make folder here here>/tuya_4gang_zha_blueprint.yaml
Example:
/homeassistant/blueprints/automations/piotrkrzyzek/tuya_4gang_zha_blueprint.yaml