home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.74k stars 30.86k forks source link

Google cast integration not accepting any devices #34931

Closed BeardedTinker closed 4 years ago

BeardedTinker commented 4 years ago

The problem

After upgrade to latest release (v 0.109) all Google Cast devices disappeared. They were not added through integration page, but added and working through manual cast: configuration.

Disabling manual configuration trying to add them through Integrations, restarting, deleting etc doesn't make any difference.

Environment

Problem-relevant configuration.yaml

cast:
  media_player:
    - host: !secret chromecast_living_ip  
    - host: !secret chromecast_loft_ip
    - host: !secret google_home_mini_ip
    - host: !secret google_nest_hub_ip
    - host: !secret google_home_mini_2_ip
    - host: !secret google_lenovo_clock_ip

Traceback/Error logs

none

Additional information

Not sure if this is related to https://github.com/home-assistant/core/pull/33922 as this is the only change I've seen for this release that has anything to do with Cast integration. I don't use and have option to use mDNS, all devices are on same network and subnet.

danibercero commented 4 years ago

In case anyone can help, I have continued investigating my problem. In my router, by deactivating the IGMP Snooping option, I see Cast devices in my wired LAN again, without having to activate the wifi.

Martinvdm commented 4 years ago

@danibercero i do have this setting in my UniFi switch/controller. I do not have an USG. Strange thing is that my clients on LAN can discover clients in IOT, but Home Assistant container can’t, despite using Avahi.

Martinvdm commented 4 years ago

I did investigate this further more. It does seems to be an issue in HA docker. Iam running Home Assistant with net=host requirement. Some results:

22:49:45.231428 IP (tos 0x0, ttl 255, id 35454, offset 0, flags [DF], proto UDP (17), length 386)
    Chromecast-Ultra.domain.local.mdns > 224.0.0.251.mdns: [udp sum ok] 0*- [0q] 1/0/3 _googlecast._tcp.local. PTR Chromecast-Ultra-4b647692a2c9055eb97b8b18ace185ce._googlecast._tcp.local. ar: Chromecast-Ultra-4b647692a2c9055eb97b8b18ace185ce._googlecast._tcp.local. (Cache flush) TXT "id=4b647692a2c9055eb97b8b18ace185ce" "cd=C1A51BAA367D65F36523A1CAC0B55A3E" "rm=" "ve=05" "md=Chromecast Ultra" "ic=/setup/icon.png" "fn=Chromecast" "ca=200709" "st=0" "bs=FA8FCA7146AE" "nf=1" "rs=", Chromecast-Ultra-4b647692a2c9055eb97b8b18ace185ce._googlecast._tcp.local. (Cache flush) SRV 4b647692-a2c9-055e-b97b-8b18ace185ce.local.:8009 0 0, 4b647692-a2c9-055e-b97b-8b18ace185ce.local. (Cache flush) A 10.10.11.13 (358)

so my conclusion is that is seems to be something with Home assistant i think.

emontnemery commented 4 years ago

@martinvdm if list_chromecasts.py does not work, it most likely means sending and/or receiving of mDNS multicast packets is not working correctly. You have a very complicated setup, can you test to temporarily put Chromecasts and Home Assistant on the same network to make sure list_chromecasts.py is working on host and in container. Next, suggest to run wireshark on both networks while again running list_chromecasts.py to verify forwarding is working.

Edit: Please also check there is no other rules blocking the traffic enabled on the host, for example https://github.com/home-assistant/core/issues/34931#issuecomment-623394430

Martinvdm commented 4 years ago

Thanks for the advise. I continously searching for a solution. My setup is not very complicated. Just HA docker container with net=host (advise) in LAN and IoT devices in other vLAN. That list_chromecast.py isn't listing any devices i can;t level this with the fact that i do see all multicast traffic on the host with tcpdump. I did check iptables, offcourse there are some docker default entries, but Home Assistant is on the host.

I did try home assistant in the iOT vlan withhout network_mode: host, that seems to work fine. So it has to be something on the host level i think.

emontnemery commented 4 years ago

@Martinvdm

My setup is not very complicated. Just HA docker container with net=host (advise) in LAN and IoT devices in other vLAN.

It's still a bit more complex than a typical domestic setup, and something in the setup seems incorrect since mDNS discovery is working when homassistant is in the IoT VLAN but breaks when it's not.

The UDP broadcast traffic across VLANs may be dropped by a switch, router, AP, the host running HA etc.

To debug further, I suggest to log packets when list_chromecasts.py --show-debug is running. I would suggest to log:

Then compare differences between the logs.

In the packet logs you should see something like this (as parsed with wireshark):

protocol info comment
MDNS Standard query 0x0000 PTR _googlecast._tcp.local, "QM" question Query from pychromecast to discover chrome cast devices
MDNS Standard query response 0x0000 PTR Chromecast-Audio-b3904b74c13867cd723fd589d5f305e7._googlecast._tcp.local TXT, .... Response from a Chromecast device
MDNS Standard query response 0x0000 PTR Google-Cast-Group-657e8e9d261e42e79fc536748ad083c5-1._googlecast._tcp.local TXT, ... Response from a Chromecast device
Martinvdm commented 4 years ago

@emontnemery great thanks for the help. Will try that and report

Martinvdm commented 4 years ago

Sorry could'nt get socat working, command:

socat UDP4-RECV:mdns,broadcast,reuseaddr | hexdump -C

keep getting:

 socat[26636] E exactly 2 addresses required (there are 1); use option "-h" for help

i don't know socat very well.....

emontnemery commented 4 years ago

@Martinvdm There was a mistake in the socat command, it should be: socat UDP4-RECV:mdns,broadcast,reuseaddr - | hexdump -C Sorry about that.

Martinvdm commented 4 years ago

Ok great. that command is accepted, but not giving any output, neither from the host, neither from within the ha container. I did migrated the container to the IOT vlan and chromecast started working in ha. tcpdump giving chromecast info again, but this was also there in the main lan. not quite sure, but it seems to be the host which is not receiving the mdns info from the over vlan., despite using avahi-reflector.

Did tried it with Windows and Bonjour browser from both vlans working just fine and can see al mdns info, including googles from other vlan. so again, it seems to be my ubuntu docker host somehere here i think

emontnemery commented 4 years ago

Maybe this can be helpful: https://serverfault.com/questions/163244/linux-kernel-not-passing-through-multicast-udp-packets

The comment about tcpdump -e to make sure the packets you see are for the right VLAN is interesting.

You're sure mDNS forwarding between the VLANs is working correctly?

emontnemery commented 4 years ago

I'm closing this issue since it seems Home Assistant is working fine as long as mDNS is allowing device discovery. If this is not the case, please go ahead and open another issue.