Zigbee2MQTT - Tuya 4-Button Scene Switch TS0012

Sharing my 1st blueprint - maybe someone will find it useful

Stolen from here: ZHA - TS004F Tuya 4-Button Dimmer Switch blueprint

blueprint:
  name: Zigbee2MQTT - Tuya 4-Button Scene Switch TS0012
  description: Automate your Tuya 4-Button Scene Switch (TS0012) via Zigbee2MQTT. Link - https://www.zigbee2mqtt.io/devices/TS0012.html
  domain: automation
  input:
    switch:
      name: TS0012 Switch
      description: Tuya 4-Button Wireless Switch
      selector:
        entity:
          domain: sensor
          integration: mqtt
    button_one_short_press:
      name: Button 1 - Single Press
      description: Action to run on button 1 (bottom-left) single press
      default: []
      selector:
        action: null
    button_one_double_press:
      name: Button 1 - Double Press
      description: Action to run on button 1 (bottom-left) single press
      default: []
      selector:
        action: null
    button_two_short_press:
      name: Button 2 - Single Press
      description: Action to run on button 2 (lower-right) single press
      default: []
      selector:
        action: null
    button_two_double_press:
      name: Button 2 - Double Press
      description: Action to run on button 2 (lower-right) single press
      default: []
      selector:
        action: null
    button_three_short_press:
      name: Button 3 - Single Press
      description: Action to run on button 3 (top-right) single press
      default: []
      selector:
        action: null
    button_three_double_press:
      name: Button 3 - Double Press
      description: Action to run on button 3 (top-right) single press
      default: []
      selector:
        action: null
    button_four_short_press:
      name: Button 4 - Single Press
      description: Action to run on button 4 (top-left) single press
      default: []
      selector:
        action: null
    button_four_double_press:
      name: Button 4 - Double Press
      description: Action to run on button 4 (lower-left) long press
      default: []
      selector:
        action: null
  source_url: https://github.com/maciey/HA/blob/ff7e1f9737700bdb10bd41367ee3780d2c64abab/Blueprints/button_TS0012.yaml
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"

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

The problem with triggering like this and not having a top condition statement to screen out things that don’t match your device, or in your case not having a default statement to handle things that won’t match this device is that the logs will spam with errors. You will need to limit what this blueprint action statement sees to what it is prepared to act on, or it will be a sir spamsalot blueprint…

Thanks - Im not an expert here - as mentioned Ive used referenced blueprint and tunned it a bit to my needs

What would you propose to use here then?

Does below look better?

trigger:
- platform: state
  entity_id: !input switch
  attribute: action

The trigger itself is a matter of choice and if this one works, it’s fine.
My suggestion is to add a global condition statement that screens the triggers such that only triggers that will result in one of the below action templates also triggering. So look at your variable ‘command’, and make sure it’s == to one of ‘1_single’, 2_single’, etc.
You can see examples of this on my cube blueprints for Z2M as I had the same problem.
Link to my blueprints in my tagline.

That’s how I did it anyway.

This being all in a single choose, there is probably a way to add a default on the choose statement that collects all the triggers you do not care about and makes them happy. I have not gone that way and don’t have sample code for that, but it could also work.

As long as the command matches one of the actions, it will do something, even if that something is an empty action statement, and there will be no error. If a command of wake-up or null or something from another device triggers this BP, the condition will screen those out and it’s happy and done doing nothing else.