Volume issue with the Cast (Google) integration

My wife has been complaining that she had issue casting music to our Google Cast device for some time. The main issue she has is with the volume when she is casting to a cast group (3 devices). She reduce the volume to a certain point but everytime song finishes and a new one start, the volume of all the device in the group goes back to a certain level, 30,30 and 45% to be exact.

I’ve long believed it was her iPhone or Google stuff that was acting up (as is usually the case) but I recently decided to determine the cause of this behavior.

After multiple test, I realized that the problem seems to be coming from my Home Assistant cast integration. The process to arrive at that conclusion was pretty straight forward (once I’d eliminated everything else):

  • If I remove the cast integration, volume of all devices stay the same when a new song start
  • If the cast integration is present and configured in Home Assistant, the volume automatically change to 30,30,and 45% on my 3 devices when a new song start
  • If music is playing and I add the cast integration to my Home Assistant, it automatically change the volume of my devices (not just when a new song starts) as soon as the integration is added

That’s a really weird behavior as I don’t really use the cast integration of HA that much. I’ve got 3 automation configured with it:

  • If it detect one of the device member of a group playing, I start my soundbar in the living room and set its audio input to the 3.5mm aux in (using the Harmony integration) where a chromecast audio is connected to the soundbar
  • The second automation is a reverse of the previous one (stop the soundbar when a specific device is not playing)
  • Plays a TTS message on a specific cast device if an intrusion is detected by the alarm system in HA

Anyone got an idea why the integration would be trying to manage the volume of the cast device as soon as it discover them?

Well, while I was writing my post, I thought it might be a good idea to just check those 3 automations, as they were added years ago.

And that’s where I discovered that in my past wisdom (or lack of), I also added actions to set the volume on the media player when starting the soundbar.

What’s weird is that now, everytime the song change, the automation is getting triggered, which wasn’t the case some month ago. I guess the media player goes in a !=playing state briefly between each song, which cause the trigger.