ZHA - Tuya 4-button Scene Switch (TS0044)

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

Supported actions for each button:

  1. Short press
  2. Double press
  3. Long press (5 seconds)
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'
17 Likes

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'
2 Likes

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.

Here’s the Zigbee2MQTT version of this blueprint: Zigbee2MQTT - Tuya 4-button Scene Switch (TS0044)

3 Likes

when i saw this device under blueprints i was more than happy it was at least usable for a beginner like me but i got it linked through deconz.
it would be nice someone to point how to adapt it to work with deconz or to get a deconz version of this blueprint.
thanks in advance.
this is my 1st message and i never thought of getting so far with home assistant just following tutorials, posts, etc. but no videos at all. it would have not been possible without your contributions. thank you all

Hi All i am thinking of bying that 4-button scene it works with conbeeII?

I’m having issues pairing this switch with zha. Any suggestions? I can’t find a reset button to put it into pairing mode.

1 Like

I’ve adapted it for Deconz, but I get a double event fired for each button press.
I think the double triggers are a problem with deconz and this device. If anybody knows better, please let me know.
Here’s what I changed:

blueprint:
  name: deCONZ - LoraTap Tuya TS0044 4 button remote
  description: Automate your LoraTap Tuya TS0044 4 button remote using deCONZ events.
  domain: automation
  input:
    loratap_tuya_ts0044:
      name: Tuya TS0044 4 button remote
      description: Tuya TS0043 4 button remote to use
      selector:
        device:
          integration: deconz
          manufacturer: _TZ3000_vp6clf9d
          model: TS0044
    button_one_long_press:
      name: Button 1 (long press)
      description: Action to run on button 1 long press
      default: []
      selector:
        action: {}
    button_one_single_press:
      name: Button 1 (single press)
      description: Action to run on button 1 single press
      default: []
      selector:
        action: {}
    button_one_double_press:
      name: Button 1 (double press)
      description: Action to run on button 1 double press
      default: []
      selector:
        action: {}
    button_two_long_press:
      name: Button 2 (long press)
      description: Action to run on button 2 long press
      default: []
      selector:
        action: {}
    button_two_single_press:
      name: Button 2 (single press)
      description: Action to run on button 2 single press
      default: []
      selector:
        action: {}
    button_two_double_press:
      name: Button 2 (double press)
      description: Action to run on button 2 double press
      default: []
      selector:
        action: {}
    button_three_long_press:
      name: Button 3 (long press)
      description: Action to run on button 3 long press
      default: []
      selector:
        action: {}
    button_three_single_press:
      name: Button 3 (single press)
      description: Action to run on button 3 single press
      default: []
      selector:
        action: {}
    button_three_double_press:
      name: Button 3 (double press)
      description: Action to run on button 3 double press
      default: []
      selector:
        action: {}
    button_four_long_press:
      name: Button 4 (long press)
      description: Action to run on button 4 long press
      default: []
      selector:
        action: {}
    button_four_single_press:
      name: Button 4 (single press)
      description: Action to run on button 4 single press
      default: []
      selector:
        action: {}
    button_four_double_press:
      name: Button 4 (double press)
      description: Action to run on button 4 double press
      default: []
      selector:
        action: {}
  source_url: https://community.home-assistant.io/t/deconz-loratap-tuya-ts0043-3-button-remote/268690
mode: restart
max_exceeded: silent
trigger:
- platform: event
  event_type: deconz_event
  event_data:
    device_id: !input 'loratap_tuya_ts0044'
action:
- variables:
    event: '{{ trigger.event.data.event }}'
- choose:
  - conditions:
    - '{{ event == 1003 }}'
    sequence: !input 'button_one_long_press'
  - conditions:
    - '{{ event == 1002 }}'
    sequence: !input 'button_one_single_press'
  - conditions:
    - '{{ event == 1004 }}'
    sequence: !input 'button_one_double_press'
  - conditions:
    - '{{ event == 2003 }}'
    sequence: !input 'button_two_long_press'
  - conditions:
    - '{{ event == 2002 }}'
    sequence: !input 'button_two_single_press'
  - conditions:
    - '{{ event == 2004 }}'
    sequence: !input 'button_two_double_press'
  - conditions:
    - '{{ event == 3003 }}'
    sequence: !input 'button_three_long_press'
  - conditions:
    - '{{ event == 3002 }}'
    sequence: !input 'button_three_single_press'
  - conditions:
    - '{{ event == 3004 }}'
    sequence: !input 'button_three_double_press'
  - conditions:
    - '{{ event == 4003 }}'
    sequence: !input 'button_four_long_press'
  - conditions:
    - '{{ event == 4002 }}'
    sequence: !input 'button_four_single_press'
  - conditions:
    - '{{ event == 4004 }}'
    sequence: !input 'button_four_double_press'
1 Like

Bottom left button, press and hold until all LEDs illuminate (about 10 seconds)

1 Like

Thank you but I don’t know how to import this blueprint as I try to link to this message but it shows an ‘unsupported url’

Thanks I figured that out the other day. I long pressed everything before that not thinking that it would be for ten seconds. Either way its up and running and my new favorite button

Yeah, you can’t import from anything but the top post, I think.
Create a text file in your automations folder, copy and paste.

1 Like

Thanks for the blueprint and I got it working in version “2021.2.3”. I’m wondering if I can get LEDs to light up based on a condition. For example if my water heater is turned on. Any idea?

So is it an issue with the blueprint, HA or just me that I cannot see nor select any ZHA created light groups for a device?

With the same blueprint, I can select light groups:

Your use case has nothing to do with the switch or this blueprint. You need to create a separate automation for that within HA, either using the native automation (UI or YAML) or via node-red.

Thank you. It was me. I was picking a device rather than an entity.

Anyone have pointers for debugging my installation of this? I’ve got one of these switches connected and ZHA says it’s connected and is reporting the battery level. Initially my switch wasn’t showing up, but when I updated the manufacturer to _TZ3000_xabckq1v and the model to TS004F I was able to make an automation and select my device. To start out I tried a call service to a switch that I often use and it doesn’t seem to work.

Are there any events I can monitor to see what’s going on? Other devices connected to ZHA seem to work. Was changing the manufacturer and model not a good idea?