Zigbee2MQTT - Tuya 4-button Scene Switch (TS0044)

I made a new blueprint, avoiding the legacy action entity and implementing the MQTT device trigger.

It takes the Device ID. In my case, I have the 4 button switch. So, adjust to 1,2, or 3 according to your device.

blueprint:
  name: Zigbee2MQTT 2.0 - Tuya 4-Button Scene Switch
  description: Automate your Tuya 4-Button Scene Switch via Zigbee2MQTT.
  domain: automation
  input:
    switch:
      name: Tuya 4-Button Scene Switch
      description: Select the Tuya 4-Button Scene Switch to use
      selector:
        device:
          integration: mqtt

    # Button 1 Actions
    button_one_short_press:
      name: Single Press - Button 1 (Lower-Left)
      description: Action to run on button 1 single press
      default: []
      selector:
        action: {}
    button_one_double_press:
      name: Double Press - Button 1 (Lower-Left)
      description: Action to run on button 1 double press
      default: []
      selector:
        action: {}
    button_one_long_press:
      name: Long Press - Button 1 (Lower-Left)
      description: Action to run on button 1 long press
      default: []
      selector:
        action: {}

    # Button 2 Actions
    button_two_short_press:
      name: Single Press - Button 2 (Lower-Right)
      description: Action to run on button 2 single press
      default: []
      selector:
        action: {}
    button_two_double_press:
      name: Double Press - Button 2 (Lower-Right)
      description: Action to run on button 2 double press
      default: []
      selector:
        action: {}
    button_two_long_press:
      name: Long Press - Button 2 (Lower-Right)
      description: Action to run on button 2 long press
      default: []
      selector:
        action: {}

    # Button 3 Actions
    button_three_short_press:
      name: Single Press - Button 3 (Upper-Right)
      description: Action to run on button 3 single press
      default: []
      selector:
        action: {}
    button_three_double_press:
      name: Double Press - Button 3 (Upper-Right)
      description: Action to run on button 3 double press
      default: []
      selector:
        action: {}
    button_three_long_press:
      name: Long Press - Button 3 (Upper-Right)
      description: Action to run on button 3 long press
      default: []
      selector:
        action: {}

    # Button 4 Actions
    button_four_short_press:
      name: Single Press - Button 4 (Upper-Left)
      description: Action to run on button 4 single press
      default: []
      selector:
        action: {}
    button_four_double_press:
      name: Double Press - Button 4 (Upper-Left)
      description: Action to run on button 4 double press
      default: []
      selector:
        action: {}
    button_four_long_press:
      name: Long Press - Button 4 (Upper-Left)
      description: Action to run on button 4 long press
      default: []
      selector:
        action: {}

trigger:
  # Button 1 Triggers
  - platform: device
    device_id: !input switch
    domain: mqtt
    type: action
    subtype: 1_single
  - platform: device
    device_id: !input switch
    domain: mqtt
    type: action
    subtype: 1_double
  - platform: device
    device_id: !input switch
    domain: mqtt
    type: action
    subtype: 1_hold

  # Button 2 Triggers
  - platform: device
    device_id: !input switch
    domain: mqtt
    type: action
    subtype: 2_single
  - platform: device
    device_id: !input switch
    domain: mqtt
    type: action
    subtype: 2_double
  - platform: device
    device_id: !input switch
    domain: mqtt
    type: action
    subtype: 2_hold

  # Button 3 Triggers
  - platform: device
    device_id: !input switch
    domain: mqtt
    type: action
    subtype: 3_single
  - platform: device
    device_id: !input switch
    domain: mqtt
    type: action
    subtype: 3_double
  - platform: device
    device_id: !input switch
    domain: mqtt
    type: action
    subtype: 3_hold

  # Button 4 Triggers
  - platform: device
    device_id: !input switch
    domain: mqtt
    type: action
    subtype: 4_single
  - platform: device
    device_id: !input switch
    domain: mqtt
    type: action
    subtype: 4_double
  - platform: device
    device_id: !input switch
    domain: mqtt
    type: action
    subtype: 4_hold

action:
  - variables:
      command: '{{ trigger.payload }}'
  - 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_long_press
    - conditions:
      - '{{ command == ''2_hold'' }}'
      sequence: !input button_two_long_press
    - conditions:
      - '{{ command == ''3_hold'' }}'
      sequence: !input button_three_long_press
    - conditions:
      - '{{ command == ''4_hold'' }}'
      sequence: !input button_four_long_press

mode: single
max_exceeded: silent
6 Likes