Z2M - TS004F Tuya 4-Gang Switch blueprint

Hi everyone,

This is a blueprint for the Tuya 4-Gang switch, TS004F edition. This will not work for TS0044.

blueprint:
  name: Zigbee2MQTT - Tuya 4-Button Scene Switch TS004F
  description: Automate your Tuya 4-Button Scene Switch (TS004F) via Zigbee2MQTT.
  domain: automation
  input:
    switch:
      name: TS004F Switch
      description: Tuya 4-Button Scene Switch to use
      selector:
        entity:
          domain: sensor
          integration: mqtt
    button_one_short_press:
      name: Single Press - Button 1
      description: Action to run on button 1 (upper-left) single press
      default: []
      selector:
        action: null
    button_one_hold:
      name: Hold - Button 1
      description: Action to run on button 1 (upper-left) single press
      default: []
      selector:
        action: null
    button_one_double_press:
      name: Double Press - Button 1
      description: Action to run on button 1 (upper-left) single press
      default: []
      selector:
        action: null
    button_two_hold:
      name: Hold - Button 2
      description: Action to run on button 2 (upper-right) single press
      default: []
      selector:
        action: null
    button_two_double_press:
      name: Double Press - Button 2
      description: Action to run on button 2 (upper-right) single press
      default: []
      selector:
        action: null
    button_two_short_press:
      name: Single Press - Button 2
      description: Action to run on button 2 (lower-right) single press
      default: []
      selector:
        action: null
    button_three_short_press:
      name: Single Press - Button 3
      description: Action to run on button 3 (lower-left) single press
      default: []
      selector:
        action: null
    button_three_hold:
      name: Hold - Button 3
      description: Action to run on button 3 (lower-left) long press
      default: []
      selector:
        action: null
    button_three_double_press:
      name: Double Press - Button 3
      description: Action to run on button 3 (lower-left) long press
      default: []
      selector:
        action: null
    button_four_short_press:
      name: Single Press - Button 4
      description: Action to run on button 4 (lower-right) single press
      default: []
      selector:
        action: null
    button_four_hold:
      name: Long Press - Button 4
      description: Action to run on button 4 (lower-right) long press
      default: []
      selector:
        action: null
    button_four_double_press:
      name: Double Press - Button 4
      description: Action to run on button 4 (lower-right) long press
      default: []
      selector:
        action: null
  source_url: https://gist.github.com/edememinov/1ae89374ece50d2aa4beee4bf8f3fd76
mode: single
max_exceeded: silent
variables:
  command: '{{ trigger.payload }}'
  topic: '{{ trigger.topic }}'
  switch_name: !input 'switch'
  deviceName: '{{ state_attr(switch_name, ''friendly_name'') }}'
trigger:
- platform: mqtt
  topic: zigbee2mqtt/+/action
action:
- choose:
  - conditions:
    - '{{ topic.split(''/'')[1].replace(''/'', '''') == deviceName.split('' '')[0]
      }}'
    sequence:
    - 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_hold'
      - conditions:
        - '{{ command == ''2_hold'' }}'
        sequence: !input 'button_two_hold'
      - conditions:
        - '{{ command == ''3_hold'' }}'
        sequence: !input 'button_three_hold'
      - conditions:
        - '{{ command == ''4_hold'' }}'
        sequence: !input 'button_four_hold'



Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

Known limitation:

  • Friendly name has to be set for the button in Z2M

  • This only works with 1 switch for now.

Support for multiple switches coming as soon as I figure out how I can use switch friendly name as a variable in the mqtt topic

Update:
Now works with multiple devies.

Update 2:
Updated for Z2M v 1.22.1-1.
Added double press and hold for all buttons

The following button commands work:

  • Button 1 short press
  • Button 1 double press
  • Button 1 hold
  • Button 2 short press
  • Button 2 double press
  • Button 2 hold
  • Button 3 short press
  • Button 3 double press
  • Button 3 hold
  • Button 4 short press
  • Button 4 double press
  • Button 4 hold
3 Likes

well done :slight_smile:

there’s also an option for ZHA support?

2 Likes

Thank you!

No, sadly. I didn’t have any luck getting TS004F to work with ZHA

Sadly didn’t work for me too

Are you getting any errors?

I eventually got it to work but it was after a full factory reset of hassio on my raspberry pi. I think there was a problem with my original zigbee setup.
I fully reset hassio to the latest image, then setup zigbee using zigbee2mqtt and I got it to work through that using the blueprint.
So thank you for this! It’s working now

After did a full reinstall RPi4, it finally able to detected in zigbee2mqtt. It was also able to be selected in automation. But it was unresponsive to all the click. How do I check it ?

2 Likes


Any idea what i did wrong?

1 Like

I can’t use this model of buttons. No matter what I do I can’t see any log messages on Zigbee2MQTT when I press any button. You guys can see any log message? Due to this, unfortunately, I can’t put this blueprint to work.

Have you tried restarting home assistant and reconnecting the buttons (after deleting them first from HA)?
Another possibility is not renaming the entity IDs in HA (when renaming the buttons in Z2M not selecting “Update Home Assistant entity ID”)

Hello and thanks for the response.

Unfortunately that also doesn’t work. Maybe it has to do with the USB sniffer I’m using.
In my case I’m using Texas’s ttyACM0

Has anyone tried the latest update of [email protected] version. Does it work with this blueprint?

I am on version 1.21.0-1 and I had no troubles

Hi,
what do I do wrong?
It says it a not supported device:
Warning Received message from unsupported device with Zigbee model 'TS004F' and manufacturer name '_TZ3000_xabckq1v'
Warning Please see: https://www.zigbee2mqtt.io/how_tos/how_to_support_new_devices.html.
But it is from the logs so if I touch a button it knows. But I can’t make an entity.
Thanks for your help!

When I make an automation using this blueprint, the automation gets triggered but no action is ever performed. Has anyone got an idea what I’m doing wrong? :slight_smile:

mode: single
max_exceeded: silent
variables:
  command: '{{ trigger.payload }}'
  topic: '{{ trigger.topic }}'
  switch_name: sensor.knop_eettafel_action
  deviceName: '{{ state_attr(switch_name, ''friendly_name'') }}'
trigger:
  - platform: mqtt
    topic: zigbee2mqtt/+/action
action:
  - choose:
      - conditions:
          - >-
            {{ topic.split('/')[1].replace('/', '') == deviceName.split(' ')[0]
            }}
        sequence:
          - choose:
              - conditions:
                  - '{{ command == ''on'' }}'
                sequence:
                  - type: toggle
                    device_id: 729d43e6ba4ce328966706da09e344ce
                    entity_id: light.kantoor_links_2
                    domain: light
              - conditions:
                  - '{{ command == ''off'' }}'
                sequence:
                  - type: toggle
                    device_id: c8256b95e61b5282ce79326aa0b3c8d4
                    entity_id: light.kantoor_rechts_2
                    domain: light
              - conditions:
                  - '{{ command == ''brightness_step_up'' }}'
                sequence: []
              - conditions:
                  - '{{ command == ''brightness_step_down'' }}'
                sequence: []
              - conditions:
                  - '{{ command == ''brightness_move_up'' }}'
                sequence:
                  - device_id: 729d43e6ba4ce328966706da09e344ce
                    domain: light
                    entity_id: light.kantoor_links_2
                    type: brightness_increase
              - conditions:
                  - '{{ command == ''brightness_move_down'' }}'
                sequence:
                  - device_id: c8256b95e61b5282ce79326aa0b3c8d4
                    domain: light
                    entity_id: light.kantoor_rechts_2
                    type: brightness_decrease
id: '1630512617940'
alias: Zigbee2MQTT - Tuya 4-Button Scene Switch TS004F
description: ''

I see that the button is sending on, off, brightness_move_up etc. just as expected. But the automation still skips choosing a action to trigger? :thinking:

I had exactly the same issue. Rename your sensor that it does not contain any spaces.

eg. knop-eettafel will work, while knop eettafel won’t.

1 Like

I have the same issue and my switch name is sensor.wireless_switch_master_action so there’s no spaces here too. any solutions at your end?

That means your friendly name is ‘wireless switch master’, so that does contain spaces. Rename it to something like wireless-switch-master and it should work.

The only issue I have now is that the long presses don’t really seem to work.

For example:

Button 3, single press: brightness_increase ← works.

Button 3, long press: brightness_increase ← most of the time nothing happens. Once in a while my lamp goes up one step in brightness, like with a single press. But 95% of the time, there is no change in brightness at all.

:thinking:

Seems that i am not alone at getting any sort off response from my ts004f. Z2M reports the device is supported and binding suggests that I should be expecting battery status, link quality, and action. However, mqtt doesn’t deliver any messages to a debug node so i guess I’d be on a fool’s errand trying to get the blue print working. Like others, I’m using a TI usb concentrator, my version of Z2M is up to date. I wondered why some folk seem to get this device to respond while others fail to.

For me, it works after restarting zigbre2mqtt add on, no need to start home assistant.