Hi everyone,
I have zigbee2mqtt and Hue Tap Dial dimmer switches, and I’d like to use the dial to dim lights. In most cases I want to control a zigbee group (all lights in the room). Using the excellent blueprint from @freakshock Philips Hue Tap Dial Switch - Zigbee2MQTT I am able to adjust brightness based on step,slow and fast turns of the dial - but this gets triggered multiple times a second. For zigbee groups, they can only receive about 1 command a second.
I have been trying to make a “rate limiting” script/automation, but have hit various issues. Basic idea:
- A helper to store the pending brightness change (number from -255 to 255)
- An automation triggered on any turn of the dial, that adds/subtracts from the helper
- A second automation triggered on changes to the helper to a non 0 value, that changes uses brightness_step to adjust the brightness, resets the helper to 0, then waits 1 second, repeating until it stays 0. This is in “single” mode thus limiting how often brightness commands are sent.
Initially i was just using “step” as 25, “slow” as 50, “fast” as 100 in terms of the amount subtracted/ added, but this isn’t really precise enough. I then saw that there is a step_size (always a positive integer) and a step_direction (left/right) set - so I tried adjusting my first automation to use this, but I’ve found that “size” and “direction” aren’t being set simultaneously - and immediately get set back to “None”, so it gets very complicated trying to capture both of these values.
Below is the last basically working version of the automation - it works for increasing brightness, but almost never catches the “left” direction so it’s always increasing, never decreasing, brightness.
I feel like this must be a common issue that someone else has solved (rate limiting for zigbee groups, smooth dimming with the tapdial, or capturing the two different values that change at different times) - so would appreciate any ideas or pointers!
automation 1, sets helper:
alias: Tapdial helper test 3
description: ""
trigger:
- platform: state
entity_id:
- sensor.officejames_tapdial_action_step_size
from: None
id: size
condition: []
action:
- action: input_number.set_value
metadata: {}
data:
value: >-
{{ states('input_number.tapdial_test_helper_3')|int + (-1 if
states('sensor.officejames_tapdial_action_direction') == 'left' else
1)*states('sensor.officejames_tapdial_action_step_size')|int(0) }}
target:
entity_id: input_number.tapdial_test_helper_3
enabled: true
mode: single
automation 2, sets brightness
alias: Tapdial dim test 2
description: ""
trigger:
- platform: state
entity_id:
- input_number.tapdial_test_helper_3
condition:
- condition: not
conditions:
- condition: state
entity_id: input_number.tapdial_test_helper_3
state: "0.0"
action:
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 100
enabled: true
- repeat:
sequence:
- target:
entity_id: light.officejames_lamp
data:
brightness_step: "{{ states('input_number.tapdial_test_helper_3')|int}}"
action: light.turn_on
- action: input_number.set_value
target:
entity_id: input_number.tapdial_test_helper_3
data:
value: 0
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: 900
enabled: true
until:
- condition: state
entity_id: input_number.tapdial_test_helper_3
state: "0.0"
mode: single
Visual, showing the helper value changing and being reset as expected (except it’s always increasing even though I was turning left)
and here you can see that the values for step size goes from 8 to None, and then the direction goes from left to None (but sometimes it’s the other way round), which I believe is why I’m not getting negative numbers