Hello,
I am trying to create a dimmable light that I can change over my phone AND using a rotary encoder. It all works fine, except the fact, that my encoder always keeps the last state and doesnt update to the current value of the light. The result is that (If I changed something on my phone) was soon as I turn the knob, the light jumps to the last state of the rotary encoder instead of adding/subtracting to the current light state.
So my question is: How can I read the current state of brightness of my light component in order to pass it to the encoder via:
light:
- platform: binary # or any other platform
# ...
on_state:
- sensor.rotary_encoder.set_value:
id: my_rotary_encoder
value: *??VALUEOFLIGHT??*
What do I need to put in for ??VALUEOFLIGHT?? ?
Thank you in advance!
My whole code:
esphome:
name: d1-lichtleiste-schlafzimmer
esp8266:
board: d1_mini
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "3sh6HmIFsLs+12r/HOZo44VHjrFe0BGNLPDKmG0ERZw="
ota:
password: "a6dfa5e175c5db6aaeb97190cfdb5f2f"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "D1-Lichtleiste-Schlafzimmer"
password: "GWOnDwJwq5vi"
captive_portal:
# Example configuration entry
light:
- platform: monochromatic
name: "Lichtleiste Bett"
id: lichtleiste_bett
output: output_pwm_1
# Output für Lichtleiste
output:
- platform: esp8266_pwm
id: output_pwm_1
min_power: 0.03
zero_means_zero: true
pin:
number: D8
inverted: false
# Example configuration entry
sensor:
- platform: rotary_encoder
id: my_rotary_encoder
name: "Rotary Encoder"
min_value: 0
max_value: 100
resolution: 2
publish_initial_value: true
pin_a:
number: D1
inverted: true
mode:
input: true
pullup: true
pin_b:
number: D2
inverted: true
mode:
input: true
pullup: true
on_value:
then:
- light.turn_on:
id: lichtleiste_bett
brightness: !lambda "return x/100;"
transition_length: 31ms