ZHA - 1-Button (TS004F)

Hi everyone!

I just created my first blueprint for those very cheap single buttons identified as TS004F using the ZHA integration. Manufacturer is TZ3000_ja5osu5g and it is sold as eWeLink ZB-K1.

It supports:

  • Single press
  • Double press
  • Long press

It works by listening specifically to the press_type command sent by the device and filters out the extra noise from other events like toggle or remote_button_short_press.

Let me know what you think, and feel free to suggest improvements.

blueprint:
  name: ZHA - 1-Button (TS004F)
  description: |
    Handle single, double and long presses from 1-button devices identified as TS004F button using ZHA.

  domain: automation
  input:
    remote:
      name: TS004F 1-Button Device
      description: Select the TS004F 1-button
      selector:
        device:
          integration: zha
          model: TS004F

    single_press_action:
      name: Single Press
      description: Action to run on single press
      default: []
      selector:
        action: {}

    double_press_action:
      name: Double Press
      description: Action to run on double press
      default: []
      selector:
        action: {}

    long_press_action:
      name: Long Press
      description: Action to run on long press
      default: []
      selector:
        action: {}

mode: single

trigger:
  - platform: event
    event_type: zha_event
    event_data:
      device_id: !input remote
      command: press_type

action:
  - variables:
      press_type: "{{ trigger.event.data.args[0] | int }}"

  - choose:
      - conditions:
          - condition: template
            value_template: "{{ press_type == 0 }}"
        sequence: !input single_press_action

      - conditions:
          - condition: template
            value_template: "{{ press_type == 1 }}"
        sequence: !input double_press_action

      - conditions:
          - condition: template
            value_template: "{{ press_type == 2 }}"
        sequence: !input long_press_action

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

2 Likes

Very nice! I tried to use the long press function to change the brightness, but that long_press event is just too short to make sense for changing brightness significantly (changed just about 10% or so)
So I got carried away a bit and did the following:

short_press: switch on or off (toggle)
double_press: increase brightness in 4 steps
long_press: decrease brightness in 4 steps

for the increase and decrease I used a scripts and a helper, but see yourself:

Automation:

alias: Bedroom_Switch_Door_3-functions
description: β€œβ€
use_blueprint:
path: lehenandmartin/ZHA-1-Button-TS004F.yaml
input:
remote: 395220573487ff9bf11a5e4ba912f593
double_press_action:
- target:
entity_id: input_number.brightness_level_step
action: input_number.increment
data: {}
- action: script.set_brightness_from_helper
data: {}
long_press_action:
- target:
entity_id: input_number.brightness_level_step
action: input_number.decrement
data: {}
- action: script.set_brightness_from_helper
data: {}
single_press_action:
- target:
device_id: a53398b04d9c9218636bcf19da48d179
action: light.toggle
data: {}

Script:

alias: Set brightness from helper
description: β€œβ€
mode: single
sequence:

  • variables:
    brightness_map:
    β€œ0”: 1
    β€œ1”: 15
    β€œ2”: 50
    β€œ3”: 100
  • data:
    brightness_pct: >
    {% set level = states(β€˜input_number.brightness_level_step’) | int %} {%
    set level_str = level | string %} {{ brightness_map.get(level_str, 15)
    }}
    target:
    device_id: a53398b04d9c9218636bcf19da48d179
    action: light.turn_on

Helper:

input_number.brightness_level_step

Min: 0
Max: 3

Then I got carried away even more and added 3 more automations for brightness presets for different daytimes or sunrise…

Automation 1:

alias: "Morgens ab 10:00 Uhr Helligkeit auf 50 % setzen "
description: β€œβ€
triggers:

  • trigger: time
    at: β€œ10:00:00”
    conditions:
    actions:
  • target:
    entity_id: input_number.brightness_level_step
    data:
    value: 2
    action: input_number.set_value
    mode: single

Automation 2:

alias: Morgens u. Abends Helligkeit auf 15 % setzen
description: β€œβ€
triggers:

  • trigger: sun
    event: sunrise
    offset: "00:15:00 "
  • trigger: sun
    event: sunset
    conditions:
    actions:
  • target:
    entity_id: input_number.brightness_level_step
    data:
    value: 1
    action: input_number.set_value
    mode: single

Automation 3:

alias: Nachts Helligkeit auf 1 Prozent setzen
description: β€œβ€
triggers:

  • trigger: sun
    event: sunset
    offset: β€œ00:30:00”
    conditions:
    actions:
  • target:
    entity_id: input_number.brightness_level_step
    data:
    value: 0
    action: input_number.set_value
    mode: single