Here is the code for a rotary encoder used to control a thermostat:
- platform: rotary_encoder
id: myencoder
min_value: 1
max_value: 4
pin_a:
number: D6
mode: INPUT_PULLUP
pin_b:
number: D7
mode: INPUT_PULLUP
# on_clockwise:
# - if:
# condition:
# switch.is_on: heat_adjust
# then:
# - climate.control:
# id: livingroom_thermostat
# target_temperature: !lambda "return id(livingroom_thermostat).target_temperature + (5.0/18);"
# on_anticlockwise:
# - if:
# condition:
# switch.is_on: heat_adjust
# then:
# - climate.control:
# id: livingroom_thermostat
# target_temperature: !lambda "return id(livingroom_thermostat).target_temperature - (5.0/18);"
on_value:
- if:
condition:
switch.is_on: preset_adjust
then:
- if:
condition:
- lambda: "return id(myencoder).state == 1;"
then:
- climate.control:
id: livingroom_thermostat
custom_preset: Night
else:
- if:
condition:
- lambda: "return id(myencoder).state == 2;"
then:
- climate.control:
id: livingroom_thermostat
custom_preset: Day
else:
- if:
condition:
- lambda: "return id(myencoder).state == 3;"
then:
- climate.control:
id: livingroom_thermostat
custom_preset: Away
else:
- if:
condition:
- lambda: "return id(myencoder).state == 4;"
then:
- climate.control:
id: livingroom_thermostat
custom_preset: Summer
The on_value section only works if the on_clockwise and on_anticlockwise sections are commented out. If those are uncommented, then they work but the on_value section does not. Can these commands be made to work together, or, if not, could anyone suggest another approach?