Hi, I’m using Moode Audio MPD player running on an old Rpi2. It’s somewhat integrated with HA through the built-in MPD integration but whenever it restarts, HA can no longer talk to it until HA is restarted too:
Failed to call service media_player/play_media. Can not
send command to disconnected client
Is there any other way to reconnect HA to MPD so it doesn’t completely break after any MPD restart or a network glitch?
2 Likes
blissarts
(Blissart)
March 28, 2023, 7:55am
3
I have the same Problem. Dors anybody know of a solution (reload integration, initiate reconnect etc.)?
Only solution I can see is restarting home assistant but thats not really a good solution.
RemyyB
(Remy B)
June 4, 2023, 12:48pm
4
I currently have the same problem. MPD is really unstable for me, any MPD client worsk perfectly fine, only home assistant randomly disconnects. How can I fix this? Only restarts helps…
Have you ever been able to identify or fix this issue?
lupa18
(Lu)
June 12, 2023, 3:46pm
5
Same here.
MPD version: 0.22.6
HAAS version: 2023.5.4
lupa18
(Lu)
June 28, 2023, 3:20pm
6
The only solution I have found is to restart home-assistant. It’s really strange and not so good for stability and robustness.
Same here. This is really annoying. The only solution is to restart HA.
Any idea where I’d submit this as a bug? I’m trying to phase out an unstable chromecast audio for MPD on an old RPI but this is killing it!
kuenkin
(Kuenkin)
August 21, 2023, 11:20pm
9
Hello,
I think they should be submited to home-assistant/core :
I also have this problem in my parent’s house where I try to use a mpd player for TTS notifications.
This will be fixed when the following PR is added to Home Assistant.
home-assistant:dev
← thijsputman:mpd-non-persistent-connection
opened 11:20PM - 12 Jun 23 UTC
<!--
You are amazing! Thanks for contributing to our project!
Please, DO N… OT DELETE ANY TEXT from this template! (unless instructed).
-->
## Proposed change
<!--
Describe the big picture of your changes here to communicate to the
maintainers why we should accept this pull request. If it fixes a bug
or resolves a feature request, be sure to link to that issue in the
additional information section.
-->
Instead of relying on the (persistent) connection handling of [`python-mpd2`](https://github.com/Mic92/python-mpd2) (which is not working optimally – see for example https://github.com/Mic92/python-mpd2/issues/31), explicitly connect and disconnect for every command send to MPD.
This resolves https://github.com/home-assistant/core/issues/57633#issuecomment-1483837477 (and probably some related issues) where the MPD integration would get stuck in "limbo": Disconnected _and_ unable to reconnect at the same time. Outside of a full restart of Home Assistant there was no way of recovering from this.
With the three MPD players in my network, this issue would occur once per week; a slight hiccup in the Wi-Fi was often already enough to require a full restart of HA.
This change introduces a bit of overhead, but as the integration is local-polling (ie, nothing actually gets pushed back to us over the persistent connection) I'd say the impact is minimal. The MPD protocol doesn't really appear to be geared towards persistent connections any way.
The best solution would probably be a fix in `python-mpd2` itself, but I'm afraid that's a bit out of scope for me at the moment.
I've tried to keep changes to a minimum (didn't totally succeed 😇) and use an elegant/modern Python approach. I'm not very familiar with Python, so there might be some oddities here and there...
I've been running this code locally for about two months (with three MPD players on the network) and it's been rock solid: Disconnects happen from time to time, the integration always recovers and never gets stuck in "limbo".
In case anyone is wondering: I did initially try to simply brute-force some additional connection attempts into the integration – that didn't work at all: Once `python-mpd2` looses the connection, there doesn't appear to an (obvious) way to get it to reconnect again.
## Type of change
<!--
What type of change does your PR introduce to Home Assistant?
NOTE: Please, check only 1! box!
If your PR requires multiple boxes to be checked, you'll most likely need to
split it into multiple PRs. This makes things easier and faster to code review.
-->
- [ ] Dependency upgrade
- [x] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [ ] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests
## Additional information
<!--
Details are important, and help maintainers processing your PR.
Please be sure to fill out additional details, if applicable.
-->
- This PR fixes or closes issue: https://github.com/home-assistant/core/issues/57633#issuecomment-1483837477
- This PR is related to issue:
- Link to documentation pull request:
## Checklist
<!--
Put an `x` in the boxes that apply. You can also fill these out after
creating the PR. If you're unsure about any of them, don't hesitate to ask.
We're here to help! This is simply a reminder of what we are going to look
for before merging your code.
-->
- [ ] The code change is tested and works locally.
- [ ] Local tests pass. **Your PR cannot be merged unless tests pass**
- [ ] There is no commented out code in this PR.
- [ ] I have followed the [development checklist][dev-checklist]
- [ ] I have followed the [perfect PR recommendations][perfect-pr]
- [ ] The code has been formatted using Black (`black --fast homeassistant tests`)
- [ ] Tests have been added to verify that the new code works.
If user exposed functionality or configuration variables are added/changed:
- [ ] Documentation added/updated for [www.home-assistant.io][docs-repository]
If the code communicates with devices, web services, or third-party tools:
- [ ] The [manifest file][manifest-docs] has all fields filled out correctly.
Updated and included derived files by running: `python3 -m script.hassfest`.
- [ ] New or updated dependencies have been added to `requirements_all.txt`.
Updated by running `python3 -m script.gen_requirements_all`.
- [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
- [ ] Untested files have been added to `.coveragerc`.
<!--
This project is very active and we have a high turnover of pull requests.
Unfortunately, the number of incoming pull requests is higher than what our
reviewers can review and merge so there is a long backlog of pull requests
waiting for review. You can help here!
By reviewing another pull request, you will help raise the code quality of
that pull request and the final review will be faster. This way the general
pace of pull request reviews will go up and your wait time will go down.
When picking a pull request to review, try to choose one that hasn't yet
been reviewed.
Thanks for helping out!
-->
To help with the load of incoming pull requests:
- [ ] I have reviewed two other [open pull requests][prs] in this repository.
[prs]: https://github.com/home-assistant/core/pulls?q=is%3Aopen+is%3Apr+-author%3A%40me+-draft%3Atrue+-label%3Awaiting-for-upstream+sort%3Acreated-desc+review%3Anone+-status%3Afailure
<!--
Thank you for contributing <3
Below, some useful links you could explore:
-->
[dev-checklist]: https://developers.home-assistant.io/docs/development_checklist/
[manifest-docs]: https://developers.home-assistant.io/docs/creating_integration_manifest/
[quality-scale]: https://developers.home-assistant.io/docs/integration_quality_scale_index/
[docs-repository]: https://github.com/home-assistant/home-assistant.io
[perfect-pr]: https://developers.home-assistant.io/docs/review-process/#creating-the-perfect-pr
1 Like
SonarClouds
(Sonar Clouds)
October 15, 2023, 10:48am
11
Is the PR still active? Looked like there wasn’t much work left and it would be shame not to see the fix being merged soon as I really would like to use the mpd again
Dyson
October 21, 2023, 9:13pm
12
Looks like all the work is done for the PR. Just the one change in August which was resolved was never marked resolved, so it’s stuck in limbo until that happens.
1 Like
shadowdog
(Rich)
December 19, 2023, 3:14pm
14
This issue affects me too. I am using the updated version from the pull request by patching the Homeassistant docker image. I put the below in my dockerfile and rebuild it:
COPY ./mpd-patch/patched.py ./usr/src/homeassistant/homeassistant/components/mpd/media_player.py
I was also having trouble with the MPD integration not getting status updates from the media player so the state in HA was inaccurate when I used any other app to control MPD. This fixed that too.
2 Likes
trash.heap
(Jimbo Jones)
February 12, 2024, 6:50am
15
Does anyone have an update on this? I have stability issues with MPD and needing to restart HA is a pretty major pain. At last with an integration I could just restart that. its not clear from this thread if people feel like its fixed.
actran70
(AndyT)
February 12, 2024, 6:23pm
16
I can use this fix as well.
trash.heap
(Jimbo Jones)
June 16, 2024, 12:58am
17
Is this progressing anywhere? MPD is basically unusable for me. It works for a while (maybe) then will just stop. The worst element of this is that there is no method to kick it back into life other than a complete restart of HA. Which is really beyond frustrating.