Display Device Volume with AppDaemon

Home Assistant Convert Media Player Volume

hacs_badge

Convert Media Player Volume app for AppDaemon.

This creates a sensor that represents your hardwares volume level.

Home assistant typically represents it’s volume from 0.0 to 1.0. Many hardware devices have ranges outside these values. This app will convert the home assistant ranges to your devices ranges!

I personally use sync my yamaha receiver with home assistant. It helps me display the units on this custom button.

image

    type: custom:button-card
    layout: icon_label
    color: auto
    aspect_ratio: 1/1
    show_state: true
    show_name: true
    show_label: true
    entity: switch.zone_1
    name: Zone 1
    label: >
      [[[
        var entity_id = "sensor.yamaha_receiver_volume";
        var level = Math.round(parseFloat(states[entity_id].state));
        var muted = entity.attributes.is_volume_muted;
        if (muted) {
          return 'muted';
        }
        return (level ? level : '0') + ' dB';
      ]]]
    styles:
      grid:
        - grid-template-rows: 42px auto 42px
        - grid-template-columns: 42px auto
      card:
        - border-radius: 15px
        - margin: 5px 5px 0px 0px
        - padding: 0px 0px
      icon:
        - height: 30px
        - width: 30px
      name:
        - justify-self: start
        - padding: 0px 10px
        - font-size: 13px
      label:
        - align-self: end
        - padding: 7px
        - font-size: 11px
        - font-weight: bold
        - font-family: Helvetica
      state:
        - font-size: 11px
        - font-family: Helvetica
        - text-transform: capitalize
        - font-weight: bold
        - align-self: end
        - justify-self: start
        - padding: 9px 10px
      lock:
        - align-items: flex-end
    tap_action:
      action: toggle
    state:
      - value: "on"
        styles:
          card:
            - --paper-card-background-color: rgba(40, 40, 40)
            - box-shadow: 0px 0px 10px 3px rgba(228, 94, 101)
          icon:
            - color: rgba(228, 94, 101)
          name:
            - color: white
          state:
            - color: white
          label:
            - color: white
      - value: "off"
        styles:
          label:
            - color: rgba(0, 0, 0, 0.0)

Installation

Download the convert_media_volume directory from inside the apps directory to your local apps directory, then add the configuration to enable the hacs module.

Example App configuration

Basic

#  0 to 100 volume range
zone1_volume:
  module: convert_media_volume
  class: ConvertMediaVolume
  media_player: media_player.bravia

Alexa Media Player

# Converts volume range from 0 to 10.
zone1_volume:
  module: convert_media_volume
  class: ConvertMediaVolume
  media_player: media_player.alexa
  min_volume:
    device: 0.0
    media_player: 0.0
  max_volume:
    device: 10.0
    media_player: 1.0
  precision: 0

decibel

# Converts to decibels (dB) - Typical Yamaha Media Player Configuration
zone1_volume:
  module: convert_media_volume
  class: ConvertMediaVolume
  media_player: media_player.yamaha_receiver
  unit_of_measurement: dB
  min_volume:
    device: -80.0
    media_player: 0.2
  max_volume:
    device: 0.0
    media_player: 1.0
  precision: 0

App Configuration

key optional type default description
module False string convert_media_volume The module name of the app.
class False string ConvertMediaVolume The name of the Class.
media_player False string entity_id of the media_player.
name True str <media player name> Volume Friendly name of the Media Player.
min_volume True map A map of the device min volume level and media_player volume level.
max_volume True map A map of the device max volume level and media_player volume level.
precision True int 1 precision of the sensor. e.g. 100.0 has a precision of 1, 1 number after the decimal place.
log_level True 'INFO' | 'DEBUG' 'INFO' Switches log level.

Min Map Configuration

key optional type default description
device True float 0.0 Device volume at the lowest possible level.
media_player True float 0.0 media_player.<entity_id>.attributes.volume_level at the lowest possible level.

Max Map Configuration

key optional type default description
device True float 100.0 Device volume at the highest possible level.
media_player True float 1.0 media_player.<entity_id>.attributes.volume_level at the highest possible level.

Recommended Setup

Getting the miminum volume

  1. Turn on the media_player in home assistant.
  2. Slide the volume slider all the way to the left.
  3. Open Developer Tools / States page.
  4. Find the media_player adjusted in step 2.
  5. Record the numerical value for volume_level in the configuration min_volume/media_player.
  6. Record the numerical value on your device in the configuration min_volume/device.

Getting the maximum volume

You don’t need to record the maximum. You just need a value higher than the minimum. The further away, the better.

  1. Turn on the media_player in home assistant.
  2. Slide the volume slider all the way to the right.
  3. Open Developer Tools / States page.
  4. Find the media_player adjusted in step 2.
  5. Record the numerical value for volume_level in the configuration max_volume/media_player.
  6. Record the numerical value on your device in the configuration max_volume/device.

Sorry to ask such a basic question, but I am still ab it new to the platform and cannot find the answer elsewhere online. I’d installed the integration using HACS but wnere does the code actually go? It’s a sensor so I tried putting it into my sensor.yaml file but HA gave me some errors. I see s ome stuff online talking about an apps.yaml file in the apps directory but I have no such file. Thanks.

It’s an appdaemon app, you need appdaemon as an addon.

But you don’t need this. You can use the compensation integration to do this now. It’s the main example for that integration.

What I’d really been hoping to do was something similar to the home theater volume control example on t his page so that I could expose an entity to Alexa asking her to set the volume whereas now when I do it it;s now the level I asked for due to the way Yamaha has their volume range setup, even if I change the range from 0-97 instead of decibels.

Just expose your media player to Alexa. She handles them & volume up/down commands