Home Assistant integration is using external_url with it should be using internal_url

I have a Home Assistant OS configuration with internal_url and external_url set up with a proxy on split DNS. That means local machines can only access HAOS through the internal_url and external machines can only access HAOS through the external_url. Most things work great, but occasionally Home Assistant decides to use the external_url for callback URLs when it should be using the internal_url.

How can I get Home Assistant to use the internal_url for callback integrations correctly?

Case in point is the Music Player Daemon integration. With an MPD set up on a local machine, the integration can find the MPD, but when I try to play anything to it the logs for MPD show Home Assistant is sending it a media URL using the external_url which it can’t access.

The MPD computer and Home Assistant are on the same subnet. So how do I get Home Assistant to properly send the media link with the internal_url?

Do you mind explaining why you have this setup? It’s not like the internal URL can be accessed externally and the inverse doesn’t seem to matter.

Are you referring to the companion app?

Can you determine if it is specific devices that makes it act like that.

I have a similar setup and I found that switching from mobile plan to WiFi on my mobile phone meant it acted like that for some time after the switch, because the phone had cached DNS lookups.
I ended up getting an extra domain for my internal network only, so DNS entries would never have the same FQDN with different IP addresses attached.

The reasoning for why I have split DNS and why external can’t use internal_url and internal can’t use external_url isn’t really relevant to the problem. Internal systems should be sent media address using internal_url regardless. Or why even bother to have them as a split option in the config? But to answer, it’s split DNS to allow proper certificate signing on internal and external services. Some of the internal (non Home Assistant) are routed externally. That also means I have a wildcard DNS record set up to not expose those endpoints globally through a simple DNS query. All services internal and external are routed appropriated through a proxy that uses destination hostname and port for the routing. And that’s why external_url can’t work internally.

And I don’t mean the companion app. I mean Home Assistant itself. Whenever an integration or add-on sends a media link that points back to something on Home Assistant it seems to put the external_url into that link no matter what. It seems common across a couple integrations which makes me think it’s either something in core or it’s something integration programmers aren’t understanding for how to determine and select correctly between internal_url and external_url

It’s not device dependent. The example I use is a fixed server on the internal network right there next to Home Assistant itself. I see the same problem for some other integrations I can test on my phone and it’s always the external_url sent, which means on my phone when disconnected from my internal network they work, because the phone will try to access the media Home Assistant sent through the external_url and since it’s external, it’ll work. But the instant I put it back on the wifi and make it internal, it’s still getting external_urls and won’t work. The MPD can’t switch between the two and is always internal only, so it’s not a DNS issue, it’s that the wrong URL is getting sent in the first place.

Sounds like something is wrong in the integration configuration or in the MPD setup.