I have a rotary encoder setup in an Esphome device to control the volume of my soundbar. It works but has curious behaviour.
Setup:
sensor:
- platform: rotary_encoder
name: "Volume Knob"
pin_a: GPIO33
pin_b: GPIO19
on_clockwise:
- homeassistant.service:
service: media_player.volume_set
data_template:
entity_id: media_player.sonos_arc
volume_level: "{{ state_attr('media_player.sonos_arc', 'volume_level') + 0.01}}"
on_anticlockwise:
- homeassistant.service:
service: media_player.volume_set
data_template:
entity_id: media_player.sonos_arc
volume_level: "{{ state_attr('media_player.sonos_arc', 'volume_level') - 0.01 }}"
When the volume on the soundbar is above 6 (technically speaking 0.06), the rotary encoder is able to control the volume. As soon as I hit 6 (or 56 I found out later) it cant increase the volume to 7. It can decrease it all the way to 0 and up again till 6.
When I adjust the volume with something else to a value above 6, I can control the volume again with the rotary controller.
The logging is showing that the rotary encoder is still registering movement clockwise or counter clockwise, it just stops changing the volume.
Some logging:
[22:56:45][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 8.00
[22:56:45][D][sensor:094]: 'sonos_volume_int': Sending state 8.00000 with 1 decimals of accuracy
[22:56:46][D][sensor:094]: 'Volume Knob': Sending state 180.00000 steps with 0 decimals of accuracy
[22:56:46][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '7'
[22:56:46][D][text_sensor:064]: 'sonos_volume': Sending state '7'
[22:56:46][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 7.00
[22:56:46][D][sensor:094]: 'sonos_volume_int': Sending state 7.00000 with 1 decimals of accuracy
[22:56:46][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '7'
[22:56:46][D][text_sensor:064]: 'sonos_volume': Sending state '7'
[22:56:46][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 7.00
[22:56:46][D][sensor:094]: 'sonos_volume_int': Sending state 7.00000 with 1 decimals of accuracy
[22:56:47][D][sensor:094]: 'Volume Knob': Sending state 179.00000 steps with 0 decimals of accuracy
[22:56:47][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '6'
[22:56:47][D][text_sensor:064]: 'sonos_volume': Sending state '6'
[22:56:47][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 6.00
[22:56:47][D][sensor:094]: 'sonos_volume_int': Sending state 6.00000 with 1 decimals of accuracy
[22:56:47][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '6'
[22:56:47][D][text_sensor:064]: 'sonos_volume': Sending state '6'
[22:56:47][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 6.00
[22:56:47][D][sensor:094]: 'sonos_volume_int': Sending state 6.00000 with 1 decimals of accuracy
[22:56:49][D][sensor:094]: 'Volume Knob': Sending state 178.00000 steps with 0 decimals of accuracy
[22:56:49][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '5'
[22:56:49][D][text_sensor:064]: 'sonos_volume': Sending state '5'
[22:56:49][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 5.00
[22:56:49][D][sensor:094]: 'sonos_volume_int': Sending state 5.00000 with 1 decimals of accuracy
[22:56:49][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '5'
[22:56:49][D][text_sensor:064]: 'sonos_volume': Sending state '5'
[22:56:49][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 5.00
[22:56:49][D][sensor:094]: 'sonos_volume_int': Sending state 5.00000 with 1 decimals of accuracy
[22:56:50][D][sensor:094]: 'Volume Knob': Sending state 177.00000 steps with 0 decimals of accuracy
[22:56:50][D][sensor:094]: 'Volume Knob': Sending state 176.00000 steps with 0 decimals of accuracy
[22:56:51][D][sensor:094]: 'Volume Knob': Sending state 175.00000 steps with 0 decimals of accuracy
[22:56:51][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '4'
[22:56:51][D][text_sensor:064]: 'sonos_volume': Sending state '4'
[22:56:51][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 4.00
[22:56:51][D][sensor:094]: 'sonos_volume_int': Sending state 4.00000 with 1 decimals of accuracy
[22:56:51][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '4'
[22:56:51][D][text_sensor:064]: 'sonos_volume': Sending state '4'
[22:56:51][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 4.00
[22:56:51][D][sensor:094]: 'sonos_volume_int': Sending state 4.00000 with 1 decimals of accuracy
[22:56:52][D][sensor:094]: 'Volume Knob': Sending state 174.00000 steps with 0 decimals of accuracy
[22:56:52][D][sensor:094]: 'Volume Knob': Sending state 173.00000 steps with 0 decimals of accuracy
[22:56:52][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '3'
[22:56:52][D][text_sensor:064]: 'sonos_volume': Sending state '3'
[22:56:52][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 3.00
[22:56:52][D][sensor:094]: 'sonos_volume_int': Sending state 3.00000 with 1 decimals of accuracy
[22:56:52][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '3'
[22:56:52][D][text_sensor:064]: 'sonos_volume': Sending state '3'
[22:56:52][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 3.00
[22:56:52][D][sensor:094]: 'sonos_volume_int': Sending state 3.00000 with 1 decimals of accuracy
[22:56:53][D][sensor:094]: 'Volume Knob': Sending state 172.00000 steps with 0 decimals of accuracy
[22:56:54][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '1'
[22:56:54][D][text_sensor:064]: 'sonos_volume': Sending state '1'
[22:56:54][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 1.00
[22:56:54][D][sensor:094]: 'sonos_volume_int': Sending state 1.00000 with 1 decimals of accuracy
[22:56:54][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '1'
[22:56:54][D][text_sensor:064]: 'sonos_volume': Sending state '1'
[22:56:54][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 1.00
[22:56:54][D][sensor:094]: 'sonos_volume_int': Sending state 1.00000 with 1 decimals of accuracy
[22:56:55][D][sensor:094]: 'Volume Knob': Sending state 173.00000 steps with 0 decimals of accuracy
[22:56:55][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '2'
[22:56:55][D][text_sensor:064]: 'sonos_volume': Sending state '2'
[22:56:55][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 2.00
[22:56:55][D][sensor:094]: 'sonos_volume_int': Sending state 2.00000 with 1 decimals of accuracy
[22:56:55][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '2'
[22:56:55][D][text_sensor:064]: 'sonos_volume': Sending state '2'
[22:56:55][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 2.00
[22:56:55][D][sensor:094]: 'sonos_volume_int': Sending state 2.00000 with 1 decimals of accuracy
[22:56:55][D][sensor:094]: 'Volume Knob': Sending state 174.00000 steps with 0 decimals of accuracy
[22:56:55][D][sensor:094]: 'Volume Knob': Sending state 175.00000 steps with 0 decimals of accuracy
[22:56:55][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '3'
[22:56:55][D][text_sensor:064]: 'sonos_volume': Sending state '3'
[22:56:55][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 3.00
[22:56:55][D][sensor:094]: 'sonos_volume_int': Sending state 3.00000 with 1 decimals of accuracy
[22:56:55][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '3'
[22:56:55][D][text_sensor:064]: 'sonos_volume': Sending state '3'
[22:56:55][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 3.00
[22:56:55][D][sensor:094]: 'sonos_volume_int': Sending state 3.00000 with 1 decimals of accuracy
[22:56:56][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '4'
[22:56:56][D][text_sensor:064]: 'sonos_volume': Sending state '4'
[22:56:56][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 4.00
[22:56:56][D][sensor:094]: 'sonos_volume_int': Sending state 4.00000 with 1 decimals of accuracy
[22:56:56][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '4'
[22:56:56][D][text_sensor:064]: 'sonos_volume': Sending state '4'
[22:56:56][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 4.00
[22:56:56][D][sensor:094]: 'sonos_volume_int': Sending state 4.00000 with 1 decimals of accuracy
[22:56:56][D][sensor:094]: 'Volume Knob': Sending state 176.00000 steps with 0 decimals of accuracy
[22:56:56][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '5'
[22:56:56][D][text_sensor:064]: 'sonos_volume': Sending state '5'
[22:56:56][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 5.00
[22:56:56][D][sensor:094]: 'sonos_volume_int': Sending state 5.00000 with 1 decimals of accuracy
[22:56:56][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '5'
[22:56:56][D][text_sensor:064]: 'sonos_volume': Sending state '5'
[22:56:56][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 5.00
[22:56:56][D][sensor:094]: 'sonos_volume_int': Sending state 5.00000 with 1 decimals of accuracy
[22:56:57][D][sensor:094]: 'Volume Knob': Sending state 177.00000 steps with 0 decimals of accuracy
[22:56:58][D][sensor:094]: 'Volume Knob': Sending state 178.00000 steps with 0 decimals of accuracy
[22:56:58][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '6'
[22:56:58][D][text_sensor:064]: 'sonos_volume': Sending state '6'
[22:56:58][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 6.00
[22:56:58][D][sensor:094]: 'sonos_volume_int': Sending state 6.00000 with 1 decimals of accuracy
[22:56:58][D][homeassistant.text_sensor:017]: 'sensor.sonos_volume': Got state '6'
[22:56:58][D][text_sensor:064]: 'sonos_volume': Sending state '6'
[22:56:58][D][homeassistant.sensor:024]: 'sensor.sonos_volume': Got state 6.00
[22:56:58][D][sensor:094]: 'sonos_volume_int': Sending state 6.00000 with 1 decimals of accuracy
[22:56:59][D][sensor:094]: 'Volume Knob': Sending state 179.00000 steps with 0 decimals of accuracy
[22:57:00][D][sensor:094]: 'Volume Knob': Sending state 180.00000 steps with 0 decimals of accuracy
[22:57:01][D][sensor:094]: 'Volume Knob': Sending state 181.00000 steps with 0 decimals of accuracy
Later I found that 56 seems to have the same issue. And looking at the log, it seems to skip some steps a few times.
What is going on here? Am I missing something?