Last active
May 25, 2025 14:09
-
-
Save kkilchrist/691dd3979882fce625ee2ac9d7cd392f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: ZHA - Tuya - TS004F Smart Knob - Custom Actions | |
description: >- | |
This automation adds triggers for all actions of the Tuya TS004F rotary knob remote. | |
It can be used in both Command/Dimmer mode and Event/Scene mode. Both modes have their own actions. | |
In Command/Dimmer mode, the configuration is mostly internal except for button press. | |
In Event/Scene mode, you can select your own actions. | |
To switch between modes, you can quickly press the button 3 times. | |
Sold on AliExpress by brands like Moes, Girier, etc. | |
domain: automation | |
input: | |
mode: | |
name: Automation Mode | |
description: "https://www.home-assistant.io/docs/automation/modes/" | |
default: restart | |
selector: | |
select: | |
mode: dropdown | |
options: | |
- single | |
- restart | |
- queued | |
- parallel | |
max: | |
name: Automation Max Executions | |
description: The maximum number of executions that can be run and queued at one time. | |
default: 10 | |
selector: | |
number: | |
mode: box | |
min: 1 | |
max: 100 | |
remote: | |
name: Tuya - TS004F Smart Knob | |
description: Select the remote you want to use. | |
selector: | |
device: | |
integration: zha | |
manufacturer: _TZ3000_abrsvsou | |
model: TS004F | |
light: | |
name: Light (Command/Dimmer mode) | |
selector: | |
target: | |
entity: | |
domain: light | |
toggle: | |
name: Toggle (Command/Dimmer mode) | |
selector: | |
action: | |
default: [] | |
press_short: | |
name: Short Press (Event/Scene mode) | |
selector: | |
action: | |
default: [] | |
press_double: | |
name: Double Press (Event/Scene mode) | |
selector: | |
action: | |
default: [] | |
press_long: | |
name: Long Press (Event/Scene mode) | |
selector: | |
action: | |
default: [] | |
rotate_left: | |
name: Rotate Left (Event/Scene mode) | |
selector: | |
action: | |
default: [] | |
rotate_right: | |
name: Rotate Right (Event/Scene mode) | |
selector: | |
action: | |
default: [] | |
mode: !input mode | |
max: !input max | |
max_exceeded: silent | |
trigger: | |
- platform: event | |
event_type: zha_event | |
event_data: | |
device_id: !input remote | |
action: | |
- variables: | |
light: !input light | |
command: "{{ trigger.event.data.command }}" | |
cluster_id: "{{ trigger.event.data.cluster_id }}" | |
endpoint_id: "{{ trigger.event.data.endpoint_id }}" | |
args: "{{ trigger.event.data.args }}" | |
direction: "{% if trigger.event.data.args[0] == 0 %} 0 {% elif trigger.event.data.args[0] == 1 %} 1 {% elif trigger.event.data.args[0] == 3 %} 3 {% endif %}" | |
value: "{% if trigger.event.data.args[1] %} {{ trigger.event.data.args[1] / 2 }} {% endif %}" | |
speed: "{% if trigger.event.data.args[2] == 1 %} 0.5 {% else %} 0 {% endif %}" | |
- choose: | |
# Command Mode | |
- conditions: | |
- "{{ command == 'toggle' }}" | |
- "{{ cluster_id == 6 }}" | |
- "{{ endpoint_id == 1 }}" | |
sequence: !input toggle | |
# Command Mode: Dimming | |
- conditions: | |
- "{{ command == 'step' }}" | |
- "{{ cluster_id == 8 }}" | |
- "{{ endpoint_id == 1 }}" | |
- "{{ direction == 0 }}" | |
sequence: | |
- repeat: | |
while: | |
- condition: template | |
value_template: "{{ repeat.index < 2 }}" | |
sequence: | |
- service_template: light.turn_on | |
target: !input light | |
data_template: | |
brightness_step_pct: "{{ value }}" | |
transition: "{{ speed }}" | |
- conditions: | |
- "{{ command == 'step' }}" | |
- "{{ cluster_id == 8 }}" | |
- "{{ endpoint_id == 1 }}" | |
- "{{ direction == 1 }}" | |
sequence: | |
- repeat: | |
while: | |
- condition: template | |
value_template: "{{ repeat.index < 2 }}" | |
sequence: | |
- service_template: light.turn_on | |
target: !input light | |
data_template: | |
brightness_step_pct: "{{ - value }}" | |
transition: "{{ speed }}" | |
# Command Mode: Color Temperature | |
- conditions: | |
- "{{ command == 'step_color_temp' }}" | |
- "{{ cluster_id == 768 }}" | |
- "{{ endpoint_id == 1 }}" | |
- "{{ direction == 1 }}" | |
sequence: | |
- repeat: | |
while: | |
- condition: template | |
value_template: "{{ repeat.index < 2 }}" | |
sequence: | |
- service_template: light.turn_on | |
target: !input light | |
data_template: | |
color_temp: "{{ ( state_attr( light.entity_id, 'color_temp' ) or 300 ) + value }}" | |
transition: "{{ speed }}" | |
- conditions: | |
- "{{ command == 'step_color_temp' }}" | |
- "{{ cluster_id == 768 }}" | |
- "{{ endpoint_id == 1 }}" | |
- "{{ direction == 3 }}" | |
sequence: | |
- repeat: | |
while: | |
- condition: template | |
value_template: "{{ repeat.index < 2 }}" | |
sequence: | |
- service_template: light.turn_on | |
target: !input light | |
data_template: | |
color_temp: "{{ ( state_attr( light.entity_id, 'color_temp' ) or 300 ) - value }}" | |
transition: "{{ speed }}" | |
# Command Mode: Color Hue | |
- conditions: | |
- "{{ command == 'move_hue' }}" | |
- "{{ cluster_id == 768 }}" | |
- "{{ endpoint_id == 1 }}" | |
sequence: | |
- repeat: | |
while: | |
- condition: template | |
value_template: "{{ repeat.index < 24 }}" | |
sequence: | |
- service_template: light.turn_on | |
target: !input light | |
data_template: | |
hs_color: | |
- "{{ ( value + (state_attr( light.entity_id , 'hs_color' )[0] or 0)) % 360 }}" | |
- 100 | |
transition: 0.5 | |
- delay: | |
hours: 0 | |
minutes: 0 | |
seconds: 1 | |
milliseconds: 0 | |
- conditions: | |
- "{{ command == 'stop_move_step' }}" | |
- "{{ cluster_id == 768 }}" | |
- "{{ endpoint_id == 1 }}" | |
sequence: | |
# Event mode: Short Press | |
- conditions: | |
- "{{ command == 'remote_button_short_press' }}" | |
sequence: !input press_short | |
# Event mode: Double Press | |
- conditions: | |
- "{{ command == 'remote_button_double_press' }}" | |
sequence: !input press_double | |
# Event mode: Long Press | |
- conditions: | |
- "{{ command == 'remote_button_long_press' }}" | |
sequence: !input press_long | |
# Event mode: Rotate Left | |
- conditions: | |
- "{{ command == 'left' }}" | |
sequence: !input rotate_left | |
# Event mode: Rotate Right | |
- conditions: | |
- "{{ command == 'right' }}" | |
sequence: !input rotate_right |
In my fork I extended support for multiple variations of knobs in the selector:
selector:
device:
filter:
- integration: zha
manufacturer: _TZ3000_abrsvsou
model: TS004F
- integration: zha
manufacturer: _TZ3000_402vrq2i
model: TS004F
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thanks for sharing this nice blueprint. It gave me a real good start.
Please allow me to share some suggestions to fix warnings in the log file:
The ‘toggle’ command doesn’t have arguments. So I added some checks for that in the variables section:
For the color temp I made two changes. Use Kelvin and mind the range (2000-6500 typically):
And
Update: Created a fork with these two changes