Remote cmus integration stops working when cmus is stopped/restarted

I am using a remote cmus instance and it works when:

  1. cmus is running on the remote server cmus --listen
  2. Then I start Home Assistant Core

My config is as follows:

  - platform: cmus
    name: cmus
    port: 3000
    password: SomePassword

I can play, pause and change tracks… even volume changing works as far as muting the sound (another issue is that it won’t set the volume at all).

Problem #1 - Starting cmus after Home Assistant

But when I start the applications in the wrong order it doesn’t work e.g.:

  1. Start Home Assistant Core
  2. Start cmus

In this case, the media player remains disconnected and the logs show an error:

Log Details (ERROR)
Logger: homeassistant.components.media_player
Source: components/cmus/
Integration: Media player (documentation, issues)
First occurred: 8:11:12 PM (1 occurrences)
Last logged: 8:11:12 PM

Error while setting up cmus platform for media_player
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/", line 184, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.8/concurrent/futures/", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/cmus/", line 68, in setup_platform
    cmus_remote = CmusDevice(host, password, port, name)
  File "/usr/src/homeassistant/homeassistant/components/cmus/", line 83, in __init__
    self.cmus = remote.PyCmus(server=server, password=password, port=port)
  File "/usr/local/lib/python3.8/site-packages/pycmus/", line 78, in __init__
    raise exceptions.ConfigurationError(
pycmus.exceptions.ConfigurationError: A configuration error occured
Details: Unable to connect to server

No matter how long I wait, Home Assistant Core never reconnects the integration.

Problem #2 - Restarting cmus whilst connected to Home Assistant

When I restart cmus after it is successfully connected to Home Assistant, any future actions, like playing or pausing triggers a series of errors:

Log Details (WARNING)
Logger: homeassistant.components.cmus.media_player
Source: components/cmus/
Integration: cmus (documentation, issues)
First occurred: 8:47:16 PM (1 occurrences)
Last logged: 8:47:16 PM

Received no status from cmus


Log Details (ERROR)
Logger: homeassistant.components.websocket_api.http.connection.140450245543248
Source: components/cmus/
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 8:47:21 PM (1 occurrences)
Last logged: 8:47:21 PM

[Errno 32] Broken pipe
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/", line 125, in handle_call_service
  File "/usr/src/homeassistant/homeassistant/", line 1308, in async_call
  File "/usr/src/homeassistant/homeassistant/", line 1343, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/", line 208, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/", line 454, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/", line 583, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/", line 485, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/media_player/", line 523, in async_turn_on
    await self.hass.async_add_job(self.turn_on)
  File "/usr/local/lib/python3.8/concurrent/futures/", line 57, in run
    result = self.fn(*self.args, **self.kwargs)

And finally:

Log Details (ERROR)
Logger: homeassistant.helpers.entity
Source: components/cmus/
First occurred: 8:47:26 PM (1 occurrences)
Last logged: 8:47:26 PM

Update for media_player.cmus fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/", line 263, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/", line 456, in async_device_update
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.8/concurrent/futures/", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/cmus/", line 93, in update
    status = self.cmus.get_status_dict()
  File "/usr/local/lib/python3.8/site-packages/pycmus/", line 225, in get_status_dict
    status_str = self.status()
  File "/usr/local/lib/python3.8/site-packages/pycmus/", line 216, in status
    return self.send_cmd('status\n')
  File "/usr/local/lib/python3.8/site-packages/pycmus/", line 123, in send_cmd
BrokenPipeError: [Errno 32] Broken pipe

Anyone else experiencing more issues around this?

I have the same problem Except that if cmus is already running, I get control. Otherwise, I get some “broken pipe” error. All I want to do is have cmus start automatically, play a single mp3 repeatedly and be able to pause it in HA. I’ve spent hours trying to get there but, not being a Linux Guru, have come up empty-handed. Popular assistance includes (repeatedly) “Google is your friend”. Well actually, no it’s not.

1 Like

100%… searching cmus related issues returns a barren wasteland.

Are you running cmus remotely or locally? Anything interesting showing up in your logs other than what I’m seeing above?

CMUS and HA are both on the same RPi. I have since moved on to VLC - it has more documentation so I’ll at least have a fighting chance.

Edit: Finally got it working, but indeed HA has to be started after every cmus start or it won’t work (anymore).

Appreciate the report @Saturnus.

Not a Python dev, but I’ve just written a PR to keep cmus connected across restarts. You guys may like to follow the issue here:

Looks like there’s so much more that could be done to improve this integration!

Great effort. :ok_hand: Following it.

Agree for improvement. Even the documentation needs an update. Could have missed it but after searching for a while went for trial and error to found that:

To play a file by filename use service media_player.play_media

entity_id: media_player.cmus
media_content_id: '/media/file.wav'
media_content_type: music

I think changing volume from within HA is bugged too? In HA a value between 0 and 1 is used, which is then not translated to cmus range of 0-100.

It is, unless we use softvol in cmus. I need to learn more about the remote to make it work with standard volume / mixer (if at all possible).

Just an update, the fix was merged into HA Core and is in the latest release. Took a while due to my noob Python skills.

Maybe worth finding and fixing other cmus “bugs” too. E.g. Softvol and potentially media browser would be amazing I reckon.