ZHA - TS004F Tuya 4-Button Dimmer Switch blueprint

Many thanks, @Kevin64 ! I should have been more attentive when doing it.

Just fixed it. Can you try now?

Works great Luis !

1 Like

@Kevin64 i followed your advise but error is still happening when i’d like to create automation by using blueprint.

2022-03-05 11:45:12 DEBUG (MainThread) [zigpy.zdo] [0xd729:zdo] ZDO request ZDOCmd.Bind_rsp: [<Status.SUCCESS: 0>]
2022-03-05 11:45:12 DEBUG (MainThread) [zigpy.zdo] [0xd729:zdo] No handler for ZDO request:ZDOCmd.Bind_rsp([<Status.SUCCESS: 0>])
2022-03-05 11:45:12 DEBUG (MainThread) [zigpy_zigate.uart] Frame received: 8012000a5b00000002d7293e010000
2022-03-05 11:45:12 DEBUG (MainThread) [zigpy_zigate.api] data received 0x8012 b'00000002d7293e0100' LQI:0
2022-03-05 11:45:12 DEBUG (MainThread) [zigpy_zigate.zigbee.application] zigate_callback_handler [0, 0, 0, <Address address_mode=ADDRESS_MODE.NWK address=0xd729>, 62]
2022-03-05 11:45:12 DEBUG (MainThread) [zigpy_zigate.zigbee.application] ZPS Event APS data confirm, message routed to <Address address_mode=ADDRESS_MODE.NWK address=0xd729> 0
2022-03-05 11:45:12 DEBUG (MainThread) [zigpy_zigate.uart] Frame received: 80110008f800d7290080213e00
2022-03-05 11:45:12 DEBUG (MainThread) [zigpy_zigate.api] data received 0x8011 b'00d7290080213e' LQI:0
2022-03-05 11:45:12 DEBUG (MainThread) [zigpy_zigate.zigbee.application] zigate_callback_handler [0, 0xd729, 0, 32801, 62]
2022-03-05 11:45:12 DEBUG (MainThread) [zigpy_zigate.zigbee.application] ACK Data received 62 0
2022-03-05 11:45:35 DEBUG (MainThread) [zigpy_zigate.uart] Frame received: 80080005fb29b609e000
2022-03-05 11:45:35 DEBUG (MainThread) [zigpy_zigate.api] data received 0x8008 b'29b609e0' LQI:0
2022-03-05 11:45:35 WARNING (MainThread) [zigpy_zigate.api] Received unhandled response 0x8008
2022-03-05 11:46:03 ERROR (stream_worker) [homeassistant.components.stream.stream.camera.hikvision_i91bm_mainstream] Error from stream worker: Stream ended; no additional packets
2022-03-05 11:46:35 WARNING (MainThread) [zigpy_zigate.api] Received unhandled response 0x8008
2022-03-05 11:47:21 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'event' when rendering '{{ trigger.event.data.command }}'
2022-03-05 11:47:21 ERROR (MainThread) [homeassistant.components.automation.zha_tuya_4_button_dimmer_switch] ZHA - Tuya 4-Button Dimmer Switch: Error executing script. Error rendering template for variables at pos 1: UndefinedError: 'dict object' has no attribute 'event'
2022-03-05 11:47:21 ERROR (MainThread) [homeassistant.components.automation.zha_tuya_4_button_dimmer_switch] Error while executing automation automation.zha_tuya_4_button_dimmer_switch: UndefinedError: 'dict object' has no attribute 'event'
2022-03-05 11:47:35 WARNING (MainThread) [zigpy_zigate.api] Received unhandled response 0x8008
2022-03-05 11:48:35 WARNING (MainThread) [zigpy_zigate.api] Received unhandled response 0x8008
2022-03-05 11:49:26 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'event' when rendering '{{ trigger.event.data.command }}'
2022-03-05 11:49:26 ERROR (MainThread) [homeassistant.components.automation.zha_tuya_4_button_dimmer_switch] ZHA - Tuya 4-Button Dimmer Switch: Error executing script. Error rendering template for variables at pos 1: UndefinedError: 'dict object' has no attribute 'event'
2022-03-05 11:49:26 ERROR (MainThread) [homeassistant.components.automation.zha_tuya_4_button_dimmer_switch] Error while executing automation automation.zha_tuya_4_button_dimmer_switch: UndefinedError: 'dict object' has no attribute 'event'
2022-03-05 11:49:34 WARNING (MainThread) [zigpy_zigate.api] Received unhandled response 0x8008
2022-03-05 11:50:05 ERROR (stream_worker) [homeassistant.components.stream.stream.camera.hikvision_i91bm_mainstream] Error from stream worker: Stream ended; no additional packets
2022-03-05 11:50:05 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'event' when rendering '{{ trigger.event.data.command }}'
2022-03-05 11:50:05 ERROR (MainThread) [homeassistant.components.automation.zha_tuya_4_button_dimmer_switch_2] ZHA - Tuya 4-Button Dimmer Switch: Error executing script. Error rendering template for variables at pos 1: UndefinedError: 'dict object' has no attribute 'event'
2022-03-05 11:50:05 ERROR (MainThread) [homeassistant.components.automation.zha_tuya_4_button_dimmer_switch_2] Error while executing automation automation.zha_tuya_4_button_dimmer_switch_2: UndefinedError: 'dict object' has no attribute 'event'
2022-03-05 11:50:34 WARNING (MainThread) [zigpy_zigate.api] Received unhandled response 0x8008
2022-03-05 11:51:34 WARNING (MainThread) [zigpy_zigate.api] Received unhandled response 0x8008type or paste code here

image

Are you on latest version of HA? Otherwise you might need the local handler files for the switch. Try and look here ZHA - Tuya 4-button Scene Switch (TS0044) - #25 by mutchun
I have not installed the files manually, just integrated it. Maybe something with version of HA

It looks like something has changed on the way the device is recognized by Home Assistant: buttons dim-down and dim-up aren’t being correctly recognized by our blueprint and no action is executed for these 2 buttons.

At beginning I thought it came from my new trådfri bulbs, but after changing to my old livarno ones, I’m having the same behaviour (no action is triggered from these 2 buttons).

Anyone else here experiencing this issue?

My button also draw the CR2430 battery within one month, not sure it’s related.

Update: adding picture of automation debug for a click on dim down button. We can see that it bypass the action I have defined (toggle a lamp).

It seems the conditions {{ args == [ 0, 51, 10] }}, {{ args == [ 1, 51, 10] }} are no longer satisfied.

Just frustrating that things get changed when they are working, but I will keep you posted on my discoveries. Let me know if you find something as well.

1 Like

I have changed, im using Zigbee2MQTT now, hence can not change the blueprint.

I have read somewhere that the ARGS is no longer working in 2204. Have a look here where they mention it should work again. Not sure

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?