I have a Chromecast Audio and I am trying to set the media player volume before the media player starts playing. I can pull up the device in the native Google Home app, view the current volume level, adjust the volume to whatever I want, connect to it with a media source (Pandora, Spotify, whatever), and then start playing music.
I would like to do the same thing using Home Assistant, but I run into an error when attempting to view and set the volume using media_player.volume_set: âmedia player has no attribute âvolume_levelââ
It appears that if the media player is not playing, the media player has no idea what volume it is set to since it is in the state of âoffâ and the attribute âvolume_levelâ does not exist when âoffâ. The native Google Home app does not have this limitation; it can view and adjust the volume when no media is playing. Everything in my automation script works fine in Home Assistant once the media player starts playing since the âvolume_levelâ attribute is then available.
Is there a way to know the current volume level and set a media playerâs volume before the media connects and starts playing (like the Google Home app does)?
How would I get the media playerâs current volume before playing? I would like to set the volume only if it is louder or quieter than certain thresholds.
I would like to set the volume to .15 if it is currently <.15 and set to .25 if it is >.25 before playing. Is there a reason the attributes are available only when playing and not before? The Google Home app has access to them before playing.
Go to Developer Tools > States and locate your speaker.
Ensure it is off.
It has no volume attribute when itâs off.
Without a volume attribute, you canât check the speakerâs current volume level.
If you call media_player.turn_on, the volume attribute will be available. In other words, as long as the state is something other than off, you can access the attribute.
Step 0 can be a test to determine if the speaker is off before proceeding to turn it on. Similarly, step 2.5 can be a test to determine if the current volume is not the desired volume. These tests can be implemented with choose.
Well dang it, that didnât work. I manually set the state to various not âoffâ values, but none of them would reveal any other details of the media player, specifically volume_level; the attributes were exactly the same as âoffâ when the state was manually set to not âoffâ.
Should this be a feature request? The values are available to not Home Assistant (Google Home), so there should be a way to make them available to Home Assistant.
It might be a characteristic of the Chromecast Audio or how Home Assistant interacts with it.
What I had described above was tested with an off-brand device (battery powered weatherproof speaker supporting Chromecast). For all intents and purposes, itâs a portable Google Mini. Turning it on sets its state to idle and causes the volume attribute to appear (and a few others).
So this is exactly what I was looking for thanks! Question- for my application I need the speaker to bump up the volume to 8 but after the automation runs I would like it to go back to where it was, 50% for example, I am sure it is not that hard but I am struggling to figure it out- Any idea how to do this?
If you want your automaton to dynamically adjust the volume, youâd need the automaton to read and store the volume value in a text helper, bump up the volume, do the thing, then reset the volume to the stored value from the helper when the thing is done. (I do something similar with storing other state values for future related automaton uses.)
When I wake up with a sound system loud, windows almost break, because mediaplayer started with volume on â1â, yes thanks, my wife honoured you now,