Skip to content

Instantly share code, notes, and snippets.

@tbaumann
Last active November 30, 2023 18:17
Show Gist options
  • Save tbaumann/54015bd40bc2e9eda6ce4d59981996ac to your computer and use it in GitHub Desktop.
Save tbaumann/54015bd40bc2e9eda6ce4d59981996ac to your computer and use it in GitHub Desktop.
Smart knob blueprint
blueprint:
name: ZHA - Tuya - TS004F Rotating Knob - Custom Actions
description: >-
This automation adds triggers for all actions of the Tuya TS004F rotating knob remote.
It can be used in both Command/Dimmer and Event/Scene mode. Both modes have their own actions.
In Command/Dimmer mode the config is mostly internal except for pressing the button.
In Event/Scene mode you can select your own actions.
To switch modes you can press the button 3 times fast.
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 Queue
description: The maximum number of runs that can be executing and/or queued up at a time.
default: 10
selector:
number:
mode: box
min: 1
max: 100
remote:
name: Tuya - TS004F Rotating Knob
description: Select the remote control you wish to use.
selector:
device:
integration: zha
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment