I turned my audio interface into a brightness slider for my smart lights with Home Assistant


I’ve been looking into new ways to build out my Home Assistant set-up to make use of the various bits of tech that I have lying around, and I recently came across the GoXLR HACS integration. This integration can link up with the third-party GoXLR Utility (which is still updated, unlike the official GoXLR App, which is in a state of purgatory), so that you can control your audio interface through Home Assistant.

However, I only use three of the four faders on my GoXLR Mini; the leftmost fader is my game audio, next is my chat audio (think Google Meet, Zoom, Discord), and then it’s my music audio. The fourth is a microphone controller by default, but I don’t ever need it; if I’m not speaking, I’m just pressing my mute key instead. Because of that, I looked into using the GoXLR to control the light above my head at my desk, so that I could turn up or down the brightness with a quick fader.

To my surprise, it’s worked perfectly. I can use my GoXLR to control the light brightness above my head by reading the volume percentage that it reports to Home Assistant, converting it to a brightness, and then setting that brightness level on a specified light. I’ll walk you through my entire setup, as it’s ridiculously simple for how well it works.

Setting up GoXLR Utility and the Home Assistant integration

GoXLR Home Assistant integration, showing all of the controls

You’ll first need to make sure you have HACS installed. It’s an easy set-up, and it’s honestly a vital part of any Home Assistant installation these days. There are so many great, unofficial integrations for Home Assistant that you can install, and practically everything is supported in some way or another. I came across the GoXLR Utility integration completely by accident when scrolling through, and I’m sure there are many you’d find that would suit your needs, too.

Each fader is represented by a media player with this integration, and the media player is always marked as “Playing.” There’s a volume controller which will be directly reflected on your PC for each of them, so I changed my fourth fader to the “Samples” audio channel, as I don’t ever play anything through this channel anyway. The audio level doesn’t actually matter, as it’s just a way for me to communicate a percentage to Home Assistant on a physical medium that’s always on my desk.

The first thing we need to do with our automation is listen for any volume changes in the specific media player that we’re monitoring, so in this case, it’s our GoXLR Samples media player, and we watch the volume-level automation. Next, before firing our automation, we do a comparison of the before state and the after state of the volume by saving it to a float to ensure that there actually is a change.

GoXLR automation to match volume to brightness

This is the code in my “And if” block:

{{ trigger.to_state.attributes.volume_level | float
!= trigger.from_state.attributes.volume_level | float }}

On the surface, this additional check may seem redundant; after all, we already got here with a change of state in the volume control, right? However, I’ve found that the GoXLR integration can fire it when I turn on my PC, for example, as the overall item is instantiated even if the volume level is the same. It’s basically just an insurance policy, as otherwise my light can turn on when I don’t actually want it to.

Finally, my “Then do” block performs an action on my light to match the brightness level to the volume level, as both are measured from 0% to 100%. It takes the volume percentage as a float and saves the float value into a variable called “vol”, and then scales that value back to an actual percentage.

{% set vol = state_attr('media_player.pc_goxlr_sample', 'volume_level') | float(0) %} {{ (vol * 100) | round(0) }}

So, for example, if my volume is set to 73%, it takes this value, saves it as 0.73, then scales it back up to 70 as a raw number rather than a value associated with volume. This number can then be read as a percentage to set the light brightness to.

Finally, click the menu button in the top right of the automation editor, and click Show YAML editor. Add this line at the very bottom of the automation without any indentation:

mode: restart

I previously tested this with “queued” mode as I thought that it would result in a smoother transition as I moved the fader up and down. However, there’s actually a queue limit in Home Assistant that I would frequently hit, and changing this to restart cancels the previous execution and replaces it with the most recent. It’s not as gradual, but it’s completely reliable. Without changing the execution mode, you can only have one execution of the automation running at a time, so it will finish the last recognized movement before changing the brightness again.

I turned an old phone into a Home Assistant dashboard for my desk

Home Assistant is everything you make it

A photo of Home Assistant Dashboard with custom cards

With Home Assistant, I’ve seen a lot of criticism leveled at it for being overly complex or difficult to manage, but the truth is that most things simply just work. If you want to “overcomplicate” it, you absolutely can, and that’s the beauty of it. Like how Linux can catch a lot of flak for the same reasons, you can go your whole life in Home Assistant or Linux without dealing with anything advanced if you don’t want to. I’d much rather have the tools available and never use them than have them locked off and never accessible in the first place.

This has been a fantastic addition to my office space, and it’s a great bit of convenience to simply move a fader on my interface to turn up and down the brightness. I still have a smart switch on my desk for turning on and off the light, but the GoXLR gets the job done for a quick brightness shift when I need it. I’ve been so impressed with how well this has worked, and I love that I can find random integrations on HACS which turn into big quality of life upgrades completely for free.



Source link

Previous Article

Best Buy's Father's Day sale is ending soon - 19 deals I'd buy on TVs, cheap smart home, AirPods, and more from $25

Next Article

AOSU Security Cameras Wireless Outdoor Home System, True 2K HD Night Vision, No Subscription, 240-Day Battery Life, 166° Wide View, Spotlight & Siren Alarm, Motion Alert, Support 2.4G & 5G WiFi Router

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨