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
72.62k stars 30.38k forks source link

Cast: External URL is no longer resolvable in 0.115 and some integrations fail to pull it properly #40273

Closed dshokouhi closed 4 years ago

dshokouhi commented 4 years ago

The problem

I was trying to play with the new stream features and went to cast a camera and I got an error in the logs:

Failed to cast media https://192.168.1.48:8123/api/hls/dfa768e11fafe3ae1eb8b29f8fe83c26111bc8cfbace4411d8035f60af521bbe/playlist.m3u8 from internal_url (https://192.168.1.48:8123). Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address
Failed to cast media https://www.home-assistant.io/images/cast/splash.png. Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address
Failed to cast media https://DOMAIN:8123/api/tts_proxy/a94a8fe5ccb19ba61c4c0873d391e987982fbbd3_en_-_google_translate.mp3 from external_url (https://DOMAIN:8123). Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address

Example from Cast: https://github.com/home-assistant/core/blob/dev/homeassistant/components/cast/media_player.py#L364

My own configuration that shows I have external URL configured:

homeassistant:
  name: Home
  latitude: !secret home_lat
  longitude: !secret home_long
  elevation: 739
  unit_system: imperial
  time_zone: America/Los_Angeles
  customize: !include customize.yaml
  external_url: !secret baseurl

Environment

Problem-relevant configuration.yaml

service: camera.play_stream
entity_id: media_player.den_home_hub
media_player: camera.baby_monitor

Traceback/Error logs

Failed to cast media https://192.168.1.48:8123/api/hls/dfa768e11fafe3ae1eb8b29f8fe83c26111bc8cfbace4411d8035f60af521bbe/playlist.m3u8 from internal_url (https://192.168.1.48:8123). Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address
Failed to cast media https://www.home-assistant.io/images/cast/splash.png. Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address
Failed to cast media https://DOMAIN:8123/api/tts_proxy/a94a8fe5ccb19ba61c4c0873d391e987982fbbd3_en_-_google_translate.mp3 from external_url (https://DOMAIN:8123). Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address

Additional information

The TTS call was successful but the camera stream was not successful so I am not 100% sure if that is the issue.

probot-home-assistant[bot] commented 4 years ago

cast documentation cast source (message by IssueLinks)

probot-home-assistant[bot] commented 4 years ago

Hey there @emontnemery, mind taking a look at this issue as its been labeled with an integration (cast) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

frenck commented 4 years ago

https://192.168.1.48:8123

You have HTTPS set on a IP address, which means the SSL certificate is never valid.

dshokouhi commented 4 years ago

@frenck while that may be true looking at the flow of things cast should've picked up my tts config where I have my external URL defined. I also have my external url defined in my main configuration so that shouldve been used too. I do have HA under https but for something like cast it should never prefer local IP over external, and in the past this was not an issue. Cast devices must use publicly accessible URLs per the error I posted. If you notice in the 3 errors above you'll see that even the home assistant URL is failing to load and says its not public when we know it is. TTS has the same error for my actual external URL except the difference there is that it works, however the error was not in 0.114.

Whats happening here is that when using camera.play_stream cast tries to use hte internal URL only eventhough it has the external. In the past it did prefer external and it was working but I am not sure if it was working in 0.114.

cjamieso commented 4 years ago

I've been seeing similar issues. On 114 or below I can play streams on my google home hub (or chromecast), but on 115, it no longer works. I've been using snapshots to flip back and forth to verify. Sometimes I get the error in the logs that you do, but other times it doesn't seem to show.

I assumed my issue was related to addition of audio to the streams, but perhaps something else is at work here.

KennethLavrsen commented 4 years ago

I have similar issue https://github.com/home-assistant/core/issues/40376

But I do not see the error in the logs about urls

KennethLavrsen commented 4 years ago

Tried again this morning. Nothing in my logs. I can cast the Lovelace screens to the Google Homes. And tts also works My extermal URL is (distorted on purpose) https://home.xxxxxxxx.dk/ and my internal URL is http://192.168.1.15:8123/ The external URL is a valid working real domain that I pay for and it works. My Ubiquiti router has hairpin enabled so the external URL actually works also inside my home with valid SSL certs.

ghost commented 4 years ago

I am having the same issue, my TTS has not been working as well. I have tried setting the base_url to the IP or my duckdns url's and I get the same result. Previously I did not have a base_url set and it was working ok. I recently had to restore my installation so I wasn't sure when the issue appeared or if it was due to me but in trying to resolve the issue I found this ticket. I believe the issue started around the release of 0.114

The Google device plays it's awaken sound as it comes out of sleep, hubs activate their screen, but no sound plays. The TTS plays fine in the browser when I navigate to the URLs.

Logger: homeassistant.components.cast.media_player
Source: components/cast/media_player.py:382
Integration: Google Cast (documentation, issues)
First occurred: 1:29:19 PM (6 occurrences)
Last logged: 1:29:27 PM

Failed to cast media https://---------.duckdns.org:8123/api/tts_proxy/e3cdfdbb3b2310333c45bc9dfe0eb873506086ee_en_-_google_translate.mp3 from external_url (https://---------.duckdns.org:8123). Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address
Failed to cast media https://---------.duckdns.org:8123/api/tts_proxy/1921a59c33cd26ed73247fe2dc6ec6f6faa01fca_en_-_google_translate.mp3 from external_url (https://---------.duckdns.org:8123). Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address

Update

I finally got it working, but it doesn't seem like the proper way to utilize it. I set both my External URL and Internal URL to my duckdns.org address in the General Configuration.

boda1976 commented 4 years ago

Something similar for me.

D-link camera feed/stream via onvif integration,( no SSL ) which I then use with cast integration to show on my chromecast when somebody triggers a motion sensor approaching my house.

I first had local IP configured in external_URL and internal_URL which kind of produced similiar output as below (change hostname to some typical RFC 1918 IP). Then tried snook's solution using static home-mapping record at my home router ( which then produced output below) however no success for me.

Logger: homeassistant.components.cast.media_player
Source: components/cast/media_player.py:382
Integration: Google Cast (documentation, issues)
First occurred: 25 september 2020 20:51:13 (9 occurrences)
Last logged: 25 september 2020 20:51:53

Failed to cast media https://www.home-assistant.io/images/cast/splash.png. Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address
Failed to cast media http://YYXX-YYXX.duckdns.org/api/hls/4c69c7654383d9d7be4d1aaae142ead282ba027245c3d10bd0a729cd28266624/playlist.m3u8 from internal_url (http://YYXX-YYXX.duckdns.org). Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address

Hope it helps. . .

chrisavfc commented 4 years ago

I'm having similar issues with being unable to cast, however I'm using Nabu Casa for the cloud support and it looks like the other reports are using other solutions (duckdns etc).

Edit: Going via the Nabu Casa address or the local IP address below manually works fine. https://... .ui.nabu.casa/local/day.jpeg

Whereas Home Assistant seems to be casting https://... .ui.nabu.casa/config/www/day.jpeg

stboch commented 4 years ago

@chrisavfc I am using Nabu Casa as well and noticed this issue as well.

balonchiks commented 4 years ago

i am having sort of a similar issue, i was thinking that it's the yandextts integration that got broken, but apparently it isn't

on versions 0.115.1 (it still works on 0.114.4) and later i am seeing this in config when trying to case something to my media players:

Failed to cast media **_hello_**. Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address

where hello is the command i'm trying to say.

changing Internal url to the same value as external url haven't made any difference.

dzungpv commented 4 years ago

I have the same problem, on previous version (.114 and ealier) it work fine, now i see the logs:

Failed to cast media https://localip/api/tts_proxy/words_-_google_translate.mp3 from internal_url (https://localip). Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address
nettosama commented 4 years ago

Camera works in the frontend for me (amcrest and generic), but they both fail when casting to any cast device:

Failed to cast media http://192.168.1.72:8123/api/hls/cd4a3b1eefd5a5f369aa4b978a53174757100f688a2a22bd9379a52d84d0d101/master_playlist.m3u8 from internal_url (http://192.168.1.72:8123). Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address
Failed to cast media http://192.168.1.72:8123/api/hls/4b00eac51bcaab370e63d806a6ae56fa54754dd6af96f0003e081bb24d39971d/master_playlist.m3u8 from internal_url (http://192.168.1.72:8123). Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address

They worked on the previous version. I have set my external_url properly.

nerdosity commented 4 years ago

Had the same problem too. Had always worked, now my Google Mini can't speak TTS anymore.

stboch commented 4 years ago

Had the same problem too. Had always worked, now my Google Mini can't speak TTS anymore.

@nerdosity this was do to a change end of 0.115 to add a different cast recieve that doesn't work on audio only devices 0.116.b1 rolls back the change and fixed the TTS issue. Still an issue with the camera feed.

stboch commented 4 years ago

@dshokouhi @balloob It looks like an error on the chromecast side where it doesn't like the socket buffer? Not sure I know enough about pychromecast to figure this one out. I forced a vaild SSL url and it doesn't matter this was broken as part of the movie to mp4 from mp2t on the video format. I also changed the media type to be application/x-mpegurl instead of the apple vendor mapping and no dice either. 2020-10-02 16:32:24 DEBUG (Thread-11) [pychromecast.socket_client] [Master Bedroom TV 2(10.1.0.2):8009] Message unhandled: Message urn:x-cast:com.google.cast.media from 116aea84-48dd-41b0-8d34-b79ea86eab9b to sender-0: {'requestId': 166, 'type': 'LOAD_FAILED', 'detailedErrorCode': 110, 'itemId': 1}

stboch commented 4 years ago

Ok seems like I might have made some more progress. It looks like a codec issue I don't have a Chromecast Ultra but it looks like Chromecast doesn't support at least in the camera feed I was attempting to display. CODECS="avc1.4d0032,mp4a.40.2 https://developers.google.com/cast/docs/media Only supports upto H.264 level 4.2 as AVC1 then changes to hev1 but even then H.265 is only supported on Chromecast Ultra. best would be to support h.264 level 4.1 which will allow support for Gen1 chromecasts still.

Not sure if there is a good way to have multiple codec streams

stboch commented 4 years ago

Is there a reason this PR isn't in the beta? https://github.com/home-assistant/core/pull/40641 haven't tried if it fixes the issue.

arsaboo commented 4 years ago

I am seeing the same errors. Lights and other entities work with google_assistant

Failed to cast media https://blah.duckdns.org/api/hls/a6cab55b62b69d063ec6849XYZ6216e8326752/master_playlist.m3u8 from external_url (https://blah.duckdns.org). Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address
theleshek commented 4 years ago

hi

I have same error, internal_url is used during cast instead of external one. as soon as I change my internal_url to my external address, cast works as it should.

Is there any date set when can it be fixed? It started for me to be an issue either with version 0.113 or 0.114.

balloob commented 4 years ago

TTS will use the configured TTS base url or request a url (internal/external) - last changed 5 months ago https://github.com/home-assistant/core/blob/0f3489f5cbcea80f5a5b967cf640d2ed9d928110/homeassistant/components/tts/__init__.py#L120

Stream will return a relative url - last changed 2 years ago https://github.com/home-assistant/core/blob/0f3489f5cbcea80f5a5b967cf640d2ed9d928110/homeassistant/components/stream/hls.py#L21

Camera requests a url (internal/external) and combines it with stream - last changed 5 months ago https://github.com/home-assistant/core/blob/0f3489f5cbcea80f5a5b967cf640d2ed9d928110/homeassistant/components/camera/__init__.py#L700

The default options for get_url - last changed 5 months ago https://github.com/home-assistant/core/blob/0f3489f5cbcea80f5a5b967cf640d2ed9d928110/homeassistant/helpers/network.py#L28-L40

The Cast integration is not actually responsible for getting a url in this case. It receives a full url from both TTS and Camera

If you have issues, please include:

balloob commented 4 years ago

Step 1 to solve this, is that less is more. Remove your internal url if you have set it to https://<ip-address>. That is more pain than it's worth. If you really feel like setting it, and your router supports it, set it to your external url.

https://<ip-address> will always be invalid as your certificate is meant for a domain name, not an IP address.

nettosama commented 4 years ago

My case is using cameras, casting through an script using camera.play_stream. I changed internal_url to match my external_url (YAML configuration).

Now the error looks like this:

    Failed to cast media https://***/api/hls/a4a0be20d6573f523c5d03d45d2681fe223389e7e94aa97b26044119ce0b5823/master_playlist.m3u8 from internal_url (https://***). Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address
    Failed to cast media https://***/api/hls/e8f60dc7fef8b62c3c6e1fddf54850249fa3bdff304c85a705dd0e5d86de48e2/master_playlist.m3u8 from internal_url (https://***). Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address

*** being my external_url which is correctly accessible from outside (I can even open the reported url through VLC, though it stops after a second).

The cast app starts on the Google Home Hub, but the camera itself never loads.

raz0rf0x commented 4 years ago

Service called: camera.play_stream External URL: https://homeassistant.xxxx.yyy Internal URL: blank Home Assistant supervised 0.116.0 .

http://192.168.0.232:8123/api/hls/68c83c1909a6bf0141b13933fe664bdb3e10f246489b511da5684b75100b81a3/master_playlist.m3u8

Error: ERROR (Thread-27) [homeassistant.components.cast.media_player] Failed to cast media http://192.168.0.232:8123/api/hls/68c83c1909a6bf0141b13933fe664bdb3e10f246489b511da5684b75100b81a3/master_playlist.m3u8 from internal_url (http://192.168.0.232:8123). Please make sure the URL is: Reachable from the cast device and either a publicly resolvable hostname or an IP address

Casting to a Google Chromecast works. It is running Cast firmware ver. 1.49.226077 . Casting to a Google/Nest Home Hub running cast firmware 1.50.229149 does not work. I did have that hub in the beta program and this may be the cause.

TTS Works. Casting a camera does not. Casting an audio file from the media library works.

If I enter that URL into VLC while the app is running it shows the camera feed on VLC.

balloob commented 4 years ago

I think that we should update our error message. I don't think that @raz0rf0x issue is related to being resolvable but instead have to do with Cast not being able to play the video. Please make sure you run Home Assistant 116 and if you can reproduce it, please open a new issue. Make sure you include the camera that you use and how it is integrated into Home Assistant.

nettosama commented 4 years ago

I reverted back to homeassistant-0.114.3, and the stream plays correctly, without setting internal_url to external_url.

So might be something related to the cast component, maybe the hls cast code.

probot-home-assistant[bot] commented 4 years ago

stream documentation stream source (message by IssueLinks)

probot-home-assistant[bot] commented 4 years ago

Hey there @hunterjm, @uvjustin, mind taking a look at this issue as its been labeled with an integration (stream) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

uvjustin commented 4 years ago

It seems like this issue is a mix of a few different issues compounded by a possibly misleading error message, different cast devices, and several rolling changes to stream, pychromecast, cast, and google assistant across 0.115 and 0.116. I think the most likely start of the issue was the change from TS to fMP4 segments in stream in 0.115. I don't think it makes sense to revert the segment formats to TS as fMP4 is an essential part of the newer HLS standard - it has less overhead, supports H.265, and will be necessary if we implement future extensions such as Low-Latency HLS. It also doesn't seem to be causing any problems with players EXCEPT with Google Cast. The problem with Google Cast was that there was a not very well documented parameter that had to be sent along with the Cast call that specified the fMP4 segment format, otherwise the player seemed to default to TS. @hunterjm was able to make the relevant changes in stream, cast, and pychromecast to get this done. This seemed to get it working for most cases. There was a change to use a custom cast app for Google Assistant and media player 0.115.6 and then a reversion of the media player part of that in 0.116.0. All these changes have made the troubleshooting quite problematic. From looking at the above I think we have several different cases here: 1) @snook @theleshek Problems with the external/internal urls starting in 0.114.x 2) @balonchiks @dzungpv @nerdosity Problems with TTS starting in 0.115.x 3) @nettosama @stboch @arsaboo Problems casting HLS starting in 0.115.x 4) @raz0rf0x Problems casting only to Google Nest Hub I think only 2) and some of 3) are related to the original issue in the title. @balloob Should we split this issue into different issues?

balloob commented 4 years ago

Yes we should split this issue. I think at this point it's better to close this one and have new issues created for each of them, so to not further confuse other people.

nov30th commented 3 years ago

I've met this issue a long time ago, currently, I need the Google Home/Cast to work with music playing. The problem might be the URL which IP address with SSL. once I put the

homeassistant:
  external_url: https://xxx.xxx.xxx:xxx
  internal_url: https://192.168.123.165:38123

I saw the post data to cast is external_url, I set the router's static DNS to the HA internal IP address with its external_url domain, the google home mini works. problem solved. [20210303]

nov30th commented 3 years ago

Steps:

  1. set the external_url in HA config.
  2. adds the static DNS record for the external_url domain points to the HA server. finally, Google home mini and any other 3rd part services work.