Blueprint - Tuya 2 button scene switch - TS0042 - Zigbee2MQTT

Blueprint for Tuya 2 button switch.

Model: TS0042
Vendor: Tuya
Based on: Blueprint from Stinger 4 button switch (Profile - Stringer - Home Assistant Community)

Actions:

  1. Short press
  2. Double press
  3. Long press (5 seconds)

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

blueprint:
  name: Zigbee2MQTT - Tuya 2-Button Scene Switch
  description: Automate your Tuya 2-Button Scene Switch via Zigbee2MQTT.
  domain: automation
  input:
    switch:
      name: Tuya 2-Button Scene Switch
      description: Tuya 2-Button Scene Switch to use
      selector:
        entity:
          integration: mqtt
          domain: sensor
    button_one_short_press:
      name: Single Press - Button 1
      description: Action to run on button 1 (lower-left) single press
      default: []
      selector:
        action: {}
    button_one_double_press:
      name: Double Press - Button 1
      description: Action to run on button 1 (lower-left) double press
      default: []
      selector:
        action: {}
    button_one_long_press:
      name: Long Press - Button 1
      description: Action to run on button 1 (lower-left) long press
      default: []
      selector:
        action: {}
    button_two_short_press:
      name: Single Press - Button 2
      description: Action to run on button 2 (lower-right) single press
      default: []
      selector:
        action: {}
    button_two_double_press:
      name: Double Press - Button 2
      description: Action to run on button 2 (lower-right) double press
      default: []
      selector:
        action: {}
    button_two_long_press:
      name: Long Press - Button 2
      description: Action to run on button 2 (lower-right) long press
      default: []
      selector:
        action: {}
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 == ''1_double'' }}'
    sequence: !input 'button_one_double_press'
  - conditions:
    - '{{ command == ''2_double'' }}'
    sequence: !input 'button_two_double_press'
  - conditions:
    - '{{ command == ''1_hold'' }}'
    sequence: !input 'button_one_long_press'
  - conditions:
    - '{{ command == ''2_hold'' }}'
    sequence: !input 'button_two_long_press'

I had to erase this line to get it working.

1 Like

Thanks. I had the same problem. :clap:

Hello, the script works well for one device. But I have a second identical device and it is impossible to have the actions (single press, double press and long press for buttons 1 and 2). How to add this script to the second device.Thanks.