Rotary encoder cant change volume past 6 or 56

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?

Just a thought, some audio devices have a control to stop you turning the volume up too high, to stop you blowing your ears or speakers.

That does not seem the case here, as I can increase the volume when it is already higher then 6. Also, I can adjust the volume with the service media_player.volume_set to higher values then 6 without any issue (from within HA).
And a volume state of 6 (technically 0.06) is almost muted. A normal volume level is between 16 and 22 (0.16 and 0.22), depending on the source.

Normal volume level is, if course, 11. :rofl:

But sure I have any other ideas sorry.

Although what integration is the sound bar?

A Spinal Tap reference, I like you :slight_smile:

It’s a Sonos ARC sound bar.

I’m also not rulling out that the rotary encoder is shit. I tried several (bought a pack of 5, a few years ago), but the 3 I tried all have the same issue. Ordered some new rotary encoders, hopefully of better quality.

1 Like

Changing the increment to +/- 0.02 got even weirder results. When started at 0 and incremented with 2 just like it was programmed. But after 12 it only incremented to 13, it kept going on with odd numbers untill somewhere in the 50. And when decreasing the volume it went from odd to even arround the number 30.

I’ve change the code a bit:

sensor:
  - platform: rotary_encoder
    name: "Volume Knob"
    pin_a: GPIO33
    pin_b: GPIO19
    on_clockwise:
      - homeassistant.service:
          service: media_player.volume_up
          data_template:
            entity_id: media_player.sonos_arc
    on_anticlockwise:
      - homeassistant.service:
          service: media_player.volume_down
          data_template:
            entity_id: media_player.sonos_arc

Now it does nice increments of 2, no issues arround the numbers 6 or 56. For now it’s solved. But still curious what I did wrong with the volume_set.

Bought some other rotary encoders. Quality seems better, they feel sturdier. Still same behaviour with the volume_set action. Keeping it to volume_up/down for now.