Skip to content

Instantly share code, notes, and snippets.

@harmpter
Created March 3, 2025 17:55
Show Gist options
  • Save harmpter/8fd84bb3d9cc141e6eba880cc9da2959 to your computer and use it in GitHub Desktop.
Save harmpter/8fd84bb3d9cc141e6eba880cc9da2959 to your computer and use it in GitHub Desktop.
harmpter's Zigbee rotary knob (MOES) macro
{% macro get_zigbee_rotary_info(data) %}
{#- harmpter's macro 1741019010 -#}
{#- allow both 'trigger' and 'trigger.event.data' as input -#}
{%- if data.command is not defined -%}{%- set data = data.event.data -%}{%- endif -%}
{%- if data.cluster_id==6 -%}
{{- 0.0 -}}
{%- elif data.cluster_id==8 -%}
{{- (1-data.params.step_mode*2) * (data.params.step_size-1)/12 -}}
{%- else -%}
{{- (2-data.params.step_mode) * (data.params.step_size-1)/17 -}}
{%- endif -%}
{% endmacro %}
# example: changes brightness by +5 or -5 each step
action:
- alias: handle zigbee rotary knob
if: "{{ trigger.event.data.command == 'step' }}" # step | step_color_temp | toggle
then:
- alias: change brightness
action: light.turn_on
data:
entity_id: light.room
brightness_step_pct: >-
{% from 'macros.jinja' import get_zigbee_rotary_info as get %}
{{ get(trigger)|int * 5 }}
else:
- alias: change color temp
action: light.turn_on
data:
entity_id: light.room
color_temp_kelvin: >-
{% from 'macros.jinja' import get_zigbee_rotary_info as get %}
{{ get(trigger)|int * 100 + state_attr('light.room','color_temp_kelvin') }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment