Changing the buffer completely fixed the cutting issue.
There is no problem with changing the buffer length if you know what you want to achieve; it will chunk the media more often if needed.
However, the overall snapcast and TTS issue persists, and it’s now not related to a buffer, but to the stream itself, and only for TTS.
Music and all notification sounds are fine.
Error: Unable to create stream - No free port found?
UPD: Crappy workaround I’m trying now - somehow catch the error in the script and restart the failed Snapcast client (or server) and retry TTS after. Yet I don’t know how to catch this error in Script execution.
# shell_command: https://www.home-assistant.io/integrations/shell_command
shell_command:
# Reboot
reboot: "ssh -o UserKnownHostsFile=/config/.ssh/known_hosts -i /config/.ssh/id_rsa [email protected] 'sudo reboot now'"
# Restart snapcast
service_restart_snapcast_server: "ssh -o UserKnownHostsFile=/config/.ssh/known_hosts -i /config/.ssh/id_rsa [email protected] 'sudo systemctl restart snapserver'"
service_restart_snapcast_clients: "ssh -o UserKnownHostsFile=/config/.ssh/known_hosts -i /config/.ssh/id_rsa [email protected] 'sudo systemctl restart snapclient snapclient_2 snapclient_3'"
service_restart_snapcast_client_1: "ssh -o UserKnownHostsFile=/config/.ssh/known_hosts -i /config/.ssh/id_rsa [email protected] 'sudo systemctl restart snapclient'"
service_restart_snapcast_client_2: "ssh -o UserKnownHostsFile=/config/.ssh/known_hosts -i /config/.ssh/id_rsa [email protected] 'sudo systemctl restart snapclient_2'"
service_restart_snapcast_client_3: "ssh -o UserKnownHostsFile=/config/.ssh/known_hosts -i /config/.ssh/id_rsa [email protected] 'sudo systemctl restart snapclient_3'"
UPD: No luck! I’ve solved the cutting issue, but cannot catch, reproduce and solve the issue with players in automation. It just randomly happens.
Error: Unable to create stream - No free port found?
logs
2025-10-13 22:16:26.205 WARNING (MainThread) [music_assistant.snapcast] {'code': None, 'message': 'Server not connected'}
2025-10-13 22:16:26.205 ERROR (MainThread) [music_assistant.webserver] Error handling message: players/cmd/play_announcement: Unable to create stream - No free port found?
2025-10-13 22:16:31.215 INFO (MainThread) [music_assistant.snapcast] Stopping, built-in Snapserver
To recreate: Failed to perform the action tts.speak. Unable to create stream - No free port found?
Run multiple times:
action: tts.speak
data:
cache: true
media_player_entity_id: media_player.raspberrypi_5
message: MESSAGE
language: LANG
target:
entity_id: tts.piper
- media_player.raspberrypi_5 is muscis assistant audio device based on RPI5 snapcast server with USB sound card.
UPD: Unwilling to deep dive into the code to find the root cause of this constantly recurring issue, I ended up with automation to restart HA Music and all related modules hourly at idle or unavailability.
Summary
alias: Snapcast clients restart
description: Service routine - restart Snapcast when idle or unavailable
triggers:
- trigger: state
entity_id:
- media_player.bedroom
to: idle
for:
hours: 1
minutes: 0
seconds: 0
id: bedroom_idle
- trigger: state
entity_id:
- media_player.kitchen
to: idle
for:
hours: 1
minutes: 0
seconds: 0
id: kitchen_idle
- trigger: state
entity_id:
- media_player.bathroom
to: idle
for:
hours: 1
minutes: 0
seconds: 0
id: bathroom_idle
- trigger: state
entity_id:
- media_player.bedroom
to: unknown
id: bedroom_unknown
for:
hours: 0
minutes: 5
seconds: 0
- trigger: state
entity_id:
- media_player.kitchen
to: unknown
id: kitchen_unknown
for:
hours: 0
minutes: 5
seconds: 0
- trigger: state
entity_id:
- media_player.bathroom
to: unknown
id: bathroom_unknown
for:
hours: 0
minutes: 5
seconds: 0
- trigger: state
entity_id:
- media_player.bedroom
to: unavailable
id: bedroom_unavailable
for:
hours: 0
minutes: 5
seconds: 0
- trigger: state
entity_id:
- media_player.kitchen
to: unavailable
id: kitchen_unavailable
for:
hours: 0
minutes: 5
seconds: 0
- trigger: state
entity_id:
- media_player.bathroom
to: unavailable
id: bathroom_unavailable
for:
hours: 0
minutes: 5
seconds: 0
- trigger: template
value_template: >-
{{
states('media_player.bathroom') == 'idle' or
states('media_player.bathroom') == 'off'
and
states('media_player.bedroom') == 'idle' or
states('media_player.bedroom') == 'off'
and
states('media_player.kitchen') == 'idle' or
states('media_player.kitchen') == 'off'
}}
for:
hours: 1
minutes: 0
seconds: 0
id: all_music_assistant_idle
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id:
- bedroom_idle
- bedroom_unknown
- bedroom_unavailable
sequence:
- action: shell_command.service_restart_snapcast_client_2
metadata: {}
data: {}
- action: homeassistant.reload_config_entry
target:
device_id:
- dfed91884a924a58a427a508cc06a8ed
data: {}
- conditions:
- condition: trigger
id:
- kitchen_idle
- kitchen_unknown
- kitchen_unavailable
sequence:
- action: shell_command.service_restart_snapcast_client_3
metadata: {}
data: {}
- action: homeassistant.reload_config_entry
target:
device_id:
- b3edda5e47dc9d0be44755d8ad67439b
data: {}
- conditions:
- condition: trigger
id:
- bathroom_idle
- bathroom_unknown
- bathroom_unavailable
sequence:
- action: shell_command.service_restart_snapcast_clients
metadata: {}
data: {}
- action: homeassistant.reload_config_entry
target:
device_id:
- 35fe0ea1be42e3be79649813d25517c2
data: {}
- conditions:
- condition: trigger
id:
- all_music_assistant_idle
sequence:
- sequence:
- action: shell_command.service_restart_snapcast_server
metadata: {}
data: {}
- action: shell_command.service_restart_snapcast_clients
metadata: {}
data: {}
- action: shell_command.service_restart_snapcast_client_2
metadata: {}
data: {}
- action: shell_command.service_restart_snapcast_client_3
metadata: {}
data: {}
- action: hassio.addon_restart
metadata: {}
data:
addon: d5369777_music_assistant
- action: hassio.addon_restart
metadata: {}
data:
addon: core_piper
- action: homeassistant.reload_config_entry
target:
device_id:
- b3edda5e47dc9d0be44755d8ad67439b
- dfed91884a924a58a427a508cc06a8ed
- 35fe0ea1be42e3be79649813d25517c2
data: {}
- action: persistent_notification.create
metadata: {}
data:
title: Snapcast {{ trigger.id }}
message: Restarting MA, Piper addons
enabled: false
mode: queued
max: 10
And a script which will use a while loop (10 cycles limit) to force restart all modules when notification and TTS play cannot play or scripts for TTS or Notification are stuck or ended with an error.