HomePod Connect: Spotify on HomePods with Spotify Connect

Yeah, a real pity. For that reason I’m still on HA OS 9.5 and still can’t start migrate to my Odroid M1 (needs HA OS 10).

I’m hoping Music Assistant will soon be mature enough and then I’ll migrate away from Owntone.

Good point. Just tried out the Music Assistant beta and it looks already really good regarding AirPlay support.

They miss unfortunately a few features such as Spotify Connect support and AirPlay delay syncing.

I am actually really looking forward to seeing Music Assistant succeed. It provides a really good user experience in comparison to OwnTone.

New issue that popped up with 2023.9.x

Home Assistant seems to now only accept “_” as a valid separator in add-on slugs. Thus, the hassio.addon_restart service fails with error “invalid slug” when trying to restart this add-on, “63120367_homepod-connect”, due to the dash.

Thank you @maiorania!

I just renamed my addon accordingly. I guess you have to reinstall it though.

I’m getting an “Add on not found” error when trying to add HomePod Connect to Home Assistant

Should be fixed now

Has anyone been able see if the mDNS init failed issue is resolved in the HAOS 11.0 release candidates?

No, they haven’t. Still exists with 11.1.
I lost hope since there haven’t been any response in the bug report on this.
I have now migrated to Music Assistant. That works fine for my Sonos speaker, but unfortunately not for my Airplay or DLNA receivers.

Yeah, most likely this is related to the Docker engine upgrade. Docker introduced some new policies wrt open files, and we adopted this new policy (as it sounded like it should also improve performance).

There is some background in this blog post: New limits for Supervisor Add-ons | Home Assistant Developer Docs. @alexbabel it should be fairly trivial to work around by setting the new limit in your add-on.

That being said, Docker is discussing upstream to revert/change that default back to previous value (see fix: Normalize `RLIMIT_NOFILE` (LimitNOFILE) to sensible defaults by polarathene · Pull Request #45534 · moby/moby · GitHub). From what I understand this will get rolled out with Docker 25. We don’t try to reinvent the wheel on our end, and will follow what Docker officially releases.

1 Like

@agners, you mentioned a trivial workaround which I assume is from your link:

If you are an add-on developer and experience out-of-memory issues on Home Assistant OS 10, you can apply the old limit by using ulimit -n 1048576 before starting your service.

I run a local copy of the HomePod Connect addon and would like to see if I can apply the fix there. Do you or @alexbabel have some hint for where the ulimit -n 1048576 should go?

Also, I’m no wizard when it comes to docker and addons but when I run the addon under HAOS 11 I get the unreasonable ulimit -n workaround error. Just putting it out there, but it seems like dbus errors are what is causing avahi-deamon to not start.

Found user ‘avahi’ (UID 86) and group ‘avahi’ (GID 86).
Successfully dropped root privileges.
avahi-daemon 0.8 starting up.
WARNING: No NSS support for mDNS detected, consider installing nss-mdns!
dbus_bus_request_name(): Request to own name refused by policy
WARNING: Failed to contact D-Bus daemon.
avahi-daemon 0.8 exiting.
[2023-11-21 19:06:29] [ LOG] scan: Bulk library scan completed in 0 sec
[2023-11-21 19:06:29] [ LOG] spotify: No spotify refresh token found
[2023-11-21 19:06:29] [ LOG] spotify: Spotify webapi token refresh failed. In order to use Spotify, authorize the server to access your saved tracks by visiting http://owntone.local:3689
[2023-11-21 19:06:29] [ WARN] web: LWS [2023/11/21 19:06:29:3533] W: lws_create_context: unreasonable ulimit -n workaround
[2023-11-21 19:06:29] [ LOG] lib: Library init scan completed in 1 sec (2 changes)
[2023-11-21 19:06:29] [ LOG] mdns: Error ‘Bad state’ when creating service browser for _touch-remote._tcp, check that Avahi is running
[2023-11-21 19:06:29] [FATAL] remote: Could not browse for Remote services
[2023-11-21 19:06:29] [FATAL] main: Remote pairing service failed to start
[2023-11-21 19:06:29] [ LOG] main: MPD deinit

Thanks for digging into this further.

I copied these three folders with their files from linuxserver/docker-daapd (github.com) to my local HomepodConnect addon and added the ulimit statement before the execs in the run file in each folder.

Set max open file limit to avoid memory allocation issues

ulimit -n 1048576

I then rebuilt the addon and upgraded HAOS 9.5 to 10.1 and the addon worked as expected.

This approach to resolving the issue is based on: Limit maximum open file handles for EMQX specifically · agners/addon-emqx@0bc3cf0 · GitHub

Hey @agners,
So Docker engine it is… Thank you for finding this!

Hey @iVolt1,
Thank you for the proposed change!

Hey @alexbabel,
I have prepared a quick PR: Supervisor limits reverted to the old ones (experimental). by wojked · Pull Request #31 · AlexanderBabel/custom-images · GitHub with the changes from @iVolt1 (could you confirm this is the approach you took?)

I believe the command ulimit -n 1048576 might be run somewhere else… only once in the long run, however it might be considered as an optimisation/improvement. Right now the add-on is not behaving as expected due to this breaking change.

Hey @wojked

thank you for your PR, but it seems it does not work for me on HAOS 10.5.

Found user 'avahi' (UID 86) and group 'avahi' (GID 86).
Successfully dropped root privileges.
avahi-daemon 0.8 starting up.
WARNING: No NSS support for mDNS detected, consider installing nss-mdns!
dbus_bus_request_name(): Request to own name refused by policy
WARNING: Failed to contact D-Bus daemon.
avahi-daemon 0.8 exiting.

If you guys want to test out that version, feel free to install the docker image

docker pull ghcr.io/alexanderbabel/owntone:28.8-ls126

Or use the dev version of the addon as a drop in replacement for the production one. (Can be found in the addon store)

Hey @alexbabel

To be honest I tried this outside HA’s addons because I used ubuntu/docker.
I assumed naively this will apply to the Addon too.

Unfortunately, I confirm that I get the same error as you do.
So the investigation is not finished… Right now I am it seems like the “external” docker solution might be good enough for me and I am unable to dedicate too much time for debugging HA…

@iVolt1 you confirmed it worked as an addon in HA OS 10.1, is it still working in HA OS 10.5 with your changes somehow?

Yes, it is still working for me on HAOS 10.5. I have not tried going to HAOS 11.1 yet.

If I remove the ulimit statement from either the dbus or avahi services it no longer works. I will keep playing around to see if there is some other reason it works for me.

The revised HomePod Connect Dev did not work for me either so I will see what I can do to get that to work as well.

The ulimit fix on the dbus service worked for this shairport-sync user trying to get it to run in docker: [Problem]: Docker container not starting since 4.2 (Asahi Linux issue?) · Issue #1756 · mikebrady/shairport-sync · GitHub

I was getting dbus errors with new local copy of HomePod Connect Dev until I changed host_dbus: to false instead of true in the config.yaml. This is how I have been running my other local customized version. I incremented the version number in config.yaml to get it to rebuild as an update.

host_dbus: false

With the above change HomePod Connect Dev runs fine.

Today I saw that the HomePod Connect Dev repository had the config.yaml changed to have host_dbus: false instead of host_dbus: true so I uninstalled and installed the HomePod Connect Dev addon from the repository and it worked without issues on HAOS 10.5.

Thanks for fixing that so fast @alexbabel and thanks to @agners for giving some direction to a solution.

I did some looking to see what use cases there might be for host_dbus: true and did not find any.

It would be nice if the something in HA could be fixed so addon developers don’t need to consider the ulimit for deployment on past, current, and future versions of HA components.

@iVolt1 Thank you for your updates!

I have just uninstalled HomePod Connect Dev…
I have re-installed it again and it has started on HAOS 11.2 like it used to start!

This is the first time since a while when it started without mDNS init errors.
I will experiment more, seems promising!

Thanks this worked for me

I apologize if I missed this question already answered in the comments.

I’m trying to create a scene where I have spotify play a specific playlist on my homepods. I can’t seem to be able to figure this out. What is the best way to pass a specific playlist to play?