Home assistant API and Rotary knob for sonos volume

Hello everyone long time lurker, Ive been working on trying to get a physical control knob for my sonos speakers so i can quickly change the volume when needed. I followed this template on github petrepa esphome desk controller. I modified it for esp32 board. And tried to get things working. In the esphome logs i cee the volume increase and decrease with knob rotation but nothing happens in home assistant logbook.
Do I need to make a call before captive portal to define the home assistant entity?
Here is my code.
Thank you

esphome:
  name: sonos-den-controller
  friendly_name: sonos-den-controller

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "4AGkzCOReqUQGqchZoVs7hGcV///fSk4mzSxnmD/9To="

ota:
  password: "ef37e70cb42f3bebb6907f17a7067102"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Sonos-Den-Controller"
    password: "NGEuMVcA7VY3"

captive_portal:

substitutions:
  device_name: sonos-den-contoller
  friendly_name: sonos den controller

binary_sensor:
  # VOLUME KNOB BUTTON ----------------------
  - platform: gpio
    pin:
      number: GPIO19
      #mode: INPUT_PULLUP
      inverted: true
    name: "${friendly_name} Volume Switch Button"
    on_press:
      - homeassistant.service:
          service: media_player.play_pause
          data:
            entity_id: media_player.kitchen
sensor:
  - platform: rotary_encoder
    name: "${friendly_name} Rotary Encoder"
    pin_b:
      number: GPIO23
      mode: INPUT
    pin_a:
      number: GPIO18
      mode: INPUT
    on_clockwise:
      - homeassistant.service:
          service: media_player.volume_up
          data:
            entity_id: media_player.kitchen
      - logger.log: "Turned Clockwise"
    on_anticlockwise:
      - homeassistant.service:
          service: media_player.volume_down
          data:
            entity_id: media_player.kitchen
      - logger.log: "Turned Anti Clockwise"
      

Have you added the ESPHome device to HA via the integrations page?

1 Like

i’m such an idiot!
Thank you. I’ve been searching and reflashing all day. Simple error. Thank you thank you thank you.

1 Like

Common mistake. Good luck with the project.

Huge Sucess with controlling SONOS volume on Phillips Hue Rotary Dial

works a treat !