ZHA - Tuya 2-button Scene Switch (TS0042)

A clear rip off from Stringer 4 button switch :slight_smile:

Supported actions for each button:

  1. Short press
  2. Double press
  3. Long press (5 seconds)
blueprint:
  name: ZHA - Tuya 2-Button Scene Switch
  description: Automate your Tuya 2-Button Scene Switch using ZHA events.
  domain: automation
  input:
    tuya_2button_scene_switch:
      name: Tuya 2-Button Scene Switch
      description: Tuya 2-Button Scene Switch to use
      selector:
        device:
          integration: zha
          manufacturer: _TZ3000_dfgbtub0
          model: TS0042
    button_one_short_press:
      name: Single Press
      description: Action to run on button 1 (left) single press
      default: []
      selector:
        action: {}
    button_one_double_press:
      name: Double Press
      description: Action to run on button 1 left) double press
      default: []
      selector:
        action: {}
    button_one_long_press:
      name: Long Press
      description: Action to run on button 1 (left) long press
      default: []
      selector:
         action: {}
    button_two_short_press:
      name: Single Press
      description: Action to run on button 2 (right) single press
      default: []
      selector:
        action: {}
    button_two_double_press:
      name: Double Press
      description: Action to run on button 2 (right) double press
      default: []
      selector:
        action: {}
    button_two_long_press:
      name: Long Press
      description: Action to run on button 2 (right) long press
      default: []
      selector:
         action: {} 
mode: restart
max_exceeded: silent
trigger:
- platform: event
  event_type: zha_event
  event_data:
    device_id: !input 'tuya_2button_scene_switch'
action:
- variables:
    command: '{{ trigger.event.data.command }}'  
    endpoint_id: '{{ trigger.event.data.endpoint_id }}'
- choose:
  - conditions: "{{ command == 'remote_button_short_press' }}"
    sequence:
    - choose:
      - conditions: '{{ endpoint_id == 1 }}'
        sequence: !input 'button_one_short_press'
      - conditions: '{{ endpoint_id == 2 }}'
        sequence: !input 'button_two_short_press'
  - conditions: "{{ command == 'remote_button_double_press' }}"
    sequence:
    - choose:
      - conditions: '{{ endpoint_id == 1 }}'
        sequence: !input 'button_one_double_press'
      - conditions: '{{ endpoint_id == 2 }}'
        sequence: !input 'button_two_double_press'
  - conditions: "{{ command == 'remote_button_long_press' }}"
    sequence:
    - choose:
      - conditions: '{{ endpoint_id == 1 }}'
        sequence: !input 'button_one_long_press'
      - conditions: '{{ endpoint_id == 2 }}'
        sequence: !input 'button_two_long_press'
5 Likes

Worked great. I just had to change the following line manufacturer: _TZ3000_dfgbtub0 and reboot home assistant to update the blueprint.
Thanks for providing.

1 Like

This only works sometimes for me. Listened to zha_events and noticed that its two events triggered when pushing a button, might that be the problem?

event_type: zha_event
data:
  device_ieee: a4:c1:38:06:ce:67:40:6d
  unique_id: a4:c1:38:06:ce:67:40:6d:1:0x0006
  device_id: 5a841e0a5725b8661da243bb8faa2fb5
  endpoint_id: 1
  cluster_id: 6
  command: press_type
  args:
    - 0
  params:
    press_type: 0
origin: LOCAL
time_fired: "2024-08-08T09:20:33.979316+00:00"
context:
  id: 01J4RMMENVR2J694S0TQF7NNPZ
  parent_id: null
  user_id: null

And:

event_type: zha_event
data:
  device_ieee: a4:c1:38:06:ce:67:40:6d
  unique_id: a4:c1:38:06:ce:67:40:6d:1:0x0006
  device_id: 5a841e0a5725b8661da243bb8faa2fb5
  endpoint_id: 1
  cluster_id: 6
  command: remote_button_short_press
  args: []
  params: {}
origin: LOCAL
time_fired: "2024-08-08T09:20:33.978089+00:00"
context:
  id: 01J4RMMENTHJ2ZMC4TTHYMPEZJ
  parent_id: null
  user_id: null

Any ideas how to filter out the first one? My theory is that the first one runs the automation and since the command variable isnt there it won’t work.