ESParagus Media Center

ESP32-based, Home Assistant compatible streaming audio player

May 21, 2024

Project update 4 of 8

ESPHome Native Integration

by Andriy

For this week’s update, I’d like to demonstrate how to integrate Esparagus boards into Home Assistant using ESPHome native integration.

Last update, I demonstrated integration using the slim-proto protocol, which I like for two reasons: first, you have as many music nodes as you like and all can play in multi-room configuration or independently - you get to decide; second, the nodes still work as standalone devices, so you can interact with them directly with your phone.

One thing that is different about ESPHome is the Home Assistant integration is much deeper, so to say. But first things first…

Configuration - HiFi Esparagus Example

With every ESP32-based device, you start with the esphome web installer, which will give you an ESPHome base install and Wifi configuration in minutes.

Next, navigate to your Home Assistant (assuming you have your ESPHome integration already installed) and adopt the newly created node:

This configuration will activate board peripherals and publish it to the HA:

substitutions:
  devicename: hifi-esparagus
  long_devicename: "HiFi Esparagus"

esphome:
  name: "${devicename}"
  name_add_mac_suffix: false
  comment: "${long_devicename}"
  on_boot:
    priority: 800
    then:
    - media_player.volume_set:
        id: hifiesparagus
        volume: 50%

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
api:
  encryption:
    key: !secret esphome_api_key

# Allow Over-The-Air updates
ota:
  password: !secret esphome_ota_password

wifi:
  ssid: !secret esphome_wifi_ssid
  password: !secret esphome_wifi_password
  ap:
    ssid: "$devicename Fallback Hotspot"
    password: !secret esphome_ap_password

captive_portal:

psram:
  mode: octal
  speed: 80MHz

i2s_audio:
  i2s_lrclk_pin: GPIO25
  i2s_bclk_pin: GPIO26

media_player:
  - platform: i2s_audio
    name: $long_devicename
    id: hifiesparagus
    dac_type: external
    i2s_dout_pin: GPIO22
    mode: stereo
    on_play: 
      then:
        - light.addressable_set: 
            id: rgb_light
            red: 0
            green: 50%
            blue: 0
    on_pause: 
      then:
        - light.addressable_set: 
            id: rgb_light
            red: 50%
            green: 0
            blue: 0    

remote_receiver:
  pin: 
    number: GPIO39
    inverted: true
    mode:
      input: true
  dump: samsung
  on_samsung:
    then:
    - if:
        condition:
          - lambda: 'return (x.data == 0xE0E0E01F);'
        then:
          - media_player.volume_up: 
              id: hifiesparagus
    - if:
        condition:
          - lambda: 'return (x.data == 0xE0E0D02F);'
        then:
          - media_player.volume_down: 
              id: hifiesparagus

light:
  - platform: esp32_rmt_led_strip
    id: rgb_light
    rgb_order: GRB
    pin: GPIO33
    num_leds: 1
    rmt_channel: 1
    chipset: ws2812
    name: "RGB led"

Not the shortest config, I know, so a few words of explanation.

Bonus: Automation Example

The true power of the native speaker in the HA is the use of automations. Here’s one example that I find useful. This simple automation will pronounce every hour between 8AM and 9PM. Another one is used to announce bedtime and so on… you get the point.

Loud and Louder Esparagus

Loud Esparagus configuration is pretty much the same as for the HiFi used above. You just need to change the names. As for Louder Esparagus, it is a little bit more complicated, since it needs the I2C commands to initialize.

Luckily, the community beat me to it and Michael from espthings.io has already prepared a header file and some simple instructions on how to spin up Louder Esparagus using a header file and few lines of configuration.

Future Thoughts

A few more options are still to discover, for example by publishing IR commands as a binary sensor to the Home assistant you may bind HA commands to the IR remote, swicthing on the lights, music, etc. Or, you may want to connect the whole LED strip to the single RGB led on the Esparagus board and play around with audio visualisations. It should be good fun to try more things with it.

Stay tuned for snapclient implementation in next week’s update.


Sign up to receive future updates for ESParagus Media Center.

Subscribe to the Crowd Supply newsletter, highlighting the latest creators and projects