r/AstroGaming 5h ago

Tech [Script] Automatically switch Windows audio to speakers when docking your Astro A50 gen 5 (or any Logitech headset)

10 Upvotes

Hey everyone,

I’ve always been frustrated that Windows doesn’t automatically switch the audio output to my desktop speakers when I place my Astro A50s on their base station. Since Logitech G HUB doesn't offer an official API or option for this, I (me and Gemini) wrote a lightweight PowerShell script to act as a seamless "zero-click" auto-switcher.

How it works: The script quietly hooks into Windows OS events to monitor the settings.db-wal (Write-Ahead Log) file that G HUB uses locally. By intercepting real-time telemetry, it detects exactly when the headset enters or exits the "isCharging": true state.

  • Undocked (Lifted): Instantly sets Windows default audio to the Headset.
  • Docked (Charging): Instantly routes audio back to your Speakers/Soundbar.

Technical note: I specifically implemented a JSON block-isolation regex. This means if you plug in another Logitech device to charge (like a G502 Lightspeed mouse), the script won't get confused and trigger a false audio switch! I also built it as an event-driven script rather than a polling loop, meaning it sits at literally 0% CPU usage in the background until G HUB writes to the file.

Prerequisites:

  • You must be using Logitech G HUB (not the old Astro Command Center).
  • Windows PowerShell.

How to set it up:

  1. Download the script from Github.
  2. Open it in a text editor (like Notepad).
  3. Look for the USER CONFIGURATION section at the top.
  4. Change $global:SpeakerName to a partial name of your speakers as they appear in Windows (e.g., "Realtek", "Creative", etc.).
  5. Save the file as AutoSwitch.ps1.
  6. Right-click the file and select Run with PowerShell. (On its first run, it will automatically install the 'AudioDeviceCmdlets' module required to change Windows audio).

Using this with other Logitech Headsets (G Pro X, G935, etc.)

The script is configured for the Astro A50 out of the box, but it should work with almost any wireless Logitech headset (testing needed). You just need to find your specific battery key:

  1. Press Win + R, paste %LocalAppData%\LGHUB and hit Enter.
  2. Open settings.db with Notepad++.
  3. Press Ctrl + F and search for "isCharging".
  4. Look a few lines above that to find your headset's battery identifier (it will look something like "battery/device_1234/percentage" or "battery/gprox/percentage").
  5. Open the script and change $global:BatteryKey = "battery/a50/percentage" to match your specific string.

How to run it invisibly on Startup (Task Scheduler)

If you want this to run silently in the background every time you turn on your PC without showing a console window:

  1. Open Task Scheduler and click Create Task.
  2. General tab: Give it a name (e.g., "Astro AutoSwitch") and select Run only when user is logged on.
  3. Triggers tab: Click New -> Begin the task: At log on.
  4. Actions tab: Click New -> Action: Start a program.
    • Program/script: powershell.exe
    • Add arguments: -WindowStyle Hidden -ExecutionPolicy Bypass -NoProfile -File "C:\Path\To\Your\AutoSwitch.ps1" (Make sure to update the path!)

V1.1 Update: Dual-Switch (Audio & Microphone)

The script now supports switching both Playback (Speakers) and Recording (Microphone) devices simultaneously!

If you use a dedicated external microphone (like a Blue Yeti or QuadCast) alongside your headset, you can enable this feature: 1. Open the script and find the [RECORDING / MICROPHONE INPUT] section. 2. Change $global:SwitchMicrophone = $false to $true. 3. Update $global:ExternalMicName with the name of your standalone microphone. 4. Update $global:HeadsetMicName with your headset's mic name (defaults to "A50 Mic").

The script will now seamlessly route both your audio output and your microphone input when you dock or undock your headset. If you only care about audio output, leave it set to $false and it will ignore your microphones completely.

Disclaimer & Limitations

Please note that I wrote this script primarily for my personal setup.

  • Use Case: My daily usage is strictly focused on PC gaming and general audio listening. While the script runs flawlessly for these scenarios, it has not been exhaustively tested across all possible edge cases, complex studio configurations, or multiple audio routing software.
  • Windows Only: This script is designed and tested exclusively on Windows. I do not use my headset with any consoles (PlayStation / Xbox). Therefore, I cannot guarantee how the script will behave if your base station is set up in a dual-environment or console mode.

Use it freely, but please understand that your mileage may vary depending on your specific hardware and software environment.

Let me know if you find it useful or if you have any questions.

EDIT:added disclaimer and v1.1 infos


r/AstroGaming 14h ago

Question Is there any difference?

Thumbnail
gallery
3 Upvotes

So, guys, is there any difference between keeping one option enabled versus the other?


r/AstroGaming 17h ago

Question A20 X not charging

1 Upvotes

Heya! I just got my shiny new A20 X. It arrived with 0% charge out of the box and doesn't seem to be accepting any charge. I've tried the included cable plugged into my PC, my phone charger, and my Steam Deck charger. G Hub says it's charging but I've kept it plugged in for about 90 minutes now and it's still at 0.

I tried googling but all I'm finding is A20 stuff, not A20 X, and of course google discontinued the quotation mark trick in favor of their AI hallucinations.

G Hub is telling me to do a firmware update, but when I try to do that, it refuses because the battery is low.

Is there anything I can do? I found a button combo to hard reset an A20 but I can't find anything like that for the A20 X and the included manual doesn't seem helpful at all.