Skip to content

Instantly share code, notes, and snippets.

@dbuezas
Last active April 15, 2024 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbuezas/832d15a762488f2754c59bc9ca9632da to your computer and use it in GitHub Desktop.
Save dbuezas/832d15a762488f2754c59bc9ca9632da to your computer and use it in GitHub Desktop.
blueprint:
name: ZHA - Smart Knob for lights
source_url: https://gist.github.com/dbuezas/832d15a762488f2754c59bc9ca9632da
description: "Control lights with a Moes Smart Knob.
Rotating left/right will change the brightness smoothly of the selected light
and making use of step_size.
Press-Rotating left/right will change the color temperature (or hue).
Long press switches between color temperature and rgb modes.
Tripple click switches to the second mode where double click is available.
All functionality of the second mode just writes logs, adapt as necessary."
domain: automation
input:
remote:
name: Remote
description: Moes Knob to use
selector:
device:
integration: zha
model: TS004F
multiple: false
light:
name: Light(s)
description: The light(s) to control
selector:
target:
entity:
- domain:
- light
mode: queued
max_exceeded: silent
trigger:
- platform: event
event_type: zha_event
event_data:
device_id: !input remote
action:
- variables:
entity: !input light
command: "{{ trigger.event.data.command }}"
step_mode: "{{ trigger.event.data.params.step_mode | default('') | string}}"
rotate_type: "{{ trigger.event.data.params.rotate_type | default('')}}"
press_type: "{{ trigger.event.data.params.press_type | default('')}}"
step_dir: "{{ 1 if step_mode == 'StepMode.Up' or rotate_type == 1 else -1}}"
step_size: "{{ trigger.event.data.params.step_size | default('')}}"
args_value: "{{ trigger.event.data.args.value | default('')}}"
- choose:
#----------------------- Toggle -----------------------------
- conditions:
- "{{ command == 'toggle' }}"
sequence:
- service: light.toggle
target: !input light
data:
transition: 0.25
#----------------------- Brightness -----------------------------
- conditions:
- "{{ command == 'step' }}"
sequence:
- service: light.turn_on
target: !input light
data:
brightness_step_pct: "{{ step_size/4 * step_dir}}"
transition: 0.25
#----------------------- Temperature -----------------------------
- conditions:
- "{{ command == 'step_color_temp' }}"
- "{{ state_attr(entity.entity_id, 'color_mode') == 'color_temp'}}"
sequence:
- service: light.turn_on
target: !input light
data:
color_temp: "{{ state_attr(entity.entity_id, 'color_temp')|int - step_size * step_dir}}"
transition: 0.25
#----------------------- RGB -----------------------------
- conditions:
- "{{ command == 'step_color_temp' }}"
- "{{ state_attr(entity.entity_id, 'color_mode') == 'rgb'}}"
sequence:
- service: light.turn_on
target: !input light
data:
hs_color:
- "{{ (state_attr( entity.entity_id, 'hs_color')[0]|int + step_size/2*step_dir)%360}}"
- 100
transition: 0.25
#----------------------- to Temperature -----------------------------
- conditions:
- "{{ command == 'move_saturation' }}"
- "{{ state_attr(entity.entity_id, 'color_mode') == 'rgb'}}"
sequence:
- service: light.turn_on
target: !input light
data:
color_temp: 300
transition: 0.25
#----------------------- to RGB -----------------------------
- conditions:
- "{{ command == 'move_saturation' }}"
- "{{ state_attr(entity.entity_id, 'color_mode') == 'color_temp'}}"
sequence:
- service: light.turn_on
target: !input light
data:
hs_color:
- 0
- 100
#----------------------- mode 0 enter -----------------------------
- conditions:
- "{{ command == 'attribute_updated' }}"
- "{{ args_value == 0 }}"
sequence:
- service: system_log.write
data:
message: "entered mode 0"
#----------------------- mode 1 enter -----------------------------
- conditions:
- "{{ command == 'attribute_updated' }}"
- "{{ args_value == 0 }}"
sequence:
- service: system_log.write
data:
message: "entered mode 0"
#----------------------- mode 2 rotate -----------------------------
- conditions:
- "{{ command == 'rotate_type' }}"
sequence:
- service: system_log.write
data:
message: "mode 1 rotate {{step_dir}}"
#----------------------- mode 2 click -----------------------------
- conditions:
- "{{ command == 'press_type' }}"
- "{{ press_type == 0 }}"
sequence:
- service: system_log.write
data:
message: "mode 1 click "
#----------------------- mode 2 dblclick -----------------------------
- conditions:
- "{{ command == 'press_type' }}"
- "{{ press_type == 1 }}"
sequence:
- service: system_log.write
data:
message: "mode 1 dblclick "
#----------------------- mode 2 long -----------------------------
- conditions:
- "{{ command == 'press_type' }}"
- "{{ press_type == 2 }}"
sequence:
- service: system_log.write
data:
message: "mode 1 long click "
#----------------------- mode 1 Long Press -----------------------------
- conditions:
- "{{ command == 'move_hue' }}"
sequence:
- repeat:
sequence:
- service: system_log.write
data:
message: "mode 0 pressed"
- wait_for_trigger:
platform: event
event_type: zha_event
event_data:
device_id: !input remote
timeout:
milliseconds: 500
until: "{{ wait.trigger is not none or repeat.index >= 10 }}"
# ----------------------- mode 1 Long release -----------------------------
- conditions:
- "{{ command == 'stop_move_step' }}"
sequence:
- service: system_log.write
data:
message: "mode 0 released"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment