Using GenAI to configure Home Assistant control of an AV Receiver Link to heading

I used AI to help me figure out how to get my smart home to control audio settings for my home theater. This was a three hour project that enabled me to merge three of my tech hobbies, how refreshing!

I used Anthropic Claude to help me generate scripts for Home Assistant to toggle AVR Audyssey modes that use calibrated sound profiles generated by OCA’s A1 Evo Acoustica.

If that sentence made no sense, read on! If you want to jump over the home theater basics, skip to A1 Evo for Room Correction instead of Audyssey

Home theater audio calibration Link to heading

When enjoying a movie in a home theater, one of the goals is to get nice separation of sounds. When a plane goes whizzing by, you want to hear the sound traveling from one side of the room to the other (or ideally sound like it’s flying overhead if you have speakers above you).

To do this, your audio/video receiver (AVR) needs to take the movie’s audio signal and distribute it evenly through the speakers in your setup. This can vary based on qualities like room setup, how far apart your speakers are, speaker quality and power, even the flooring can have an impact on how sound travels to your ears.

To help with calibration of your speakers, AVR creators include “room correction” for your AVR that can use a microphone in your actual room to measure sound coming out of each speaker. For my Denon AVR, it’s called “Audyssey” and there are other options like “Dirac Live”.

Audyssey is software inside the AVR that will generate frequency sweeps (chirps coming out of each speaker) and listen through its microphone to measure how far away your main listening position is from each speaker. With all the chirps recorded, Audyssey can calculate how loud the AVR should be sending sounds through each of the speakers in your setup.

A1 Evo for room correction instead of Audyssey Link to heading

For about a year I’ve been following someone called the Obsessive Compulsive Audiophile (OCA) who has been maintaining a useful project to benefit home theater enthusiasts. Called the Audyssey One (or A1) project, it has several iterations named Nexus, Evo, Acoustica, etc.

While Denon’s Audyssey gets the job done, A1 Evo has become popular due to the rigor that OCA puts into the process and develops in the open. He claims that his methods come out better than Audyssey and after trying it for myself anecdotally I agree. The first time I tried A1 I started hearing movie sounds out of speakers I’d never heard before. It made a big difference for me personally.

Each month, OCA puts out newer versions that make the process more automated (e.g. integrations with REW signal processing software, or over the network updates to your AVR). It’s become really easy to get started, especially with the latest version, A1 Evo Acoustica!

What does this have to do with Home Assistant? Link to heading

In A1 Evo Acoustica, the author explains that there are two sets of signals that are uploaded to the AVR: a set for Audyssey “Reference” mode and a set for “Flat” mode. The guidance is that for low-level listening (e.g. at nighttime) you should set your AVR to Reference and it’ll use his calibrated settings for that profile. When listening at normal (loud) movie levels, Flat should be used.

I was worried about having an easy way to switch between these two modes, as pulling out my remote would be annoying. Home Assistant was my first thought!

Home Assistant is an open source home automation suite that integrates with many common vendors. Rather than using a proprietary setup like Google Home, Amazon Alexa, Apple HomeKit or others - HA makes it easy to integrate all kinds of products in a consistent control interface. The only downside is that you have to run it yourself on a computer or cloud server.

I have the HA app installed on my Android phone to make it easy to control things like my thermostat, lights, or see who’s at the door (using integrations for Ecobee, Philips Hue, and UniFi Protect respectively). Having a button to control my Denon AVR to toggle between Reference and Flat modes would be ideal.

GenAI to the rescue…? Link to heading

I stepped up to Anthropic Claude to begin the process of seeing whether it could generate an HA configuration for me to copy/paste.

Asking Claude about Denon AVR Audyssey settings in HA

This is promising, I already have the Denon AVR integration installed (I use it to dim the lights or close curtains in my media room when the AVR turns on and I’m ready to watch something). Now to see if Claude can produce the code for me:

RS: provide a dashboard button yaml snippet to toggle audyssey flat or reference

I will spare all the details, but Claude produced YAML snippets for a Button I can add to my dashboard, and a Script I’d need to add.

I looked a little closer to find that it provided the wrong code: Claude’s implementation was for configuring the Sound Mode for the AVR (e.g. Stereo, Dolby, DTS), not the Audyssey MultEQ XT32 setting.

I asked a more in different ways and it was unable to find an answer.

Human in the loop Link to heading

Undeterred, I knew that Denon has a webserver running on its AVR:

Denon AVR web-based configuration

There must exist some API I can invoke, worst case - and best case, the Denon integration for HA author must have included it.

Denon AVR HA integration

Yes! It appears you can send commands to the AVR, but I’d have to trawl through the linked PDF to understand (and my simple mind couldn’t find what I was looking for).

Denon AVR codes

AI understanding Link to heading

I pointed Claude to the PDF – but ran into a token limit for my free account. I don’t play favorites, so I tried the same with ChatGPT and got what I was looking for:

ChatGPT Denon Commands

Bingo! From the integration documentation, this command needs to be added to a hardcoded string and provided to the get_command HA action:

HA test of Denon AVR commands

A quick test with the HA Developer tools and I was able to confirm that it was properly adjusting the Audyssey MultEQ XT32 setting!

Some more tweaking in Claude and I was able to define a helper (to maintain the state of the setting), a button for my dashboard, and a script to tie it all together. I’ll put the full YAML at the bottom of this article.

HA button for toggling Audyssey settings

Conclusion and Next Steps Link to heading

Functionally, I’m done! I was able to use AI and my own knowledge to implement the outcome I was seeking. Some observations:

  • Denon is excellent for making its APIs available on local networks for others to control their AVRs
  • OCA is awesome for providing his integrations and algorithms to the community
  • HA is very powerful and can do everything
  • GenAI is a great help to get projects started and avoid my analysis paralysis which is real

I’m not completely done yet, as I have some other ideas:

  • Implement an HA automation to detect sound levels (or time of day?) and automatically switch modes
  • Make the button look prettier
  • Find out if I can interrogate the current setting on the AVR so I don’t have to maintain state in HA itself with a Helper

But knowing me, good is perfect enough. I hope you learned something too!

Resulting YAML code for HA Link to heading

Hidden Entity (to maintain state) Link to heading

input_select:
  audyssey_mode:
    name: Audyssey Mode
    options:
      - Reference
      - Flat
    initial: Reference
    icon: mdi:equalizer

Script Link to heading

alias: Toggle Audyssey Mode
sequence:
  - choose:
      - conditions:
          - condition: state
            entity_id: input_select.audyssey_mode
            state: Reference
        sequence:
          - data:
              command: /goform/formiPhoneAppDirect.xml?PSMULTEQ:FLAT
            action: denonavr.get_command
            target:
              device_id: 839eac42994b3714b49cebafa5543c7f
          - target:
              entity_id: input_select.audyssey_mode
            data:
              option: Flat
            action: input_select.select_option
    default:
      - data:
          command: /goform/formiPhoneAppDirect.xml?PSMULTEQ:AUDYSSEY
        action: denonavr.get_command
        target:
          device_id: 839eac42994b3714b49cebafa5543c7f
      - target:
          entity_id: input_select.audyssey_mode
        data:
          option: Reference
        action: input_select.select_option

Button Link to heading

show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: script.toggle_audyssey_mode
  data: {}
entity: input_select.audyssey_mode
name: Audyssey Mode
show_state: true
icon: |
  {% if is_state('input_select.audyssey_mode', 'Reference') %}
    mdi:equalizer
  {% else %}
    mdi:equalizer-outline
  {% endif %}