ZHA - TS004F Tuya 4-Button Dimmer Switch blueprint

Hi all,

This is my 1st post.

I just would like to say, I read yesterday and applied the blueprint well.
However, it seems it is quite more simple to configure and use the swith recently.

This morning, I upgraded to HA 2022.4.3 and try to reconfigure the switch from scratch.
I removed the python file ts004f.py, started a new configuration and I think I have a good functionning without the python file, the blueprint and with the new version of HA.

How I have proceeded :

  • Do the normal procedure in order to pair the switch in HA (3rd butonn maintained during 10s),
  • In automation for that switch, many more triggers are available with that version of HA, example <Button “2nd button” is clicked"> (my HA is in french language so maybe it is not exactly that expression),
    → but, anyway, the automation does not work… only previous available triggers (dimmer, …).
  • Change the configuration of the switch : maintain the 2nd (top right) and 4th (bottom right) buttons together during several seconds until the 3rd button blinks
    → the behavior of the switch is changed and is now similar to the TS0044
    → the automation works now for the 12th configurations (4 buttons, 1-click, 2-click, long-press).

Proposed blueprint: zha-ts004f-tuya-4-button-blueprint.yaml

blueprint:
  name: ZHA - Tuya 4-Button Switch
  description: Automate your Tuya 4-Button Switch using ZHA events.
  domain: automation
  input:
    tuya_4button_switch:
      name: Tuya 4-Button Switch
      description: Tuya 4-Button Switch to use
      selector:
        device:
          integration: zha
          manufacturer: _TZ3000_xabckq1v
          model: TS004F
    button_1_click:
      name: Button 1 click
      description: Action to run on button upper-left single press
      default: []
      selector:
        action: {}
    button_1_double_click:
      name: Button 1 double-click
      description: Action to run on button upper-left double press
      default: []
      selector:
        action: {}
    button_1_long_press:
      name: Button 1 long press
      description: Action to run on button upper-left long press
      default: []
      selector:
        action: {}
    button_2_click:
      name: Button 2 click
      description: Action to run on button upper-right single press
      default: []
      selector:
        action: {}
    button_2_double_click:
      name: Button 2 double-click
      description: Action to run on button upper-right double press
      default: []
      selector:
        action: {}
    button_2_long_press:
      name: Button 2 long press
      description: Action to run on button upper-right long press
      default: []
      selector:
        action: {}
    button_3_click:
      name: Button 3 click
      description: Action to run on button lower-left single press
      default: []
      selector:
        action: {}
    button_3_double_click:
      name: Button 3 double-click
      description: Action to run on button lower-right double press
      default: []
      selector:
        action: {}
    button_3_long_press:
      name: Button 3 long press
      description: Action to run on button lower-left long press
      default: []
      selector:
        action: {}
    button_4_click:
      name: Button 4 click
      description: Action to run on button lower-right single press
      default: []
      selector:
        action: {}
    button_4_double_click:
      name: Button 4 double-click
      description: Action to run on button lower-right double press
      default: []
      selector:
        action: {}
    button_4_long_press:
      name: Long Press Dim-down
      description: Action to run on button lower-right long press
      default: []
      selector:
        action: {}
mode: single
max_exceeded: silent
trigger:
- platform: event
  event_type: zha_event
  event_data:
    device_id: !input 'tuya_4button_switch'
action:
- variables:
    command: '{{ trigger.event.data.command }}'
    endpoint_id: '{{ trigger.event.data.endpoint_id }}'
- choose:
  - conditions: '{{ false }}'
    sequence:
        - service: notify.persistent_notification
          data:
            message: '{{ endpoint_id }}'
            title: '{{ command }}'
  - conditions: '{{ command == ''remote_button_short_press'' }}'
    sequence:
    - choose:
      - conditions: '{{ endpoint_id == 1 }}'
        sequence: !input 'button_1_click'
      - conditions: '{{ endpoint_id == 2 }}'
        sequence: !input 'button_2_click'
      - conditions: '{{ endpoint_id == 3 }}'
        sequence: !input 'button_3_click'
      - conditions: '{{ endpoint_id == 4 }}'
        sequence: !input 'button_4_click'
  - conditions: '{{ command == ''remote_button_double_press'' }}'
    sequence:
    - choose:
      - conditions: '{{ endpoint_id == 1 }}'
        sequence: !input 'button_1_double_click'
      - conditions: '{{ endpoint_id == 2 }}'
        sequence: !input 'button_2_double_click'
      - conditions: '{{ endpoint_id == 3 }}'
        sequence: !input 'button_3_double_click'
      - conditions: '{{ endpoint_id == 4 }}'
        sequence: !input 'button_4_double_click'
  - conditions: '{{ command == ''remote_button_long_press'' }}'
    sequence:
    - choose:
      - conditions: '{{ endpoint_id == 1 }}'
        sequence: !input 'button_1_long_press'
      - conditions: '{{ endpoint_id == 2 }}'
        sequence: !input 'button_2_long_press'
      - conditions: '{{ endpoint_id == 3 }}'
        sequence: !input 'button_3_long_press'
      - conditions: '{{ endpoint_id == 4 }}'
        sequence: !input 'button_4_long_press'
7 Likes

just tested work perfect thanks @Dunaar

I am having the exact same issue. Have you found a resolution yet?

Mine worked fine with Dunaar’s blueprint

I just connected the switch and I had the problem that I could choose the different triggers in automation but actually pressing the button did nothing.

This:

  • Change the configuration of the switch : maintain the 2nd (top right) and 4th (bottom right) buttons together during several seconds until the 3rd button blinks
    → the behavior of the switch is changed and is now similar to the TS0044
    → the automation works now for the 12th configurations (4 buttons, 1-click, 2-click, long-press).

Fixed it for me. Thank you @Dunaar

I am confused. is it now working with 12 scenes? did you improved the original blueprint from this post or did you made the changes on the original one?

I am not sure how to import the blueprint with 12 scenes to my HA

Hi all,

I’ve just proposed and posted the content of the blueprint and haven’t change the original.
I’ve just wanted to share the setup that works for me.
If you want to use the blueprint, you can create a blueprint file zha-ts004f-tuya-4-button-blueprint.yaml under the blueprints/automations directory with the File Editor.
If someone is aware about to upgrade or to fork the original blueprint (I’ve never done that), it would be great he does.

Pay attention to do the step “Change the configuration of the switch : maintain the 2nd (top right) and 4th (bottom right) buttons together during several seconds until the 3rd button blinks” to be able to use the blueprint.

2 Likes

Awesome; did not know about the switch configuration!
Merci :slight_smile:

Exactly the same issue on my side with 2 different TS004F (moes)

Thank you @Dunaar for this amazing hack! Just wondering how you discovered this magic of pressing buttons to change the switch behaviour … brilliant.

In any case, I’ve just updated the original post replacing the blueprint by the one you provided us.

And really sorry to all using this blueprint: I’ve just seen this answers now, as I got distracted by other issues (this switch draining battery, replacement of my HA server, …). Hope now things stay stable.

Converted the 12 button blueprint to Node Red flow.
To use it :

  1. Import the flow
  2. Change the device id in the Scene Switch node.
  3. Connect the end points to whatever you want it to do.

[
    {
        "id": "a332bce38a2178ce",
        "type": "tab",
        "label": "Flow 2",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "4ff9b9ef99d85d91",
        "type": "server-events",
        "z": "a332bce38a2178ce",
        "name": "zha_event_scanner",
        "server": "76b07c6c.a5b7a4",
        "version": 1,
        "event_type": "zha_event",
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "waitForRunning": true,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "eventData"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "$outputData(\"eventData\").event_type",
                "valueType": "jsonata"
            },
            {
                "property": "event_type",
                "propertyType": "msg",
                "value": "$outputData(\"eventData\").event_type",
                "valueType": "jsonata"
            }
        ],
        "x": 110,
        "y": 40,
        "wires": [
            [
                "5d3abba8ca20c166"
            ]
        ]
    },
    {
        "id": "5d3abba8ca20c166",
        "type": "switch",
        "z": "a332bce38a2178ce",
        "name": "Scene Switch",
        "property": "payload.event.device_ieee",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "60:a4:23:ff:fe:6b:75:4d",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 300,
        "y": 40,
        "wires": [
            [
                "c9f64ad0d0fbbf20"
            ]
        ]
    },
    {
        "id": "c9f64ad0d0fbbf20",
        "type": "switch",
        "z": "a332bce38a2178ce",
        "name": "Press Type",
        "property": "payload.event.command",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "remote_button_short_press",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "remote_button_double_press",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "remote_button_long_press",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 470,
        "y": 40,
        "wires": [
            [
                "fd76a00401a2958b"
            ],
            [
                "efcb89c4f5193d48"
            ],
            [
                "bb278fa79e4e0026"
            ]
        ]
    },
    {
        "id": "fd76a00401a2958b",
        "type": "switch",
        "z": "a332bce38a2178ce",
        "name": "Short Press",
        "property": "payload.event.endpoint_id",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "2",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "3",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "4",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 4,
        "x": 690,
        "y": 40,
        "wires": [
            [],
            [],
            [],
            []
        ]
    },
    {
        "id": "efcb89c4f5193d48",
        "type": "switch",
        "z": "a332bce38a2178ce",
        "name": "Double Press",
        "property": "payload.event.endpoint_id",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "2",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "3",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "4",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 4,
        "x": 700,
        "y": 120,
        "wires": [
            [],
            [],
            [],
            []
        ]
    },
    {
        "id": "bb278fa79e4e0026",
        "type": "switch",
        "z": "a332bce38a2178ce",
        "name": "Long Press",
        "property": "payload.event.endpoint_id",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "2",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "3",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "4",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 4,
        "x": 690,
        "y": 200,
        "wires": [
            [],
            [],
            [],
            []
        ]
    },
    {
        "id": "76b07c6c.a5b7a4",
        "type": "server",
        "name": "Home Assistant",
        "version": 2,
        "addon": false,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true,
        "heartbeat": false,
        "heartbeatInterval": "30"
    }
]

Worked as advertised!!! Awesome and thank you. I like this button and was quite disappointed when it didn’t work.

I am getting an error every time I restart HA

Any Ideas?

Thanks

Logger: homeassistant.config
Source: components/blueprint/models.py:161
First occurred: June 20, 2022, 9:09:31 PM (1 occurrences)
Last logged: June 20, 2022, 9:09:31 PM

Invalid config for [automation]: Missing input tuya_4button_switch (See /config/configuration.yaml, line 8).
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/automation/config.py", line 103, in _try_async_validate_config_item
    config = await async_validate_config_item(hass, config, full_config)
  File "/usr/src/homeassistant/homeassistant/components/automation/config.py", line 70, in async_validate_config_item
    return await blueprints.async_inputs_from_config(config)
  File "/usr/src/homeassistant/homeassistant/components/blueprint/models.py", line 299, in async_inputs_from_config
    inputs.validate()
  File "/usr/src/homeassistant/homeassistant/components/blueprint/models.py", line 161, in validate
    raise MissingInput(self.blueprint.domain, self.blueprint.name, missing)
homeassistant.components.blueprint.errors.MissingInput: Missing input tuya_4button_switch

I have the same. Did you manage to fix the error in the meantime?

I did everything from scratch.

Imported the blueprint, binded the switch, and created the automation.
Please pay attention to the state of the switch. Read the section under “Attention” in the 1st post.

Thank you for this Blueprint. I’m feeling a noob. I still can.t get the switch to dim up and down on long press. Any help?

Spent few hours trying to make TS004F work.
Finally found this post - changing the configuration of the switch SOLVED my problem.
THANK YOU!

Hi everyone

I might have encountered a bit of a weird Tuya TS004F.
From all I understand all devices in this threat have four distinct buttons.
Mine has two bottons with two positions (up + down) each.

I bought them here: https://de.aliexpress.com/item/1005006265612118.html

I can switch the mode when I press bottom-left + bottom-right (instead of top-right + bottom-right as recommended in the top post).
However: only the top right button is then still working.
All other buttons are not recognized in the log.

The top left button produces this two logs:

First: _TZ3000_0ht8dnxj TS004F Remote Button Short Press event was fired
Second: _TZ3000_0ht8dnxj TS004F Press Type event was fired with parameters: {‘press_type’: 0}

Double and Long press events are also present but still only for the top left.

Does somebody know what could be wrong?
Maybe I just have to bit the bullet and get some ugly Ikea Tradfri ones :confused:

Thank you for this blueprint, it’s got my button working nicely!

Just one problem - though it’s not a show stopper. We have several Tuya 4-button scene switches and due to the different hardware numbers this happened to be the only one of mine that required this Blueprint.

I find that to use it, we first have to press any button once to wake it and it goes through it’s “reconnecting” light flashes, and then accepts our next button press. There is no problem with its zigbee signal.