Hello,
I’m trying to make my own wireless controller with a rotary encoder that would control various devices. I am currently testing brightness on light.
I did it, but I don’t like the logic of control.
When I set the brightness level via the web interface (example 100%) and then use the encoder value jumps to the latest set encoder value, I want it to change the current state smoothly.
If someone already has such a control ready, can they give it to me?
I tried to get value through:
{{states ('controller_rotary_encoder') | int}}
{{states.controller_rotary_encoder.state | int}}
{{states ('controller_rotary_encoder.state') | int}}
but it always throws me a value of “0” which does not move when the encoder changes.
My configuration:
Frimware on ESP-12f:
sensor:
- platform: rotary_encoder
name: "Controller Rotary Encoder"
pin_a: GPIO4
pin_b: GPIO5
min_value: 0
max_value: 10
resolution: 1
Automations action (values jumps):
data_template:
brightness_pct: '{{states.sensor.controller_rotary_encoder.state | int*10 }}'
entity_id: light.desk
service: light.turn_on
Note: It is necessary to use “brightness_pct” because “brightness” cannot light up from zero.
Thanks for help.
Have you ever found a solution for this?
I am noticing the same issue and I would like to fix it.
Thanks.
maxym
July 27, 2021, 2:37pm
3
some lights have delta brightness control instead of absolute values. so you can send fixed value on every step of rotary controller. for example -5 for dimming by 5 units
I do believe I have a delta set, is that maybe my problem?
### Rotary encoder 1
- platform: rotary_encoder
name: "Bedroom Rotary 1"
id: bedroom_rotary1
pin_a: D5
pin_b: D7
filters:
- or:
- debounce: 0.2s
- delta: 5
resolution: 1
min_value: 1
max_value: 100
on_value:
then:
- homeassistant.service:
service: light.turn_on
data_template:
entity_id: group.bedroom_lights
brightness_pct: "{{ brightness_1 | int }}"
variables:
brightness_1: !lambda 'return id(bedroom_rotary1).state * 1;'
Hi, this is my last configure, i hope so help.
# Define values on startup
on_boot:
priority: -100
then:
- lambda: id(rotary_encoder_device1).publish_state(true);
- lambda: id(rotary_encoder_device2).publish_state(false);
- lambda: id(rotary_encoder_device3).publish_state(false);
# Physical GPIO Rotary encoder device
sensor:
- platform: rotary_encoder
id: id_rotary_encoder
name: "Controller Rotary Encoder"
pin_a: GPIO4
pin_b: GPIO5
min_value: 0
max_value: 10
filters:
- or:
- debounce: 0.1s
- delta: 5
resolution: 1
on_value:
then:
- if:
condition:
and:
- binary_sensor.is_on: rotary_encoder_device1
#- binary_sensor.is_on: re_up_down
then:
- homeassistant.service:
service: light.turn_on
data_template:
entity_id: light.desk
brightness_pct: "{{ brightness | int }}"
variables:
brightness: !lambda 'return id(id_rotary_encoder).state * 10;'
- if:
condition:
binary_sensor.is_on: rotary_encoder_device2
then:
- homeassistant.service:
service: light.turn_on
data_template:
entity_id: light.desk
brightness_pct: "{{ brightness | int }}"
variables:
brightness: !lambda 'return id(id_rotary_encoder).state * 10;'
- if:
condition:
binary_sensor.is_on: rotary_encoder_device3
then:
- homeassistant.service:
service: light.turn_on
data_template:
entity_id: light.desk
brightness_pct: "{{ brightness | int }}"
variables:
brightness: !lambda 'return id(id_rotary_encoder).state * 10;'
binary_sensor:
# Imaginary (Virtual) hellper devices
- platform: gpio
name: "RE_UP"
id: re_up
pin:
number: GPIO4
# mode: INPUT_PULLDOWN_16
filters:
- delayed_off: 10ms
on_press:
then:
- if:
condition:
and:
- binary_sensor.is_on: re_up
- binary_sensor.is_off: re_down
then:
- logger.log: "First GPIO4"
- lambda: id(re_up_down).publish_state(true);
- platform: gpio
name: "RE_DOWN"
id: re_down
pin:
number: GPIO5
# mode: INPUT_PULLDOWN_16
filters:
- delayed_off: 5ms
on_press:
then:
- if:
condition:
and:
- binary_sensor.is_on: re_down
- binary_sensor.is_off: re_up
then:
- logger.log: "First GPIO5"
- lambda: id(re_up_down).publish_state(false);
- platform: template
name: "UP/DOWN Detect"
id: re_up_down
- platform: template
name: "Device 1"
id: rotary_encoder_device1
- platform: template
name: "Device 2"
id: rotary_encoder_device2
- platform: template
name: "Device 3"
id: rotary_encoder_device3
# Physical GPIO binary devices
- platform: gpio
pin:
number: GPIO12
inverted: false
name: "Controller Rotary Encoder Button"
id: rotary_encoder_button
on_multi_click:
# Switch between imaginary hellper devices by Double Click
- timing:
- OFF for at most 1s
- ON for at most 1s
- OFF for at most 1s
- ON for at least 0.01s
then:
- logger.log: "Double Clicked"
- lambda: |-
if (id(rotary_encoder_device1).state) {
id(rotary_encoder_device1).publish_state(false);
id(rotary_encoder_device2).publish_state(true);
id(rotary_encoder_device3).publish_state(false);
} else {
if (id(rotary_encoder_device2).state) {
id(rotary_encoder_device1).publish_state(false);
id(rotary_encoder_device2).publish_state(false);
id(rotary_encoder_device3).publish_state(true);
} else {
if (id(rotary_encoder_device3).state) {
id(rotary_encoder_device1).publish_state(true);
id(rotary_encoder_device2).publish_state(false);
id(rotary_encoder_device3).publish_state(false);
} else {
}
}
};
- timing:
- OFF for at most 1s
- ON for at least 0.5s
then:
- if:
condition:
binary_sensor.is_on: rotary_encoder_device1
then:
- logger.log: "Single Clicked Device 1"
- homeassistant.service:
service: light.toggle
data:
entity_id: light.desk
- timing:
- OFF for at most 1s
- ON for at least 0.5s
then:
- if:
condition:
binary_sensor.is_on: rotary_encoder_device2
then:
- logger.log: "Single Clicked Device 2"
- homeassistant.service:
service: light.turn_off
data:
entity_id: light.desk
- timing:
- OFF for at most 1s
- ON for at least 0.5s
then:
- if:
condition:
binary_sensor.is_on: rotary_encoder_device3
then:
- logger.log: "Single Clicked Device 3"
- homeassistant.service:
service: light.turn_on
data:
entity_id: light.desk
1 Like