ZHA - Tuya 4-button Scene Switch (TS0044)

Tags: #<Tag:0x00007f327bada6d8> #<Tag:0x00007f327bada520> #<Tag:0x00007f327bada368> #<Tag:0x00007f327bada250> #<Tag:0x00007f327bada0e8>

This is a blueprint for the Tuya 4-button Scene Switch.

blueprint:
  name: ZHA - Tuya 4-Button Scene Switch
  description: Automate your Tuya 4-Button Scene Switch using ZHA events.
  domain: automation
  input:
    tuya_4button_scene_switch:
      name: Tuya 4-Button Scene Switch
      description: Tuya 4-Button Scene Switch to use
      selector:
        device:
          integration: zha
          manufacturer: _TZ3000_vp6clf9d
          model: TS0044
    button_one_short_press:
      name: Single Press
      description: Action to run on button 1 (lower-left) single press
      default: []
      selector:
        action: {}
    button_one_double_press:
      name: Double Press
      description: Action to run on button 1 (lower-left) double press
      default: []
      selector:
        action: {}
    button_one_long_press:
      name: Long Press
      description: Action to run on button 1 (lower-left) long press
      default: []
      selector:
         action: {} 
    button_two_short_press:
      name: Single Press
      description: Action to run on button 2 (lower-right) single press
      default: []
      selector:
        action: {}
    button_two_double_press:
      name: Double Press
      description: Action to run on button 2 (lower-right) double press
      default: []
      selector:
        action: {}
    button_two_long_press:
      name: Long Press
      description: Action to run on button 2 (lower-right) long press
      default: []
      selector:
         action: {}  
    button_three_short_press:
      name: Single Press
      description: Action to run on button 3 (upper-right) single press
      default: []
      selector:
        action: {}
    button_three_double_press:
      name: Double Press
      description: Action to run on button 3 (upper-right) double press
      default: []
      selector:
        action: {}
    button_three_long_press:
      name: Long Press
      description: Action to run on button 3 (upper-right) long press
      default: []
      selector:
         action: {} 
    button_four_short_press:
      name: Single Press
      description: Action to run on button 4 (upper-left) single press
      default: []
      selector:
        action: {}
    button_four_double_press:
      name: Double Press
      description: Action to run on button 4 (upper-left) double press
      default: []
      selector:
        action: {}
    button_four_long_press:
      name: Long Press
      description: Action to run on button 4 (upper-left) long press
      default: []
      selector:
         action: {}
mode: restart
max_exceeded: silent
trigger:
- platform: event
  event_type: zha_event
  event_data:
    device_id: !input 'tuya_4button_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: '{{ endpoint_id == 3 }}'
        sequence: !input 'button_three_short_press'
      - conditions: '{{ endpoint_id == 4 }}'
        sequence: !input 'button_four_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: '{{ endpoint_id == 3 }}'
        sequence: !input 'button_three_double_press'
      - conditions: '{{ endpoint_id == 4 }}'
        sequence: !input 'button_four_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'
      - conditions: '{{ endpoint_id == 3 }}'
        sequence: !input 'button_three_long_press'
      - conditions: '{{ endpoint_id == 4 }}'
        sequence: !input 'button_four_long_press'
1 Like

You can streamline the action by using nested choose and shorthand notation for Template Conditions.

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: '{{ endpoint_id == 3 }}'
        sequence: !input 'button_three_short_press'
      - conditions: '{{ endpoint_id == 4 }}'
        sequence: !input 'button_four_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: '{{ endpoint_id == 3 }}'
        sequence: !input 'button_three_double_press'
      - conditions: '{{ endpoint_id == 4 }}'
        sequence: !input 'button_four_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'
      - conditions: '{{ endpoint_id == 3 }}'
        sequence: !input 'button_three_long_press'
      - conditions: '{{ endpoint_id == 4 }}'
        sequence: !input 'button_four_long_press'

Great suggestion, thanks! I’ll make the changes.

Love it, but I have mine linked with Zigbee2MQTT. Wish I could get this blueprint working for that instead.

Good work though

Is anyone kind enough to create a template for Zigbee2MQTT or if anyone can give me some pointers, I can take a jab at it. Thanks in advance.