ZMC, a complete home audio system

ZMC, a complete home audio system

zmc_v5-01

I’ve a wired audio system at residence to all of the rooms in my home. For extra then 10 years this was operating on a XAP800 unit and managed by HA. But not too long ago I had encountered some critical issues. Why? Well the unit consumes 35W on a regular basis so I began to show it off at evening or once I was not at residence. This wasn’t one thing the outdated unit favored and broke down. 6 months later the substitute unit additionally gave up. Now, additionally my final substitute went lifeless and it was time to make one thing else.
Based on the years of utilizing the XAP800 I do know what’s a should to have and what’s by no means used. Like having quantity management for each room which is overkill. Most of the rooms stayed on the identical quantity degree for all of the years. So right here is my scope for this venture.

Design concerns

  • Low on energy consumption
  • 10 outputs
  • 2 inputs (extra on this later)
  • Volume management on some outputs
  • All outputs might be combined
  • All outputs might be muted
  • All outputs amps will likely be 3W every
  • All outputs will likely be mono (extra on that later)
  • Modular construct for straightforward restore
  • ESP32-S3 managed by HA/ESPHome(residence Assistant)

I’ll describe my design choices intimately and clarify why they’re made this manner. First of all, the 3W output. Why simply 3W and nothing extra? Well as a result of it’s actually sufficient for me. I do know I’ll get a dialogue corresponding to that is higher or that’s to mushy. But my audio system is used for bulletins and background music solely. Imagine the background music in elevators and retailers. Not annoying loud, however it may be nonetheless. 3W has confirmed to be completely sufficient. Nothing extra, nothing much less. But in case you want extra then it’s going to increase the prices for bigger amps, higher wires, connectors, filters, elements, energy provide and extra energy consumption.

Having mentioned about this let’s proceed.

step-01

The easiest setup is simply an ESP32-S3 N16R8 which has sufficient pins, CPU and reminiscence. Connect this with a MAX98357a 3W DAC module, a swap and a speaker. Looks good however is somewhat ineffective on this type.
But let’s take a more in-depth take a look at the swap. If you’ll be able to management this swap with the ESP then it will likely be already a lot better. To do that you should use a 4066 chip. This IC received 4 controllable switches in a single small bundle.
The MAX98357 has a balanced output so it’s essential swap 2 wires. And if you need the output to be in stereo then you definitely want 4 switches. This leads to one 4066 IC per output!! That is rather a lot. Because i don’t want stereo I can have 2 output per IC, however it may be higher. If you’ll be able to take away the balanced output then one wire of the output might be linked to GND and it’s essential swap only one wire. Doing so you’ll be able to swap 4 outputs with only one 4066 IC.
Also pumping 3W output into the tiny 4066 switches could be very dangerous for the sound high quality and end in plenty of crosstalk between the outputs. To resolve this you can also make the output van the MAX98357 unbalanced with a audio trafo, however a a lot better answer could be utilizing a unique DAC. That is what i did and used a PCM5102 which received a unbalance headphone line output, however the output can also be accessible on the pins.

step-02
As you’ll be able to see there may be now a amplifier positioned after the 4066 swap. The NS8002 3W amplifiers I exploit are small and utilized in battery powered gadgets and that make them extra vitality environment friendly. They have additionally a mute pin in order that checks a design standards too. At the enter I place a trim pot meter, so I can high quality tune the sound degree in every room.

step-03

If copy this stage a number of occasions and join them to the output of the DAC you’ll be able to distribute the audio to the totally different rooms and switch it on or off as you please. It takes one 4066 IC for each 4 output channels. That implies that for my requirement of 10 outputs I want 2,5 or 3 4066 IC’s.

Using HA means this the ESP is seen as a media participant to which you’ll stream audio from no matter supply you want. I exploit primarily a web radio supply but additionally streaming providers, native saved audio information and generated TTS messages when one thing is prepared just like the washer.

step-06

When doing a particular announcement you typically wish to make these to a sure room with out effecting the music performed in one other room. Or you wish to stream a unique audio supply too simply to the bed room and nowhere else. For that you simply want a second ESP media participant as enter. This ESP get it’s personal switches, however their outputs are linked to the inputs of the amplifiers. By switching the audio in a room off and the announcement swap on you’ll be able to stream your announcement to that room with out disturbing the opposite rooms. This will want additionally 2,5 4066 IC which brings the overall chip rely at 5 4066 IC’s.

step-04

Now let’s discuss quantity management. By now 23 pins are used to regulate 10 outputs and perhaps 1 for the onboard LED to offer you some standing suggestions. It is feasible to make use of digital pot meter, however they devour 2 pins every. That implies that it’s important to select which output can have quantity management or offload the amount management to the opposite ESP. I simply wanted quantity management in 4 rooms. The front room for apparent causes, kitchen due to the hood, bed room and toilet for when the the fan kicks in. This implies that I’ll want 8 further pins. Finding that many pins that aren’t strapping pins and different reserved pins will likely be tough. Also the digital pot meters I noticed want particular coding and circuitry to perform.
Can I do higher? Yes I can.
A LED/LDR combo might be merely diy made and managed with only one pin. I used a SMD LED with was very vivid. That means it’s important to do some testing to make the appropriate combo. The resistor to the LED is 4K7 and the pin provide the PWM 3V3 output. But nonetheless I needed to cowl the LED with a chunk of white paper to damp the brightness sufficient. In the yaml file of the ESP you’ll be able to see that i management the output pin from 0 to fifteen in steps of 0.1. This gave me sufficient management over the LED brightness and thus the amount.

step-05

That depart me to 1 extra issues. To cowl the backyard space I exploit a backyard speaker set that get it’s enter from a FM transmitter module. Audio is fed in by way of 3.5mm jack plug. This implies that the enter is unbalanced and it’s possible you’ll keep in mind my speak concerning the MAX98357 having a balanced output. The identical is true for the NS8002 amplifiers. To give you the chance the stream audio to my backyard is should make output unbalanced. I did that with a 600:600 audio trafo.

The finish end result

zmc_v5-07

Just as all the things else additionally the amount management is made modular. The models are wrapped in warmth shrink to maintain exterior mild that may have an effect on the amount management out.

![Amps and volume units]

zmc_v5-08

On the appropriate the amount module and on the left the amplifiers modules. All outputs labelled. Wiring is wrapped collectively and for straightforward disassembly and meeting I made connectors on them so they’ll match properly and safe and the one a technique.

![Fun bit]

zmc_v5-09

Nothing that provides to the perform of the unit, however it’s enjoyable and simply seems good. I exploit the onboard LED to show the standing of the unit however when it’s all boxed in then it’s of no use. To clear up this I made a small 3D printed adapter that cowl the onboard LED. An insert that maintain glass fiber wires plugged in and the wires are let loose to the entrance panel.

![Amps and volume units]

zmc_v5-10

In the previous I had issues with speaker wire connections. But this time I exploit the appropriate answer to attach wires fast and properly. 10 outputs, 1 additional unbalanced one and a spare.

And for the principle requirement, saving energy.
Power consumption lower than 1W @ 5V


substitutions:
  title: "zmc"
  friendly_name: 'Zoelen Media Center'
  startup_volume: '80%'
  zmc_radio: 'ZMC radio'
  preset_woonkamer_volume: '2.0'
  preset_badkamer_volume: '3.0'
  preset_slaapkamer_volume: '3.8'
  preset_keuken_volume: '4.5'

# AMPLIFIERS
  zmc_output1_2: 'Woonkamer'
  zmc_output3: 'Keuken'
  zmc_output4: 'Badkamer'
  zmc_output5: 'Slaapkamer'
  zmc_output6: 'Achtertuin'
  zmc_output7_8: 'Hobbykamer'
  zmc_output9: 'Kleedkamer'
  zmc_output10: 'Hal'
  zmc_output11: 'Zolder'  
  zmc_output12: 'Washok'  
# MUTE CONTROLE
  zmc_mute1: 'Mute washok'  
  zmc_mute2: 'Mute zolder'  
  zmc_mute3: 'Mute hal'  
  zmc_mute4: 'Mute kleedkamer'  
  zmc_mute5: 'Mute hobbykamer'
  zmc_mute6: 'Mute achtertuin'  
  zmc_mute7: 'Mute keuken'  
  zmc_mute8: 'Mute slaapkamer'  
  zmc_mute9: 'Mute badkamer'  
  zmc_mute10: 'Mute woonkamer'  
# VOLUME CONTROL  
  zmc_volume1: 'Keuken quantity'
  zmc_volume2: 'Woonkamer quantity'
  zmc_volume3: 'Slaapkamer quantity'
  zmc_volume4: 'Badkamer quantity'  

# ================================
# === Please don't edit under ===
# ================================
  music_player_idle_id: "1"
  music_player_playing_id: "2"
  music_player_muted_id: "3"
  esp_speaker_not_ready_phase_id: "10"
  esp_speaker_error_phase_id: "11"


esphome:
  title: ${title}
  friendly_name: ${friendly_name}
  min_version: 2024.6.0
  name_add_mac_suffix: false
  venture:
    title: AA_van_Zoelen.ZMC
    model: '5.0.0'
  on_boot:
    precedence: 600
    then:
      - script.execute: control_led
      - delay: 30s
      - media_player.volume_set:
          id: media_out
          quantity: ${startup_volume}      
      - if:
          situation:
            lambda: return id(init_in_progress);
          then:
            - lambda: id(init_in_progress) = false;
            - script.execute: control_led


esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  framework:
    kind: arduino


psram:
  mode: octal # Please change this to quad for N8R2 and octal for N16R8
  pace: 80MHz


globals:
  - id: init_in_progress
    kind: bool
    restore_value: false
    initial_value: "true"
  - id: esp_speaker_phase
    kind: int
    restore_value: false
    initial_value: ${esp_speaker_not_ready_phase_id}


logger:


api:
  encryption:
    key: !secret api_key
  on_client_connected:
    - script.execute: control_led
  on_client_disconnected:
    - script.execute: control_led


ota:
  platform: esphome


wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  on_connect:
    - script.execute: control_led
  on_disconnect:
    - script.execute: control_led

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: !secret fallback_ssid
    password: !secret fallback_password


captive_portal:


i2s_audio:
  - id: i2s_audio_bus
    i2s_lrclk_pin: GPIO6
    i2s_bclk_pin: GPIO7


media_player:
  - platform: i2s_audio
    id: media_out
    title: ${zmc_radio}
    dac_type: exterior
    i2s_audio_id: i2s_audio_bus
    i2s_dout_pin: GPIO8
    mode: mono

    on_play:
      - logger.log: "Playback began!"
      - lambda: id(esp_speaker_phase) = ${music_player_playing_id};
      - if:
         situation:
           swap.is_on: status_led
         then:
           - script.execute: control_led     
    on_pause:
      - logger.log: "Playback paused!"
      - lambda: id(esp_speaker_phase) = ${music_player_muted_id};
      - if:
         situation:
           swap.is_on: status_led
         then:  
           - script.execute: control_led         
    on_idle:
      - logger.log: "Playback completed!"
      - lambda: id(esp_speaker_phase) = ${music_player_idle_id}; 
      - if:
         situation:
           swap.is_on: status_led
         then: 
           - script.execute: control_led


swap:
  - platform: template
    title: "Status LED"
    id: status_led
    optimistic: true
    restore_mode: RESTORE_DEFAULT_ON
    icon: mdi:bell
    on_turn_off:
    - mild.turn_off:
        id: onboard_led
    on_turn_on:
    - script.execute: control_led

#https://esphome.io/guides/configuration-types#config-pin-schema
# Positions as seen from under. Leftside is 1
# SWITCHES
  - platform: gpio # WOONKAMER
    pin: 
      quantity: 11
      mode:
        output: True
        pulldown: true
    id: zmc_output1_2
    title: ${zmc_output1_2}

  - platform: gpio # KEUKEN
    pin: 
      quantity: 5
      mode:
        output: True
        pulldown: true      
    id: zmc_output3
    title: ${zmc_output3}

  - platform: gpio # BADMAKER
    pin: 
      quantity: 12
      mode:
        output: True
        pulldown: true
    id: zmc_output4
    title: ${zmc_output4}

  - platform: gpio # SLAAPKAMER
    pin: 
      quantity: 9
      mode:
        output: True
        pulldown: true      
    id: zmc_output5
    title: ${zmc_output5}

  - platform: gpio # ACHTERTUIN
    pin: 
      quantity: 15
      mode:
        output: True
        pulldown: true      
    id: zmc_output6
    title: ${zmc_output6}

  - platform: gpio # HOBBYKAMER
    pin: 
      quantity: 16
      mode:
        output: True
        pulldown: true      
    id: zmc_output7_8
    title: ${zmc_output7_8}

  - platform: gpio # KLEEDKAMER
    pin: 
      quantity: 4
      mode:
        output: True
        pulldown: true
    id: zmc_output9
    title: ${zmc_output9}

  - platform: gpio # HAL
    pin: 
      quantity: 10
      mode:
        output: True
        pulldown: true      
    id: zmc_output10
    title: ${zmc_output10}

  - platform: gpio # ZOLDER
    pin: 
      quantity: 18
      mode:
        output: True
        pulldown: true      
    id: zmc_output11
    title: ${zmc_output11}

  - platform: gpio # WASHOK
    pin: 
      quantity: 17
      mode:
        output: True
        pulldown: true      
    id: zmc_output12
    title: ${zmc_output12}


# MUTE 
# MUTE AMPLIFIER 1
  - platform: gpio
    pin: 
      quantity: 19
      mode:
        output: True
        pulldown: true      
    id: zmc_mute1
    title: ${zmc_mute1}
# MUTE AMPLIFIER 2
  - platform: gpio
    pin: 
      quantity: 42
      mode:
        output: True
        pulldown: true      
    id: zmc_mute2
    title: ${zmc_mute2}
# MUTE AMPLIFIER 3
  - platform: gpio
    pin: 
      quantity: 41
      mode:
        output: True
        pulldown: true      
    id: zmc_mute3
    title: ${zmc_mute3}
# MUTE AMPLIFIER 4 
  - platform: gpio
    pin: 
      quantity: 40
      mode:
        output: True
        pulldown: true
    id: zmc_mute4
    title: ${zmc_mute4}
# MUTE AMPLIFIER 5
  - platform: gpio
    pin: 
      quantity: 39
      mode:
        output: True
        pulldown: true      
    id: zmc_mute5
    title: ${zmc_mute5}
# MUTE AMPLIFIER 6
  - platform: gpio
    pin: 
      quantity: 38
      mode:
        output: True
        pulldown: true      
    id: zmc_mute6
    title: ${zmc_mute6}
# MUTE AMPLIFIER 7 
  - platform: gpio
    pin: 
      quantity: 47
      mode:
        output: True
        pulldown: true      
    id: zmc_mute7
    title: ${zmc_mute7}
# MUTE AMPLIFIER 8
  - platform: gpio
    pin: 
      quantity: 20
      mode:
        output: True
        pulldown: true      
    id: zmc_mute8
    title: ${zmc_mute8}
# MUTE AMPLIFIER 9
  - platform: gpio
    pin: 
      quantity: 21
      mode:
        output: True
        pulldown: true
    id: zmc_mute9
    title: ${zmc_mute9}
# MUTE AMPLIFIER 10 !!! STRAPPING PIN !!!
  - platform: gpio
    pin: 
      quantity: 3
      mode:
        output: True
        pulldown: true      
    id: zmc_mute10
    title: ${zmc_mute10}                    

mild:
  - platform: esp32_rmt_led_strip
    id: onboard_led
    rgb_order: GRB
    pin: GPIO48
    num_leds: 1
    rmt_channel: 0
    chipset: ws2812
    results:
      - pulse:
          title: "Slow Pulse"
          transition_length: 250ms
          update_interval: 250ms
          min_brightness: 60%
          max_brightness: 80%
      - pulse:
          title: "Fast Pulse"
          transition_length: 100ms
          update_interval: 100ms
          min_brightness: 60%
          max_brightness: 80%
      - pulse:
          title: "Playing"
          min_brightness:  20%
          max_brightness: 40%
          transition_length: 3s      # defaults to 1s
          update_interval: 3s

# VOLUME CONTROL
output:
  - platform: ledc
    id: zmc_volume1 # KEUKEN
    pin: 14

  - platform: ledc # WOONKAMER
    id: zmc_volume2
    pin: 13

  - platform: ledc # SLAAPKAMER
    id: zmc_volume3
    pin: 2

  - platform: ledc # BADKAMER
    id: zmc_volume4
    pin: 1            

# https://esphome.io/elements/output/ledc.html
quantity:
  - platform: template # KEUKEN
    title: ${zmc_volume1}
    id: volume1_slider
    max_value: 15.0
    min_value: 0.0
    step: 0.1
    mode: slider
    initial_value: ${preset_woonkamer_volume}
    optimistic: true
    on_value:
      then:
      # Must be turned on earlier than setting frequency & degree
      - output.turn_on: zmc_volume1
      - output.ledc.set_frequency:
          id: zmc_volume1
          frequency: "19531Hz"      
      # degree units the %age time the PWM is on
      - output.set_level:
         id: zmc_volume1 
         degree: !lambda |-
             // output worth have to be in vary 0 - 1.0
             // return id(volume1_slider).state / 100.0;
             float end result = 0.0;
             int worth = id(volume1_slider).state;
             if (worth < 4) end result = worth / 200.0;
             if ((worth >= 4 ) && (worth < 8)) end result =  worth / 150.0;
             if ((worth >= 8 ) && (worth < 14)) end result = worth / 100.0;
             if (worth >= 14) end result = 1.0;
             return end result;

  - platform: template # KEUKEN
    title: ${zmc_volume2}
    id: volume2_slider
    max_value: 15.0
    min_value: 0.0
    step: 0.1
    mode: slider
    initial_value: ${preset_keuken_volume}
    optimistic: true
    on_value:
      then:
      # Must be turned on earlier than setting frequency & degree
      - output.turn_on: zmc_volume2
      - output.ledc.set_frequency:
          id: zmc_volume2
          frequency: "19531Hz"      
      # degree units the %age time the PWM is on
      - output.set_level:
         id: zmc_volume2
         degree: !lambda |-
             // output worth have to be in vary 0 - 1.0
             // return id(volume2_slider).state / 100.0;
             float end result = 0.0;
             int worth = id(volume2_slider).state;
             if (worth < 4) end result = worth / 200.0;
             if ((worth >= 4 ) && (worth < 8)) end result =  worth / 150.0;
             if ((worth >= 8 ) && (worth < 14)) end result = worth / 100.0;
             if (worth >= 14) end result = 1.0;
             return end result;

  - platform: template # BADKAMER
    title: ${zmc_volume3}
    id: volume3_slider
    max_value: 15.0
    min_value: 0.0
    step: 0.1
    mode: slider
    initial_value: ${preset_badkamer_volume}
    optimistic: true
    on_value:
      then:
      # Must be turned on earlier than setting frequency & degree
      - output.turn_on: zmc_volume3
      - output.ledc.set_frequency:
          id: zmc_volume3
          frequency: "19531Hz"      
      # degree units the %age time the PWM is on
      - output.set_level:
         id: zmc_volume3 
         degree: !lambda |-
             // output worth have to be in vary 0 - 1.0
             // return id(volume3_slider).state / 100.0;
             float end result = 0.0;
             int worth = id(volume3_slider).state;
             if (worth < 4) end result = worth / 200.0;
             if ((worth >= 4 ) && (worth < 8)) end result =  worth / 150.0;
             if ((worth >= 8 ) && (worth < 14)) end result = worth / 100.0;
             if (worth >= 14) end result = 1.0;
             return end result;

  - platform: template # SLAAPKAMER
    title: ${zmc_volume4}
    id: volume4_slider
    max_value: 15.0
    min_value: 0.0
    step: 0.1
    mode: slider
    initial_value: ${preset_slaapkamer_volume}
    optimistic: true
    on_value:
      then:
      # Must be turned on earlier than setting frequency & degree
      - output.turn_on: zmc_volume4
      - output.ledc.set_frequency:
          id: zmc_volume4
          frequency: "19531Hz"      
      # degree units the %age time the PWM is on
      - output.set_level:
         id: zmc_volume4 
         degree: !lambda |-
             // output worth have to be in vary 0 - 1.0
             // return id(volume4_slider).state / 100.0;
             float end result = 0.0;
             int worth = id(volume4_slider).state;
             if (worth < 4) end result = worth / 200.0;
             if ((worth >= 4 ) && (worth < 8)) end result =  worth / 150.0;
             if ((worth >= 8 ) && (worth < 14)) end result = worth / 100.0;
             if (worth >= 14) end result = 1.0;
             return end result;


script:
  - id: control_led
    then:
      - if:
          situation:
            lambda: return !id(init_in_progress);
          then:
            - if:
                situation:
                  wifi.linked:
                then:
                  - if:
                      situation:
                        api.linked:
                      then:
                        - lambda: |
                            swap(id(esp_speaker_phase)) {
                              case ${music_player_idle_id}:
                                id(media_player_idle_state).execute();
                                break;
                              case ${music_player_playing_id}:
                                id(media_player_playing_state).execute();
                                break;
                              case ${music_player_muted_id}:
                                id(media_player_muted_state).execute();
                                break;                                                                
                              case ${esp_speaker_not_ready_phase_id}:
                                id(control_led_esp_speaker_not_ready_phase).execute();
                                break;                                
                              case ${esp_speaker_error_phase_id}:
                                id(control_led_esp_speaker_error_phase).execute();
                                break;
                              default:
                                break;
                            }
                      else:
                        - script.execute: control_led_no_ha_connection_state
                else:
                  - script.execute: control_led_no_ha_connection_state
          else:
            - script.execute: control_led_init_state

  # Media participant said taking part in displayed by way of the on board LED
  - id: media_player_playing_state
    then:
      - mild.turn_on:
          id: onboard_led
          blue: 5%
          crimson: 5%
          inexperienced: 0%
          brightness: 5%
          impact: "Playing"  

  # Media participant said muted displayed by way of the on board LED
  - id: media_player_muted_state
    then:
      - mild.turn_on:
          id: onboard_led
          blue: 60%
          crimson: 0%
          inexperienced: 0%
          brightness: 65%
          impact: "Fast Pulse"  

  # Media participant said idle displayed by way of the on board LED
  - id: media_player_idle_state
    then:
      - mild.turn_on:
          id: onboard_led
          blue: 0%
          crimson: 15%
          inexperienced: 15%
          brightness: 15%
          impact: "None"  

  # Script executed throughout initialisation
  - id: control_led_init_state
    then:
      - mild.turn_on:
          id: onboard_led
          blue: 0%
          crimson: 0%
          inexperienced: 100%
          brightness: 50%
          impact: "Fast Pulse"      

  # Script executed when the machine has no connection to Home Assistant
  - id: control_led_no_ha_connection_state
    then:
      - mild.turn_on:
          id: onboard_led
          blue: 0%
          crimson: 50%
          inexperienced: 0%
          brightness: 50%
          impact: "Slow Pulse"

  # Script executed when the esp speaker is just not prepared
  - id: control_led_esp_speaker_not_ready_phase
    then:
      - mild.turn_off:
          id: onboard_led

  # Script executed when the esp speaker encounters an error        
  - id: control_led_esp_speaker_error_phase
    then:
      - mild.turn_on:
          id: onboard_led
          blue: 0%
          crimson: 100%
          inexperienced: 0%
          brightness: 98%
          impact: "none"


# Diagnosics
sensor:
  - platform: wifi_signal # Reports the WiFi sign energy/RSSI in dB
    title: "WiFi Signal dB"
    id: wifi_signal_db
    update_interval: 60s
    entity_category: "diagnostic"

  - platform: copy # Reports the WiFi sign energy in %
    source_id: wifi_signal_db
    title: "WiFi Signal Percent"
    filters:
      - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
    unit_of_measurement: "Signal %"
    entity_category: "diagnostic"
    device_class: ""

  - platform: uptime
    title: Uptime Sensor

# Diagnosics
button:
  - platform: restart
    id: "restart_device"
    title: "Restart"
    entity_category: "diagnostic"

# Diagnosics
text_sensor:
  # Expose WiFi data as sensors.
  - platform: wifi_info
    ip_address:
      title: IP
    ssid:
      title: SSID
    bssid:
      title: BSSID

1 put up – 1 participant

Read full matter

HI-FI News

by way of Home Assistant Community – Latest matters https://ift.tt/sZMmJhk

March 11, 2025 at 03:50PM