Home Assistant Convert Media Player Volume
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.
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
- Turn on the media_player in home assistant.
- Slide the volume slider all the way to the left.
- Open Developer Tools / States page.
- Find the media_player adjusted in step 2.
- Record the numerical value for
volume_level
in the configurationmin_volume/media_player
. - 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.
- Turn on the media_player in home assistant.
- Slide the volume slider all the way to the right.
- Open Developer Tools / States page.
- Find the media_player adjusted in step 2.
- Record the numerical value for
volume_level
in the configurationmax_volume/media_player
. - Record the numerical value on your device in the configuration
max_volume/device
.