I want to migrate from espeasy to esphome for my rotary encoders but I have 2 issues that I cant resolve.
What I would like is the following:
Turn a lights brightness down by value X on every click when tuning the rotary encoder to the left – Turn a lights brightness up by value X on every click when tuning the rotary encoder to the right.
Change (step thru) the scenes of the (hue) light on a double click so that every time I do a long press, the next scene is activated.
The issue I can’t resolve is that te rotary encoder reports a value from -[virtually_endless] to +[virtually_endless]. With espeasy I was able to set a value from a lower limit of 0 to a upper limit of 100 and then use this value to set the lights brightness_pct. That worked perfectly.
Now I to need to have an automation that responds to the value changing negativ (turn left) or the value changing positive (turn right) and then on a right turn take the current light brightness_pct value and add +5 until a upper limit of 100… The same for the left turns with a lower limit of 0.
I found this post that is a move in the right direction, but since I am not a coder, I can’t quit figure it out.
This is what I have for now:
esphome:
name: rotary01
## living rotary encoder 1
platform: ESP8266
board: d1_mini
wifi:
ssid: 'SSID'
password: 'XXXXXXXXXXXXXXXXXXXX'
# Enable logging
logger:
# Enable Home Assistant API
api:
password: 'XXXXXXXXX'
ota:
password: 'XXXXXXXXX'
# encoder 1
sensor:
- platform: rotary_encoder
name: "Living Rotary 1"
id: livingrotary1
pin_a: D6
pin_b: D7
filters:
- or:
- debounce: 0.1s
- delta: 10
### insert the mission code here ;)
binary_sensor:
- platform: gpio
pin: D5
id: switch1
name: "Living switch 1"
filters:
- invert:
on_multi_click:
- timing:
- ON for at most 0.4s
- OFF for at most 0.4s
- ON for at most 0.4s
- OFF for at least 0.2s
then:
- logger.log: "Double Clicked"
### enter code here ;)
- timing:
- ON for 0.6s to 3s
- OFF for at least 0.3s
then:
- logger.log: "Single Long Clicked"
- homeassistant.service:
service: input_boolean.toggle
data:
entity_id: input_boolean.radio_woonkamer
- timing:
- ON for at most 0.5s
- OFF for at least 0.4s
then:
- logger.log: "Single short Click"
- homeassistant.service:
service: light.toggle
data:
entity_id: light.woonkamer_groep
Tried that, but that doesn’t work. If you limit the value to 100 like this and turn the encoder past the 100 limit, it will keep counting. So if you turn right 10 clicks past 100, you would have to turn left 10 clicks, before your value will lower to 99.
In this log I went up 10 clicks and then 10 clicks down again, using your suggestion:
[13:04:12][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 95.00000 steps with 0 decimals of accuracy
[13:04:15][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 96.00000 steps with 0 decimals of accuracy
[13:04:16][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 97.00000 steps with 0 decimals of accuracy
[13:04:16][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 98.00000 steps with 0 decimals of accuracy
[13:04:17][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 99.00000 steps with 0 decimals of accuracy
[13:04:18][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 100.00000 steps with 0 decimals of accuracy
[13:04:18][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 100.00000 steps with 0 decimals of accuracy
[13:04:18][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 100.00000 steps with 0 decimals of accuracy
[13:04:19][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 100.00000 steps with 0 decimals of accuracy
[13:04:20][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 100.00000 steps with 0 decimals of accuracy
[13:04:20][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 100.00000 steps with 0 decimals of accuracy
[13:04:21][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 100.00000 steps with 0 decimals of accuracy
[13:04:22][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 100.00000 steps with 0 decimals of accuracy
[13:04:23][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 100.00000 steps with 0 decimals of accuracy
[13:04:24][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 100.00000 steps with 0 decimals of accuracy
[13:04:25][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 100.00000 steps with 0 decimals of accuracy
[13:04:26][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 100.00000 steps with 0 decimals of accuracy
[13:04:27][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 99.00000 steps with 0 decimals of accuracy
[13:04:28][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 98.00000 steps with 0 decimals of accuracy
[13:04:29][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 97.00000 steps with 0 decimals of accuracy
[13:04:30][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 96.00000 steps with 0 decimals of accuracy
[13:04:30][D][sensor.sensor:131]: 'Woonkamer 1 Rotary 1': Sending state 95.00000 steps with 0 decimals of accuracy
sensor:
- platform: rotary_encoder
name: "Woonkamer 1 Rotary 1"
id: woonkamer1rotary1
pin_a: D6
pin_b: D7
filters:
- or:
- debounce: 0.1s
- delta: 10
- lambda: |-
if (x < 0.0) set x = 0.0;
if (x > 100) set x = 100;
return x;
It validates, but won’t compile:
Compiling .pioenvs/rotary01/src/main.cpp.o
src/main.cpp: In lambda function:
src/main.cpp:75:23: error: 'set' was not declared in this scope
if (x < 0.0) set x = 0.0;
^
src/main.cpp:75:27: error: expected ';' before 'x'
if (x < 0.0) set x = 0.0;
^
src/main.cpp:76:22: error: 'set' was not declared in this scope
if (x > 100) set x = 100;
^
src/main.cpp:76:26: error: expected ';' before 'x'
if (x > 100) set x = 100;
^
*** [.pioenvs/rotary01/src/main.cpp.o] Error 1
========================== [ERROR] Took 5.56 seconds ==========================
I’m trying the same thing and saw that the min/max values are in the works currently:
So we just have to wait a bit or be brave and try the dev branch.
But the other question is: how do we get the rotary encoder’s value into the PWM output? I’m currently using the config below, but it has problems: the values set with the rotary encoder are different from the values that I can send with MQTT. With step 1 of the rotary encoder the LED is still off, and with step 2 it’s rather bright already. With MQTT I can send ‘{“state”:“ON”,“brightness”:38}’ and get a very dimly lit LED.
Alas when I turn the knob too fast (?) I get a “Guru Meditation Error”:
[12:56:10][D][sensor.sensor:131]: 'Rotary Encoder': Sending state 101.00000 steps with 0 decimals of accuracy
[12:56:10][D][light.state:462]: 'LED-Platte' Turning ON
[12:56:10][D][light.state:469]: Brightness: 40%
[12:56:10][D][main:052]: brightness set to 39.61%
[12:56:11][D][sensor.sensor:131]: 'Rotary Encoder': Sending state 105.00000 steps with 0 decimals of accuracy
[12:56:11][D][light.state:462]: 'LED-Platte' Turning ON
[12:56:11][D][light.state:469]: Brightness: 41%
[12:56:11][D][main:052]: brightness set to 41.18%
[12:56:11][D][sensor.sensor:131]: 'Rotary Encoder': Sending state 111.00000 steps with 0 decimals of accuracy
[12:56:11][D][light.state:462]: 'LED-Platte' Turning ON
[12:56:11][D][light.state:469]: Brightness: 44%
[12:56:11]Guru Meditation Error: Core 1 panic'ed (Cache disabled but cached memory region accessed)
[12:56:11]Core 1 register dump:
[12:56:11]PC : 0x40080f8d PS : 0x00060034 A0 : 0x8008104c A1 : 0x3ffc0bb0
INFO Need to fetch platformio IDE-data, please stand by
INFO Running: platformio run -d esphome1 -t idedata
WARNING Decoded 0x40080f8d: esphome::sensor::RotaryEncoderSensor::process_state_machine_()
[12:56:13]A2 : 0x3ffb3550 A3 : 0x3ffb18c0 A4 : 0x80081edf A5 : 0x3ffb18c0
[12:56:13]A6 : 0x0000dea0 A7 : 0x3ffb196c A8 : 0xbad00bad A9 : 0x0000011b
[12:56:13]A10 : 0x3ffb34f8 A11 : 0x3ffb18a0 A12 : 0x80081c80 A13 : 0x3ffb1890
[12:56:13]A14 : 0x0000dea0 A15 : 0x3ffb196c SAR : 0x00000013 EXCCAUSE: 0x00000007
[12:56:13]EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff
[12:56:13]Core 1 was running in ISR context:
[12:56:13]EPC1 : 0x40062235 EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x40080f8d
[12:56:13]
[12:56:13]Backtrace: 0x40080f8d:0x3ffc0bb0 0x40081049:0x3ffc0bd0 0x40081099:0x3ffc0bf0 0x40081ac5:0x3ffc0c10 0x40062232:0x00000000
WARNING Found stack trace! Trying to decode it
WARNING Decoded 0x40080f8d: esphome::sensor::RotaryEncoderSensor::process_state_machine_()
WARNING Decoded 0x40081049: esphome::sensor::RotaryEncoderSensor::encoder_isr_()
WARNING Decoded 0x40081099: __onPinInterrupt at esp32-hal-gpio.c
WARNING Decoded 0x40081ac5: _xt_lowint1 at /Users/ficeto/Desktop/ESP32/ESP32/esp-idf-public/components/freertos/xtensa_vectors.S:1105
[12:56:13]
[12:56:13]Rebooting...
I already tried the beta and dev channels (with beta, it’s the same, with dev the rotary encoder doesn’t seem to do anything at the moment). I guess I try posting an issue at Github.
It looks like Home Assistant can’t handle this on a (hue) group of 6 lights.
If I use this on a single light the result is fully acceptable, but on a group of 6 lights the result is that the lights dimm extremely slow. I can sometime take up till 5-10 seconds before the last service call actually reaches the lights. I am having the same problem when I handle the dimming in a home assistant automation like this:
There is some lag with both light strips - but it wasn’t too bad. Also, I noticed that every time the light is turned off (brightness = 0) and then turned on, the color/temperature/hue is reset back to white. Can you think of a way to retain the light color or is it a home assistant setting?
I’m going to play around for a bit and see what else I can change.
I’m interested in flashing the esp8266 lights with ESPHome and see if they communicate faster using the API instead of MQTT.
Also, have you figured out how to use the “reset” pin as a button when you “click” it?
This part definitely stopped working for me after the update to 1.14 and I have been unable to get it working again with lambda as Otto suggested. I am no coder, so If anyone could help me out, it would be greatly appreciated.
I want to pass a value of 1 to 100 (percent) to the brightness_pct of a home assistant entity upon rotating the encoder.
Hi, esphone rotary encoder sensor. I’m also using the rotary encoder to control the LED light of cold and warm color temperature and brightness adjustment recently. Can you share the complete profile you are currently using? Thank!