Thats a great idea, I might try to implement it myself. It may get a bit complicated however.
This could be done using
BlueTask to poll what bt devices are available every 30~ secs whenever music is playing and if you're connected to your home wifi and/or you're connected to chromecast (however you want to detect that, perhaps notification?), storing the closest bluetooth beacon in a variable. You can tell which bluetooth beacon is closest by measuring its signal strength, which is the RSSI value (also returned by BlueTask)
If the stored "closest" beacon is no longer the beacon of the highest RSSI (and the difference between the RSSI values is significant), have tasker reconnect to the new closest beacon in the returned list. If the speakers aren't the same model, it may cause problems correctly choosing the closest beacon, since the RSSI vs Distance may vary by speaker.
How you connect to the chromecast varies by the music playing app (I am not familiar with how audio chromecast plays regular music; as such, neither am i familiar with how tasker can control this.
this may help). I myself use spotify, which can directly control chromecast devices. Since I don't believe there is an
android intent for controlling these chromecast devices through spotify, I will likely rely on my main computer to switch devices by brute force in the Windows Spotify app using
EventGhost, and
AutoRemote (
eg plugin) to control them. For general purpose, use
AutoNotification to start playing music again by notification if needed (or Spotify intents, or device music play (action in tasker))
Good luck, if you have any questions I will gladly help :)
Miles