Hi, I was also thinking about a general purpose rotary-encoder for to control DIFFERENT devices, but how could you really control various devices with one encoder? I was thinking about the use case that If I set for example the Living room lights to 20% brigthness, then after that I could fine tune the brightness with the rotary encoder after. And after that I control the volume of my media in HA. And the knob would work as volume controller after that?
I’m currently trying to do the same thing. I designed and printed a simple scene switcher to replace with my light switches.
I’m using a rotary encoder to control the smart bulb in the room (tapo l530). Also with help of chatGPT I added an option to change color while press and turn wheel. Double click resets to white.
This is working in concept but the issue is that I had to add a small delay before the actions so it does not does send the commands for every step. Still it isn’t very consistent.
globals:
- id: encoder_brightness
type: int
restore_value: yes
initial_value: '50'
- id: encoder_hue
type: float
restore_value: yes
initial_value: '0' # Hue: 0–360 degrees (starts at red)
- id: color_mode
type: bool
restore_value: no
initial_value: 'false' # Tracks if button is held for color mode
sensor:
- platform: rotary_encoder
id: wheel
name: "Rotary Encoder"
pin_a: GPIO5
pin_b: GPIO4
resolution: 2
filters:
- debounce: 0.01s
on_clockwise:
then:
- if:
condition:
lambda: 'return id(color_mode);'
then:
- lambda: |-
id(encoder_hue) = fmod(id(encoder_hue) + 10.0, 360.0);
ESP_LOGD("rotary", "Color mode: Hue set to %.1f°", id(encoder_hue));
- delay: ${wheel_delay}
- homeassistant.action:
action: light.turn_on
data_template:
entity_id: light.office_main_lights
hs_color: !lambda |-
return "[" + to_string(id(encoder_hue)) + ", 100.0]";
transition: "0"
else:
- lambda: |-
id(encoder_brightness) = std::min(100, id(encoder_brightness) + 4);
ESP_LOGD("rotary", "Brightness set to %d%%", id(encoder_brightness));
- delay: ${wheel_delay}
- homeassistant.action:
action: light.turn_on
data:
entity_id: light.office_main_lights
brightness: !lambda 'return (id(encoder_brightness) * 255) / 100;'
transition: "0"
# - delay: 250ms
on_anticlockwise:
then:
- if:
condition:
lambda: 'return id(color_mode);'
then:
- lambda: |-
id(encoder_hue) = fmod(id(encoder_hue) - 10.0 + 360.0, 360.0);
ESP_LOGD("rotary", "Color mode: Hue set to %.1f°", id(encoder_hue));
- delay: ${wheel_delay}
- homeassistant.action:
action: light.turn_on
data_template:
entity_id: light.office_main_lights
hs_color: !lambda |-
return "[" + to_string(id(encoder_hue)) + ", 100.0]";
transition: "0"
else:
- lambda: |-
id(encoder_brightness) = std::max(0, id(encoder_brightness) - 4);
ESP_LOGD("rotary", "Brightness set to %d%%", id(encoder_brightness));
- delay: ${wheel_delay}
- homeassistant.action:
action: light.turn_on
data:
entity_id: light.office_main_lights
brightness: !lambda 'return (id(encoder_brightness) * 255) / 100;'
transition: "0"
# - delay: 250ms
binary_sensor:
- platform: gpio
pin:
number: GPIO6
mode: INPUT_PULLUP
inverted: true
name: "Rotary Encoder Button"
filters:
- delayed_on: 50ms
- delayed_off: 50ms
on_multi_click:
- timing:
- ON for at most 0.5s
- OFF for at least 0.01s
then:
- logger.log: "Button pressed, toggling light"
- homeassistant.service:
service: light.toggle
data:
entity_id: light.office_main_lights
- timing:
- ON for at most 0.5s
- OFF for at most 0.5s
- ON for at most 0.5s
- OFF for at least 0.01s
then:
- logger.log: "Double-click detected, setting to white"
- homeassistant.action:
action: light.turn_on
data_template:
entity_id: light.office_main_lights
hs_color: !lambda |-
return "[" + to_string(id(encoder_hue)) + ", 0.0]";
transition: "0"
- timing:
- ON for at least 0.5s
then:
- logger.log: "Button held, entering color mode"
- lambda: 'id(color_mode) = true;'
on_release:
- logger.log: "Button released, exiting color mode"
- lambda: 'id(color_mode) = false;'
- platform: gpio
name: "Scene 1"
pin:
number: GPIO7
mode: INPUT_PULLUP
inverted: true
- platform: gpio
name: "Scene 2"
pin:
number: GPIO1
mode: INPUT_PULLUP
inverted: true
- platform: gpio
name: "Scene 3"
pin:
number: GPIO10
mode: INPUT_PULLUP
inverted: true
- platform: gpio
name: "Scene 4"
pin:
number: GPIO8
mode: INPUT_PULLUP
inverted: true
If chatGPT already writes your yaml why don’t you use it for debugging too?
Asking humans to fix your AI bullsh*tting sounds offensive at least
I see you have reading issues.