Tuya ZigBee 6 button switch TS0046 automation blueprint

Copied from the TS0044 blueprint by @Stringer here: Zigbee2MQTT - Tuya 4-button Scene Switch (TS0044)

I added support for buttons 5 and 6, and modified texting since the button placement is different

Looks like this:

Screenshot 2023-05-26 at 19.18.59

blueprint:
  name: Zigbee2MQTT - Tuya 6-Button Scene Switch
  description: Automate your Tuya 6-Button Scene Switch via Zigbee2MQTT.
  domain: automation
  input:
    switch:
      name: Tuya 6-Button Scene Switch
      description: Tuya 6-Button Scene Switch to use
      selector:
        entity:
          integration: mqtt
          domain:
          - sensor
          multiple: false
    button_one_short_press:
      name: Single Press - Button 1
      description: Action to run on button 1 (upper-left) single press
      default: []
      selector:
        action: {}
    button_one_double_press:
      name: Double Press - Button 1
      description: Action to run on button 1 (upper-left) double press
      default: []
      selector:
        action: {}
    button_one_long_press:
      name: Long Press - Button 1
      description: Action to run on button 1 (upper-left) long press
      default: []
      selector:
        action: {}
    button_two_short_press:
      name: Single Press - Button 2
      description: Action to run on button 2 (upper-right) single press
      default: []
      selector:
        action: {}
    button_two_double_press:
      name: Double Press - Button 2
      description: Action to run on button 2 (upper-right) double press
      default: []
      selector:
        action: {}
    button_two_long_press:
      name: Long Press - Button 2
      description: Action to run on button 2 (upper-right) long press
      default: []
      selector:
        action: {}
    button_three_short_press:
      name: Single Press - Button 3
      description: Action to run on button 3 (middle-left) single press
      default: []
      selector:
        action: {}
    button_three_double_press:
      name: Double Press - Button 3
      description: Action to run on button 3 (middle-left) double press
      default: []
      selector:
        action: {}
    button_three_long_press:
      name: Long Press - Button 3
      description: Action to run on button 3 (middle-left) long press
      default: []
      selector:
        action: {}
    button_four_short_press:
      name: Single Press - Button 4
      description: Action to run on button 4 (middle-right) single press
      default: []
      selector:
        action: {}
    button_four_double_press:
      name: Double Press - Button 4
      description: Action to run on button 4 (middle-right) double press
      default: []
      selector:
        action: {}
    button_four_long_press:
      name: Long Press - Button 4
      description: Action to run on button 4 (middle-right) long press
      default: []
      selector:
        action: {}
    button_five_short_press:
      name: Single Press - Button 5
      description: Action to run on button 5 (lower-left) single press
      default: []
      selector:
        action: {}
    button_five_double_press:
      name: Double Press - Button 5
      description: Action to run on button 5 (lower-left) double press
      default: []
      selector:
        action: {}
    button_five_long_press:
      name: Long Press - Button 5
      description: Action to run on button 5 (lower-left) long press
      default: []
      selector:
        action: {}
    button_six_short_press:
      name: Single Press - Button 6
      description: Action to run on button 6 (lower-right) single press
      default: []
      selector:
        action: {}
    button_six_double_press:
      name: Double Press - Button 6
      description: Action to run on button 6 (lower-right) double press
      default: []
      selector:
        action: {}
    button_six_long_press:
      name: Long Press - Button 6
      description: Action to run on button 6 (lower-right) long press
      default: []
      selector:
        action: {}
  source_url: https://community.home-assistant.io/t/tuya-zigbee-6-button-switch-ts0046-automation-blueprint/575541
mode: restart
max_exceeded: silent
trigger:
- platform: state
  entity_id: !input switch
  attribute: action
action:
- variables:
    command: '{{ trigger.to_state.state }}'
- 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 == ''5_single'' }}'
    sequence: !input button_five_short_press
  - conditions:
    - '{{ command == ''6_single'' }}'
    sequence: !input button_six_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 == ''5_double'' }}'
    sequence: !input button_five_double_press
  - conditions:
    - '{{ command == ''6_double'' }}'
    sequence: !input button_six_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
  - conditions:
    - '{{ command == ''5_hold'' }}'
    sequence: !input button_five_long_press
  - conditions:
    - '{{ command == ''6_hold'' }}'
    sequence: !input button_six_long_press

Thanks for sharing this! I had to make some changes for this to work:

  1. I changed the mode from restart to single. With restart, the automation would restart when you lift your finger off the button (as that clears the action), so presses were not consistently triggered.
  2. The action value for me is on the sensor entity itself - not an action attribute. So, I had to remove attribute: action.

Here’s the full blueprint.

blueprint:
  name: Zigbee2MQTT - Tuya 6-Button Scene Switch
  description: Automate your Tuya 6-Button Scene Switch via Zigbee2MQTT.
  domain: automation
  input:
    switch:
      name: Tuya 6-Button Scene Switch
      description: Tuya 6-Button Scene Switch to use
      selector:
        entity:
          integration: mqtt
          domain:
          - sensor
          multiple: false
    button_one_short_press:
      name: Single Press - Button 1
      description: Action to run on button 1 (upper-left) single press
      default: []
      selector:
        action: {}
    button_one_double_press:
      name: Double Press - Button 1
      description: Action to run on button 1 (upper-left) double press
      default: []
      selector:
        action: {}
    button_one_long_press:
      name: Long Press - Button 1
      description: Action to run on button 1 (upper-left) long press
      default: []
      selector:
        action: {}
    button_two_short_press:
      name: Single Press - Button 2
      description: Action to run on button 2 (upper-right) single press
      default: []
      selector:
        action: {}
    button_two_double_press:
      name: Double Press - Button 2
      description: Action to run on button 2 (upper-right) double press
      default: []
      selector:
        action: {}
    button_two_long_press:
      name: Long Press - Button 2
      description: Action to run on button 2 (upper-right) long press
      default: []
      selector:
        action: {}
    button_three_short_press:
      name: Single Press - Button 3
      description: Action to run on button 3 (middle-left) single press
      default: []
      selector:
        action: {}
    button_three_double_press:
      name: Double Press - Button 3
      description: Action to run on button 3 (middle-left) double press
      default: []
      selector:
        action: {}
    button_three_long_press:
      name: Long Press - Button 3
      description: Action to run on button 3 (middle-left) long press
      default: []
      selector:
        action: {}
    button_four_short_press:
      name: Single Press - Button 4
      description: Action to run on button 4 (middle-right) single press
      default: []
      selector:
        action: {}
    button_four_double_press:
      name: Double Press - Button 4
      description: Action to run on button 4 (middle-right) double press
      default: []
      selector:
        action: {}
    button_four_long_press:
      name: Long Press - Button 4
      description: Action to run on button 4 (middle-right) long press
      default: []
      selector:
        action: {}
    button_five_short_press:
      name: Single Press - Button 5
      description: Action to run on button 5 (lower-left) single press
      default: []
      selector:
        action: {}
    button_five_double_press:
      name: Double Press - Button 5
      description: Action to run on button 5 (lower-left) double press
      default: []
      selector:
        action: {}
    button_five_long_press:
      name: Long Press - Button 5
      description: Action to run on button 5 (lower-left) long press
      default: []
      selector:
        action: {}
    button_six_short_press:
      name: Single Press - Button 6
      description: Action to run on button 6 (lower-right) single press
      default: []
      selector:
        action: {}
    button_six_double_press:
      name: Double Press - Button 6
      description: Action to run on button 6 (lower-right) double press
      default: []
      selector:
        action: {}
    button_six_long_press:
      name: Long Press - Button 6
      description: Action to run on button 6 (lower-right) long press
      default: []
      selector:
        action: {}
mode: single
trigger:
- platform: state
  entity_id: !input switch
action:
- variables:
    command: '{{ trigger.to_state.state }}'
- 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 == ''5_single'' }}'
    sequence: !input button_five_short_press
  - conditions:
    - '{{ command == ''6_single'' }}'
    sequence: !input button_six_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 == ''5_double'' }}'
    sequence: !input button_five_double_press
  - conditions:
    - '{{ command == ''6_double'' }}'
    sequence: !input button_six_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
  - conditions:
    - '{{ command == ''5_hold'' }}'
    sequence: !input button_five_long_press
  - conditions:
    - '{{ command == ''6_hold'' }}'
    sequence: !input button_six_long_press

Thanks. I admit I haven’t looked at this for a while.
In the end, I moved the handling of this button to Node-RED, which I think is a bit easier, and handles the button up/down more efficiently, and for which the “empty” action field is not as much a problem.

For the action to be in the entity itself, I think it might depend whether you use ZHA or Z2M. With Z2M, there is a specific toggle on each device to copy the “action” into the entity. It might be the default in ZHA?