Z2M - TS004F Tuya 4-Gang Switch blueprint

Tags: #<Tag:0x00007fc412c4d960>

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_two_short_press:
      name: Single Press - Button 2
      description: Action to run on button 2 (lower-left) single press
      default: []
      selector:
        action: null
    button_three_short_press:
      name: Single Press - Button 3
      description: Action to run on button 3 (upper-right) single press
      default: []
      selector:
        action: null
    button_three_long_press:
      name: Long Press - Button 3
      description: Action to run on button 3 (upper-right) long press
      default: []
      selector:
        action: null
    button_four_short_press:
      name: Single Press - Button 4
      description: Action to run on button 4 (upper-left) single press
      default: []
      selector:
        action: null
    button_four_long_press:
      name: Long Press - Button 4
      description: Action to run on button 4 (upper-left) long press
      default: []
      selector:
        action: null

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 == 'on' }}"
                sequence: !input "button_one_short_press"
              - conditions:
                  - "{{ command == 'off' }}"
                sequence: !input "button_two_short_press"
              - conditions:
                  - "{{ command == 'brightness_step_up' }}"
                sequence: !input "button_three_short_press"
              - conditions:
                  - "{{ command == 'brightness_step_down' }}"
                sequence: !input "button_four_short_press"
              - conditions:
                  - "{{ command == 'brightness_move_up' }}"
                sequence: !input "button_three_long_press"
              - conditions:
                  - "{{ command == 'brightness_move_down' }}"
                sequence: !input "button_four_long_press"


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.

The following button commands work:

  • Button 1 short press
  • Button 2 short press
  • Button 3 short press
  • Button 3 long press
  • Button 4 short press
  • Button 4 long press

well done :slight_smile:

there’s also an option for ZHA support?

Thank you!

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

Sadly didn’t work for me too