Setting Sonos Light Volume via HomeKit

Hi everyone,

I want to control my Sonos sound system via HomeKit (announce loudly through Siri in %) and turn a light on using media_player.sonos. Unfortunately, I’m not making progress and I’m not getting any wiser from the code on the official Home Assistant page. Maybe someone can help me with the code or the process.

Best regards,

Double lasts better. :wink:

You can create a Template Light.
Just replace the Media Player entity media_player.xyz by using your own.

#configuration.yaml
light:
  - platform: template
    lights:
      sonos_volume:
        friendly_name: "Sonos Volume"
        level_template: "{{ (state_attr('media_player.xyz', 'volume_level') * 255 ) |int }}"
        value_template: "{{ (state_attr('media_player.xyz', 'volume_level')) | float > 0 }}"
        turn_on:
          service: media_player.media_play
          target:
            entity_id: media_player.xyz
          data: {}
        turn_off:
          service: media_player.media_stop
          target:
            entity_id: media_player.xyz
        set_level:
          service: media_player.volume_set
          target:
            entity_id: media_player.xyz
          data:
            volume_level: "{{ brightness / 255}}"
1 Like