Skip to content

Instantly share code, notes, and snippets.

@DRuggeri
Last active November 27, 2022 23:20
Show Gist options
  • Save DRuggeri/5707bebd40fdcb23fe4b3a1f514d6ab2 to your computer and use it in GitHub Desktop.
Save DRuggeri/5707bebd40fdcb23fe4b3a1f514d6ab2 to your computer and use it in GitHub Desktop.
blueprint:
name: ZHA - Moes Tuya Smart Knob (TS004F) controller
description: Control entities with a Moes Tuya smart knob (the spinny ones). You can set functions for single press, double press, long press, rotating left, and rotating right.
domain: automation
source_url: https://gist.github.com/DRuggeri/5707bebd40fdcb23fe4b3a1f514d6ab2
input:
knob:
name: Smart Knob Device
description: Moes Tuya Smart Knob Device to use
selector:
device:
integration: zha
#manufacturer: _TZ3000_4fjiwweb
model: TS004F
action_press:
name: Action - button press
description: Action to run when button is pressed once.
default: []
selector:
action: {}
action_hold:
name: Action - button hold
description: Action to run when button is held.
default: []
selector:
action: {}
action_release:
name: Action - button release
description: Action to run when button is released after being held.
default: []
selector:
action: {}
action_left:
name: Action - knob left
description: Action to run when button is rotated left
default: []
selector:
action: {}
action_right:
name: Action - knob right
description: Action to run when button is rotated right
default: []
selector:
action: {}
mode: restart
max_exceeded: silent
trigger:
- platform: event
event_type: zha_event
event_data:
device_id: !input 'knob'
action:
- variables:
command: '{{ trigger.event.data.command }}'
cluster_id: '{{ trigger.event.data.cluster_id }}'
endpoint_id: '{{ trigger.event.data.endpoint_id }}'
args: '{{ trigger.event.data.args }}'
step_type: >-
{%- if (trigger.event.data.args|list)|length == 3 -%}
{%- set args = trigger.event.data.args|list -%}
{%- if args|first == 0 -%}
{{ 'right' }}
{%- elif args|first == 1 -%}
{{ 'left' }}
{%- else -%}
{{ '' }}
{%- endif -%}
{%- else -%}
{{ 'single_press' }}
{%- endif -%}
amount: >-
{%- if (trigger.event.data.args|list)|length == 3 -%}
{%- set args = trigger.event.data.args|list -%}
{{ args[1]|int }}
{%- else -%}
{{ 0 }}
{%- endif -%}
rate: >-
{%- if (trigger.event.data.args|list)|length == 3 -%}
{%- set args = trigger.event.data.args|list -%}
{{ args|last|int }}
{%- else -%}
{{ 0 }}
{%- endif -%}
- choose:
- conditions:
- '{{ command == "toggle" }}'
- '{{ cluster_id == 6 }}'
- '{{ endpoint_id == 1 }}'
sequence: !input 'action_press'
- conditions:
- '{{ command == "move_saturation" }}'
- '{{ cluster_id == 768 }}'
- '{{ endpoint_id == 1 }}'
sequence: !input 'action_press'
- conditions:
- '{{ command == "stop_move_step" }}'
- '{{ cluster_id == 768 }}'
- '{{ endpoint_id == 1 }}'
sequence: !input 'action_release'
- conditions:
- '{{ command == "step" }}'
- '{{ cluster_id == 8 }}'
- '{{ endpoint_id == 1 }}'
- '{{ step_type == "right" }}'
sequence: !input 'action_right'
- conditions:
- '{{ command == "step" }}'
- '{{ cluster_id == 8 }}'
- '{{ endpoint_id == 1 }}'
- '{{ step_type == "left" }}'
sequence: !input 'action_left'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment