Z2M - TS004F Tuya 4-Gang Switch blueprint

For anyone who’s running into issues with this not working, I finally got mine to work so figured I’d share:

  • The choose condition seems to be the primary point where it gets “weird”
  • I had to replace a bunch of ‘’ (single quotes, doubled up) with ’ to get it to parse correctly
    • From the file perspective:
      '{{ topic.split('/')[1].replace('/', '') == deviceName.split(' ')[0] }}
    • From the tracing perspective:
      '{{ topic.split(''/'')[1].replace(''/'', '''') == deviceName.split('' '')[0] }}'
  • Once that’s done keep in mind that the deviceName lookup (a variable) is going to split the name on the space characters and take the first one. This is because the name is " action" and the " action" needs to get chopped off.
3 Likes

That’s really a great work! Thanks!
Is there any reason why long-press works only for button 3 and 4?

Thanks,
Claudio

where do I find the friendly name? when I check on Configuration > Devices and even on Entities, the name is wireless_switch.master :thinking:

I even went to hidden .strorage directory and saw that on my .core. device_registry below, the name doesn’t have spaces on it.

You’ve to go in the Zigbee2Mqtt menù and rename it without spaces

In my case, I got rid of underscores in a friendly name and that did the trick.
camelCase all the way!

I have made a ZHA blueprint version of the Tuya 4 button switch TS004F. Works with all combinations of buttons allowed by the switch, incl the “stop” of dimming

As I have no idea of how to generate a blueprint, feel free to create a useable blueprint in the blueprint exchange if you know how.

blueprint:
  name: ZHA - Tuya 4-Button Dimmer Switch
  description: Automate your Tuya 4-Button Dimmer using ZHA events.
  domain: automation
  input:
    tuya_4button_dimmer_switch:
      name: Tuya 4-Button Dimmer Switch
      description: Tuya 4-Button Dimmer Switch to use
      selector:
        device:
          integration: zha
          manufacturer: _TZ3000_xabckq1v
          model: TS004F
    button_one_short_press:
      name: Single Press On
      description: Action to run on button upper-left single press
      default: []
      selector:
        action: {}
    button_two_short_press:
      name: Single Press Off
      description: Action to run on button lower-left single press
      default: []
      selector:
        action: {}
    button_three_short_press:
      name: Single Press Dim-up
      description: Action to run on button upper-right single press
      default: []
      selector:
        action: {}
    button_four_short_press:
      name: Single Press Dim-down
      description: Action to run on button lower-right single press
      default: []
      selector:
        action: {}
    button_three_long_press:
      name: Long Press Dim-up
      description: Action to run on button upper-right long press
      default: []
      selector:
        action: {}
    button_four_long_press:
      name: Long Press Dim-down
      description: Action to run on button lower-right long press
      default: []
      selector:
        action: {}
    button_dim_stop:
      name: Long Press Dim-down
      description: Action to run when end/stop long press
      default: []
      selector:
        action: {}
#  source_url: 
mode: restart
max_exceeded: silent
trigger:
- platform: event
  event_type: zha_event
  event_data:
    device_id: !input 'tuya_4button_dimmer_switch'
action:
- variables:
    command: '{{ trigger.event.data.command }}'
    args:  '{{ trigger.event.data.args }}'
- choose:
  - conditions: '{{ command == ''on'' }}'
    sequence: !input 'button_one_short_press'
  - conditions: '{{ command == ''off'' }}'
    sequence: !input 'button_two_short_press'
  - conditions: '{{ command == ''step'' }}'
    sequence:
    - choose:
      - conditions: '{{ args == [ 0, 51, 10] }}'
        sequence: !input 'button_three_short_press'
      - conditions: '{{ args == [ 1, 51, 10 ] }}'
        sequence: !input 'button_four_short_press'
  - conditions: '{{ command == ''move'' }}'
    sequence:
    - choose:
      - conditions: '{{ args == [ 0, 51] }}'
        sequence: !input 'button_three_long_press'
      - conditions: '{{ args == [ 1, 51 ] }}'
        sequence: !input 'button_four_long_press'
  - conditions: '{{ command == ''stop'' }}'
    sequence: !input 'button_dim_stop'

Any issues, feel free to ping me.

The Tuya TS004F is build this way. Intended to be used as on/off on the left buttons and dim-up/dim-down on the right buttons. Hence, only longpress on the right buttons

Thank you!

Has anyone had any joy getting this to work as a 4 way scene switch?

I’ve had this all working perfectly for several months, then after an HA update today, it’s all broken. I get the following error in the logs.

Logger: homeassistant.helpers.template
Source: helpers/template.py:1834
First occurred: 20:44:41 (16 occurrences)
Last logged: 21:23:24

  • Template variable error: ‘None’ has no attribute ‘split’ when rendering ‘{{ topic.split(’/’)[1].replace(’/’, ‘’) == deviceName.split(’ ‘)[0] }}’
  • Template variable error: ‘value_json’ is undefined when rendering ‘{{ value_json.battery }}’
  • Template variable error: ‘value_json’ is undefined when rendering ‘{{ value_json.action }}’
  • Template variable error: list object has no element 1 when rendering ‘{{ topic.split(’/’)[1].replace(’/’, ‘’) == deviceName.split(’ ‘)[0] }}’

Is a fix needed? It appears the trigger.topic is returning None now.

Same here, it’s bust! anyone got it working?
cheers

Is anybody realise dimming up or down while long press?
I use WZ1 LED controller. In my case long press decrease lightness to one step

Hi! Someone might find this post useful, since it also has a 4-gang device, and it’s working perfect: Tips to configure a Zigbee 4 gang switch (4 channel) thru MQTT

Trying you projetc but no suitable entity is available

Was it fixed? I chose this blueprint and device for testing my zigbee network. It’s not working. I am not sure if have a configuration problem in my network or if the blue print ist not working

This blueprint is not working for me. But I found another one which works perfectly.

Hi all, noob-ish user here trying to understand how to add a Tuya 4-gang switch, model TS004F.

I apologize for these initial questions, but please bear with me in helping me understand how this works:

  1. Does this require “zigbee2mqtt” ?
  2. If so, I can’t seem to add the repo to my add-on store, so that’s another story.
  3. Does the zigbee2mqtt add-on replace my current HubZ Smart Home Controller - HubZ ZigBee Com Port interface? I’m also using DeConz with a Conbee II if that makes any difference.

Thanks for any tips here. I was able to pair my 4-gang with the current zigbee controller and I even see events when listening for zha_events, so I think I’m close!

Thanks in advance,

Dennis

Update here – it turns out I didn’t need to do anything with this blueprint or any custom stuff at all. I just added the switch as a zigbee device and it fires off events with button presses.

I just look for the device_id, endpoint_id (button #), and what kind of press happened (i.e. remote_button_short_press and fire actions based on that. It works great!

I did notice that button #1 uses different data for what kind of press happened, but that’s easy to accommodate.

Here’s an example automation that turns off all the lights with button press of number four.

alias: 'Family room: All lights off'
description: Turn off the family room lights
trigger:
  - platform: event
    event_type: zha_event
    event_data:
      device_id: 4a6ec0fe3785de8d0bd277fb
      endpoint_id: 4
      command: remote_button_short_press
condition: []
action:
  - service: light.turn_off
    data: {}
    target:
      entity_id:
        - light.lightgroup_family_room_tv
        - light.lightgroup_family_room_lamps
        - light.lightgroup_kitchen_island
mode: single

So, which light switches are compatible with this blueprint (in the UK)?
Any links?

It is such a weird way to set up a switch in the Tuya app as well using scenes rather than being able to just pick a light etc.

Many thanks in advance