[solved] Pychromecast not connecting to devices (zeroconf issue)

I’m running HA in a docker container on my router, network is in hostmode and cast discovery of devices works, but connecting to them doesn’t work for HA for some unknown reason and they appear as not connected / not available in the UI.

2023-09-23 10:49:41.865 DEBUG (Thread-2) [pychromecast.dial] Resolved service ServiceInfo(type='host', data=('Google-Home', 8009)) to Google-Home
2023-09-23 10:49:41.972 DEBUG (zeroconf-ServiceBrowser-_googlecast._tcp-222) [pychromecast.discovery] add_service _googlecast._tcp.local., Google-Home-e6abf81fd4380f7992aeee28813cb6ce._googlecast._tcp.local.
2023-09-23 10:49:42.340 DEBUG (zeroconf-ServiceBrowser-_googlecast._tcp-222) [pychromecast.discovery] Addded host fe80::f6f5:d8ff:fec0:fb18
2023-09-23 10:49:42.361 DEBUG (zeroconf-ServiceBrowser-_googlecast._tcp-222) [pychromecast.discovery] add_service _googlecast._tcp.local., Google-Cast-Group-22d14f39b13f4bdebaf52d82dcd92048-1._googlecast._tcp.local.
2023-09-23 10:49:43.648 DEBUG (SyncWorker_1) [pychromecast] get_chromecast_from_cast_info CastInfo(services={ServiceInfo(type='mdns', data='Google-Home-e6abf81fd4380f7992aeee28813cb6ce._googlecast._tcp.local.')}, uuid=UUID('e6abf81f-d438-0f79-92ae-ee28813cb6ce'), model_name='Google Home', friendly_name='Wohnzimmer', host='fe80::f6f5:d8ff:fec0:fb18', port=8009, cast_type='audio', manufacturer='Google Inc.')
2023-09-23 10:49:44.007 DEBUG (zeroconf-ServiceBrowser-_googlecast._tcp-222) [pychromecast.dial] get_info_from_service resolved service ServiceInfo(type='mdns', data='Google-Cast-Group-22d14f39b13f4bdebaf52d82dcd92048-1._googlecast._tcp.local.') to service_info ServiceInfo(type='_googlecast._tcp.local.', name='Google-Cast-Group-22d14f39b13f4bdebaf52d82dcd92048-1._googlecast._tcp.local.', addresses=[], port=32201, weight=0, priority=0, server='e6abf81f-d438-0f79-92ae-ee28813cb6ce.local.', properties={b'rs': None, b'nf': b'1', b'bs': b'FA8FCA88524C', b'st': b'0', b'ca': b'199204', b'fn': b'Zuhause', b'ic': b'/setup/icon.png', b'md': b'Google Cast Group', b've': b'05', b'rm': b'9DE8AAFE0BBE4F54', b'cd': b'22d14f39-b13f-4bde-baf5-2d82dcd92048', b'id': b'22d14f39-b13f-4bde-baf5-2d82dcd92048'}, interface_index=None)
2023-09-23 10:49:44.012 DEBUG (zeroconf-ServiceBrowser-_googlecast._tcp-222) [pychromecast.dial] Resolved service ServiceInfo(type='mdns', data='Google-Cast-Group-22d14f39b13f4bdebaf52d82dcd92048-1._googlecast._tcp.local.') to e6abf81f-d438-0f79-92ae-ee28813cb6ce.local.
2023-09-23 10:49:44.173 DEBUG (Thread-4) [pychromecast.socket_client] [(unknown):8009] connection listener: a78ba350 (CastStatusListener) ConnectionStatus(status='CONNECTING', address=NetworkAddress(address='unknown', port=8009))
2023-09-23 10:49:45.258 DEBUG (Thread-4) [pychromecast.dial] get_info_from_service resolved service ServiceInfo(type='mdns', data='Google-Home-e6abf81fd4380f7992aeee28813cb6ce._googlecast._tcp.local.') to service_info ServiceInfo(type='_googlecast._tcp.local.', name='Google-Home-e6abf81fd4380f7992aeee28813cb6ce._googlecast._tcp.local.', addresses=[], port=8009, weight=0, priority=0, server='e6abf81f-d438-0f79-92ae-ee28813cb6ce.local.', properties={b'rs': b'Default Media Receiver', b'nf': b'1', b'bs': b'FA8FCA88524C', b'st': b'1', b'ca': b'207364', b'fn': b'Wohnzimmer', b'ic': b'/setup/icon.png', b'md': b'Google Home', b've': b'05', b'rm': b'9DE8AAFE0BBE4F54', b'cd': b'D7D2F47F071E4F7A80618DD2112DE3DD', b'id': b'e6abf81fd4380f7992aeee28813cb6ce'}, interface_index=None)
2023-09-23 10:49:45.262 DEBUG (Thread-4) [pychromecast.socket_client] [Wohnzimmer(unknown):8009] Resolved service ServiceInfo(type='mdns', data='Google-Home-e6abf81fd4380f7992aeee28813cb6ce._googlecast._tcp.local.') to e6abf81f-d438-0f79-92ae-ee28813cb6ce.local.:8009
2023-09-23 10:49:45.264 DEBUG (Thread-4) [pychromecast.socket_client] [Wohnzimmer(e6abf81f-d438-0f79-92ae-ee28813cb6ce.local.):8009] Connecting to e6abf81f-d438-0f79-92ae-ee28813cb6ce.local.:8009
2023-09-23 10:49:45.294 DEBUG (Thread-4) [pychromecast.socket_client] [Wohnzimmer(e6abf81f-d438-0f79-92ae-ee28813cb6ce.local.):8009] connection listener: a78ba350 (CastStatusListener) ConnectionStatus(status='FAILED', address=NetworkAddress(address='e6abf81f-d438-0f79-92ae-ee28813cb6ce.local.', port=8009))
2023-09-23 10:49:45.296 ERROR (Thread-4) [pychromecast.socket_client] [Wohnzimmer(e6abf81f-d438-0f79-92ae-ee28813cb6ce.local.):8009] Failed to connect to service ServiceInfo(type='mdns', data='Google-Home-e6abf81fd4380f7992aeee28813cb6ce._googlecast._tcp.local.'), retrying in 5.0s

I don’t even see a connection attempt on the mentioned port, which makes sense since it seems like the address cannot be properly resolved?

$ sudo tcpdump -i eth0 port 8009 -n -v
tcpdump: listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
0 packets captured
0 packets received by filter
0 packets dropped by kernel

The interesting thing is when I docker exec -it … into the container and run the example (GitHub - home-assistant-libs/pychromecast: Library for Python 3 to communicate with the Google Chromecast.) everything works fine, i.e. I can see status of the device and play media on it, so this may be a mdns in HA issue?

Anyone has any idea what’s wrong / how to investigate this further?

I figured it out. The router has eth0 and wlan0. The former is the home network that contains the cast devices, the latter is the internet connection. The mDNS things were only running on wlan0 (though somehow getting some messages from the eth0 interface). Not sure why :confused:

Once I enabled expert mode I was able to configure which interfaces HA uses, and voilà :slight_smile: Now it’s working as intended.