I2S Media Player stops working

Hi all. I need help with my ESPHome I²S Media Player with external DAC MAX98357A, wich I use with 4 relays as a actuator for my alarm system (Home Assistant with Alarmo). Its working as expected and plays notifications about the alarm system on a speaker in the stairway of my house.
But sometimes the media player stops working. It looks like, that the media player keeps at the state “paused” and no way to play anything after this.
Here is the log:

INFO ESPHome 2023.7.1
INFO Reading configuration /config/esphome/alarm-actuator.yaml...
INFO Starting log output from alarm-actuator.local using esphome API
INFO Successfully connected to alarm-actuator.local
[13:03:28][I][app:102]: ESPHome version 2023.7.1 compiled on Aug 12 2023, 12:57:50
[13:03:28][C][status_led:019]: Status LED:
[13:03:28][C][status_led:020]:   Pin: GPIO23
[13:03:28][C][wifi:543]: WiFi:
[13:03:28][C][wifi:379]:   Local MAC: 3C:71:BF:64:44:10
[13:03:28][C][wifi:380]:   SSID: [redacted]
[13:03:28][C][wifi:381]:   IP Address: 192.168.178.167
[13:03:28][C][wifi:383]:   BSSID: [redacted]
[13:03:28][C][wifi:384]:   Hostname: 'alarm-actuator'
[13:03:28][C][wifi:386]:   Signal strength: -79 dB ▂▄▆█
[13:03:28][C][wifi:390]:   Channel: 10
[13:03:28][C][wifi:391]:   Subnet: 255.255.255.0
[13:03:28][C][wifi:392]:   Gateway: 192.168.178.1
[13:03:28][C][wifi:393]:   DNS1: 192.168.178.1
[13:03:28][C][wifi:394]:   DNS2: 0.0.0.0
[13:03:28][C][logger:301]: Logger:
[13:03:28][C][logger:302]:   Level: DEBUG
[13:03:28][C][logger:303]:   Log Baud Rate: 115200
[13:03:28][C][logger:305]:   Hardware UART: UART0
[13:03:28][C][gpio.output:010]: GPIO Binary Output:
[13:03:28][C][gpio.output:011]:   Pin: GPIO32
[13:03:28][C][gpio.output:010]: GPIO Binary Output:
[13:03:28][C][gpio.output:011]:   Pin: GPIO33
[13:03:28][C][gpio.output:010]: GPIO Binary Output:
[13:03:28][C][gpio.output:011]:   Pin: GPIO25
[13:03:28][C][gpio.output:010]: GPIO Binary Output:
[13:03:28][C][gpio.output:011]:   Pin: GPIO26
[13:03:28][C][output.switch:068]: Output Switch 'Innensirene'
[13:03:28][C][output.switch:091]:   Restore Mode: always OFF
[13:03:28][C][output.switch:068]: Output Switch 'Außensirene'
[13:03:28][C][output.switch:091]:   Restore Mode: always OFF
[13:03:28][C][output.switch:068]: Output Switch 'Blitz'
[13:03:28][C][output.switch:091]:   Restore Mode: always OFF
[13:03:28][C][output.switch:068]: Output Switch 'Relay 4'
[13:03:28][C][output.switch:091]:   Restore Mode: always OFF
[13:03:28][C][captive_portal:088]: Captive Portal:
[13:03:28][C][mdns:112]: mDNS:
[13:03:28][C][mdns:113]:   Hostname: alarm-actuator
[13:03:28][C][ota:093]: Over-The-Air Updates:
[13:03:28][C][ota:094]:   Address: alarm-actuator.local:3232
[13:03:28][C][ota:097]:   Using Password.
[13:03:28][C][api:138]: API Server:
[13:03:28][C][api:139]:   Address: alarm-actuator.local:6053
[13:03:28][C][api:141]:   Using noise encryption: YES
[13:03:28][C][audio:203]: Audio:
[13:03:28][C][audio:225]:   External DAC channels: 1
[13:03:28][C][audio:226]:   I2S DOUT Pin: 14
[13:03:36][D][media_player:059]: 'I2S Media Player' - Setting
[13:03:36][D][media_player:066]:   Media URL: http://192.168.178.132:8123/api/tts_proxy/7d7ca7d39753a164cef858a8f35bd3a3f1c6c4d9_de-de_19e78850b6_google_cloud.mp3
[13:03:37][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.54 s).
[13:03:37][W][component:205]: Components should block for at most 20-30ms.
[13:03:39][I][ota:113]: Boot seems successful, resetting boot loop counter.
[13:03:39][D][esp32.preferences:114]: Saving 1 preferences to flash...
[13:03:39][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[13:03:43][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.34 s).
[13:03:43][W][component:205]: Components should block for at most 20-30ms.
[13:03:43][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.34 s).
[13:03:43][W][component:205]: Components should block for at most 20-30ms.
[13:04:12][D][media_player:059]: 'I2S Media Player' - Setting
[13:04:12][D][media_player:066]:   Media URL: http://192.168.178.132:8123/api/tts_proxy/7d7ca7d39753a164cef858a8f35bd3a3f1c6c4d9_de-de_19e78850b6_google_cloud.mp3
[13:04:12][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.54 s).
[13:04:12][W][component:205]: Components should block for at most 20-30ms.
[13:04:19][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.34 s).
[13:04:19][W][component:205]: Components should block for at most 20-30ms.
[13:04:19][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.33 s).
[13:04:19][W][component:205]: Components should block for at most 20-30ms.
[13:04:51][D][media_player:059]: 'I2S Media Player' - Setting
[13:04:51][D][media_player:066]:   Media URL: http://192.168.178.132:8123/media/local/signal.mp3?authSig=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIzNzc5N2IyYmQxMDM0MmMzOThhMmRkMmI3ZDc1YWM1NCIsInBhdGgiOiIvbWVkaWEvbG9jYWwvc2lnbmFsLm1wMyIsInBhcmFtcyI6W10sImlhdCI6MTY5MTgzODI5MSwiZXhwIjoxNjkxOTI0NjkxfQ.ELEsyOOgCiRVhyIbqsxWq8Qlh6XDJkI7oV9apX-pcn0
[13:04:51][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.54 s).
[13:04:51][W][component:205]: Components should block for at most 20-30ms.
[13:04:54][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.17 s).
[13:04:54][W][component:205]: Components should block for at most 20-30ms.
[13:04:54][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.17 s).
[13:04:54][W][component:205]: Components should block for at most 20-30ms.
[13:05:23][D][media_player:059]: 'I2S Media Player' - Setting
[13:05:23][D][media_player:066]:   Media URL: http://192.168.178.132:8123/api/tts_proxy/7d7ca7d39753a164cef858a8f35bd3a3f1c6c4d9_de-de_19e78850b6_google_cloud.mp3
[13:05:24][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.54 s).
[13:05:24][W][component:205]: Components should block for at most 20-30ms.
[13:05:30][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.34 s).
[13:05:30][W][component:205]: Components should block for at most 20-30ms.
[13:05:30][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.34 s).
[13:05:30][W][component:205]: Components should block for at most 20-30ms.
[13:06:51][D][media_player:059]: 'I2S Media Player' - Setting
[13:06:51][D][media_player:066]:   Media URL: http://st01.dlf.de/dlf/01/128/mp3/stream.mp3
[13:06:52][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.72 s).
[13:06:52][W][component:205]: Components should block for at most 20-30ms.
[13:06:52][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.33 s).
[13:06:52][W][component:205]: Components should block for at most 20-30ms.
[13:07:12][D][media_player:059]: 'I2S Media Player' - Setting
[13:07:12][D][media_player:066]:   Media URL: http://192.168.178.132:8123/api/tts_proxy/7d7ca7d39753a164cef858a8f35bd3a3f1c6c4d9_de-de_19e78850b6_google_cloud.mp3
[13:07:12][W][component:204]: Component api took a long time for an operation (0.19 s).
[13:07:12][W][component:205]: Components should block for at most 20-30ms.
[13:07:18][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.34 s).
[13:07:18][W][component:205]: Components should block for at most 20-30ms.
[13:07:19][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.34 s).
[13:07:19][W][component:205]: Components should block for at most 20-30ms.
[13:08:01][D][media_player:059]: 'I2S Media Player' - Setting
[13:08:01][D][media_player:066]:   Media URL: http://st01.dlf.de/dlf/01/128/mp3/stream.mp3
[13:08:01][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.63 s).
[13:08:01][W][component:205]: Components should block for at most 20-30ms.
[13:08:02][W][component:204]: Component i2s_audio.media_player took a long time for an operation (0.43 s).
[13:08:02][W][component:205]: Components should block for at most 20-30ms.
[13:08:12][D][media_player:059]: 'I2S Media Player' - Setting
[13:08:12][D][media_player:063]:   Command: PAUSE
[13:08:37][D][media_player:059]: 'I2S Media Player' - Setting
[13:08:37][D][media_player:066]:   Media URL: http://192.168.178.132:8123/api/tts_proxy/7d7ca7d39753a164cef858a8f35bd3a3f1c6c4d9_de-de_19e78850b6_google_cloud.mp3
[13:08:46][D][media_player:059]: 'I2S Media Player' - Setting
[13:08:46][D][media_player:066]:   Media URL: http://192.168.178.132:8123/api/tts_proxy/7d7ca7d39753a164cef858a8f35bd3a3f1c6c4d9_de-de_19e78850b6_google_cloud.mp3
[13:09:33][D][media_player:059]: 'I2S Media Player' - Setting
[13:09:33][D][media_player:063]:   Command: PLAY
[13:09:40][D][media_player:059]: 'I2S Media Player' - Setting
[13:09:40][D][media_player:063]:   Command: PLAY
[13:09:59][D][media_player:059]: 'I2S Media Player' - Setting
[13:09:59][D][media_player:063]:   Command: PLAY

At this example, after the “Command: PAUSE” the player stopped working.

This is my configuration:

esphome:
  name: "alarm-actuator"
  friendly_name: "alarm-actuator"

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: ""

ota:
  password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Alarm-Actor Fallback Hotspot"
    password: "TusHsx9lIF7B"

captive_portal:

output:
  - platform: gpio
    pin: GPIO32
    id: relay_pin_1
  - platform: gpio
    pin: GPIO33
    id: relay_pin_2
  - platform: gpio
    pin: GPIO25
    id: relay_pin_3
  - platform: gpio
    pin: GPIO26
    id: relay_pin_4

# Define the switches based on the relay pins
switch:
  - platform: output
    id: innensirene
    name: "Innensirene"
    output: relay_pin_1
  - platform: output
    id: aussensirene
    name: "Außensirene"
    output: relay_pin_2
  - platform: output
    id: blitz
    name: "Blitz"
    output: relay_pin_3
  - platform: output
    id: relay_4
    name: "Relay 4"
    output: relay_pin_4


# Use the red LED in the device as a status LED, which will blink if there are warnings (slow) or errors (fast)
status_led:
  pin:
    number: GPIO23
    inverted: False

# Example configuration entry
i2s_audio:
  i2s_lrclk_pin: GPIO27
  i2s_bclk_pin: GPIO13

# Example configuration entry
media_player:
  - platform: i2s_audio
    name: I2S Media Player
    dac_type: external
    i2s_dout_pin: GPIO14
    mode: mono
    
button:
  - platform: template
    name: Alarmsound
    id: my_button

    # Optional variables:
    icon: "mdi:emoticon-outline"
    on_press:
      - logger.log: "Button pressed"
      - media_player.play_media: "http://192.168.178.132:8123/media/local/signal.mp3?authSig=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI0YTViMmI1MWQ3Y2M0MzczODc3ODE2M2IyMWRlZDJhNSIsInBhdGgiOiIvbWVkaWEvbG9jYWwvc2lnbmFsLm1wMyIsInBhcmFtcyI6e30sImlhdCI6MTY2OTMxNTkwNCwiZXhwIjoxNjY5NDAyMzA0fQ.K3OeKR79qXiAKU0YAClim0-26vrOaGY8zKY-4qAz8_c"

Hello,

I have the same Problem. As long as the Status of the Player is idle or playing IT is working. After changing to pause IT will completly Stop playing Media (tts, mp3 or Radio stream).

At the Moment I have a Script that restarts the Player, when IT detects the Status Pause. But this is not really a good sollution.

I also have Problems controlling the Volumen of the Player. Only while it is playing, i can change the Volume via a Script. In Status “idle” it is not changing the Volumen at all via a Script.

Hi Nagel,

I made nearly the same and up to now since one week, it works perfectly! I added an on_pause action in my esphome script:


    on_pause:
      - media_player.stop
      

Volume problems have I not seen.

May I ask where did you put that in your yaml files? I am having the same issue :frowning:

Hi Kelvin,

media_player:
  - platform: i2s_audio
    name: I2S Media Player
    dac_type: external
    i2s_dout_pin: GPIO14
    mode: mono

    on_pause:
      - media_player.stop
      

Its in the ESPHome yaml-file.

1 Like

Hi Skysurfer,

I tried it directly in the esp yaml and IT works fantastic. Now I can youse the alarm System again without my automation and a lot of restarts of the Media Player. This is absolutly the better solution.

Thank you very much.

Since Update to ESPHome 2023.12.9 the issue is getting worse. After a few hours of working no more sound playing is working!

I tested my device for a couple of days now. I found no problem.
Even changing media while it is playing is working without any problem.
When is your device going offline? Maybe i can recreate the problem?

It’s crazy, since my last post 9 days ago my I2S Media Player works without any problems!
I noticed that the logs are the same for Media Player with or without function. Maybe it’s just a problem with the I2S audio chip MAX98357A. However, the I2C lines are very short, approx. 2 cm.
I will continue to monitor it.

I think it is a problem of the ESPHome firmware. I have tried the same ESP32-WROVER board with squeezelite-ESP32 and works really well. The only think I am missing is a output pin to be controlled by a homeasssitant switch (I need to activate a relay from the WROVER board).

I found the answer to my question. Going to NVS editor (enable the tab if it is not visible) and define set_GPIO as “33=amp”, when the music is playing the pin 33 turns on. This activates a relay that turns on the speaker.