Media Cast / DLNA not working with Samsung TVs or Smart Monitors

I’ve been trying to get the Media Cast capability to work with four different models of Samsung TV or Monitor in order to even do something as rudimentary as display a picture. Nothing seems to work and despite a lot of research, I don’t appear to have been able to find a solution to it. Things that I’ve tried so far:

  • Added the device via the DLNA and Samsung Smart TV Integrations in HA
  • Validated that the devices can be controlled via HA for basic power controls etc.
  • Validated that the cast capability works on the Samsung devices from other devices such as an Android phone and Windows Desktop. Both succeed on all tested devices.
  • Moved the Samsung Devices to the same VLAN as the HA Server and validated that there is connectivity between the devices.
  • Tried turning on Debug logging on the DLNA Renderer integration to see whether anything notable appears in the logs. I can’t see anything obvious, but I’m admittedly not an expert in this.
  • Tested the HA Media Cast to a Google Cast device and can successfully stream the test picture, TTS audio, and Unifi Protect camera streams.

I’ve been able to find in the logs that the http://tv-ip:9197/upnp/control/AVTransport1 destination does reveal the following:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<script id="custom-useragent-string-page-script"/>
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
<faultstring>UPnPError</faultstring>
<detail>
<UPnPError xmlns="urn:schemas-upnp-org:control-1-0">
<errorCode>402</errorCode>
<errorDescription>Invalid Args</errorDescription>
</UPnPError>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>

This is the same on all screens that I’ve attempted to cast to from HA. The process which works for the Google Devices, as in the same button clicks, only occasionally results in a UI error which says “Failed to call service media_player/media_play. ‘Resource’ object has no attribute 'url”.

I don’t open a lot of requests for help as I’ve generally found that the community has a pretty decent spread of information for self help but after trying to get this working for five hours straight with no further progress and seeing that the facility work for Google Devices, but not Samsung; I’m genuinely out of ideas.

If someone could give me a nod in the right direction, that would be amazing!

UPNP is a service in your firewall/router, so maybe that is required, but disabled, for Samsung cast to work.

I appreciate the reply, but it’s also somewhat required for Chromecast, and that works flawlessly across a number of devices in the network. The main problem I get from HA is “Failed to call service media_player/media_play. ‘Resource’ object has no attribute ‘url’” and I don’t know what the crack is with that?

I looked a bit into the tests you have done and what I could find.
It sounds like you are mixing two different features up.

DLNA is a way to play a media source from a media service. The media source is transfered in the resource called media_content_id and it can be a sound og video file, like MP3, MP4, AVI or so on.

Cast is a way to play a stream from a stream service. The stream location is transfered in the resource called url and have to be a stream and it has to be a https:// url, because the protocol do not accept http://.

Yes understood on the difference to do with DLNA and Chromecast. I suppose the point of saying that I’d tested the Chromecast cast feature was to say that the functionality is working in HA, so it doesn’t appear to be an HA instance feature. I run a Ubiquiti network and there isn’t anything which I’m able to find in the new settings to enable UPnP. I’ve enabled other settings related to cast capability on the network where the HA instance runs, but I still get this same error. Unless I’m mistaken, UPnP shouldn’t be required on the WAN interface as the devices are both in the same subnet? My understanding was that UPnP is for the dynamic opening of firewall ports on demand, but this shouldn’t be necessary outside of the network unless there’s something which demands external brokering?

I do not think this is an uPNP error.
It looks like the media_plqy command gets a media-source instead of a stream url.

I’ve opened a bug for this as well here: Media Player Cast does not work with DLNA devices · Issue #111078 · home-assistant/core · GitHub. I don’t know whether the person who’s responsible for the code is around though as there are two Samsung TV bugs reported with DLNA so I don’t know if this is unique to me or if the other one is different. Do you have a Samsung TV which is working?

Can you post your parameters for your service call to cast?

This is the extract from the debug logs that I posted on the GitHub bug report:

AttributeError: 'Resource' object has no attribute 'url'. Did you mean: 'uri'?
2024-02-21 12:33:29.469 DEBUG (MainThread) [homeassistant.components.dlna_dmr] async_browse_media(app, media-source://media_source)
2024-02-21 12:33:30.390 DEBUG (MainThread) [homeassistant.components.dlna_dmr] Playing media: image/jpeg, media-source://media_source/local/20240212_192423.jpg, {'extra': {}}
2024-02-21 12:33:30.390 DEBUG (MainThread) [homeassistant.components.dlna_dmr] sourced_media is PlayMedia(url='/media/local/20240212_192423.jpg', mime_type='image/jpeg')
2024-02-21 12:33:30.391 DEBUG (MainThread) [async_upnp_client.traffic.upnp] Sending request:
HEAD http://<HAS-IP>:8123/media/local/20240212_192423.jpg?authSig=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI2ZjFlN2JjZDdlNzM0MThmOWViY2ZmNzVjZmRkOTlmMiIsInBhdGgiOiIvbWVkaWEvbG9jYWwvMjAyNDAyMTJfMTkyNDIzLmpwZyIsInBhcmFtcyI6W10sImlhdCI6MTcwODUxODgxMCwiZXhwIjoxNzA4NjA1MjEwfQ.HHSdd75kwlNCmE9AX8AlTnR_ecOQ4eIx3SlGNZaVe0g
GetContentFeatures.dlna.org: 1


2024-02-21 12:33:30.395 DEBUG (MainThread) [async_upnp_client.traffic.upnp] Got response from HEAD http://<HAS-IP>:8123/media/local/20240212_192423.jpg?authSig=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI2ZjFlN2JjZDdlNzM0MThmOWViY2ZmNzVjZmRkOTlmMiIsInBhdGgiOiIvbWVkaWEvbG9jYWwvMjAyNDAyMTJfMTkyNDIzLmpwZyIsInBhcmFtcyI6W10sImlhdCI6MTcwODUxODgxMCwiZXhwIjoxNzA4NjA1MjEwfQ.HHSdd75kwlNCmE9AX8AlTnR_ecOQ4eIx3SlGNZaVe0g:
405
Content-Type: text/plain; charset=utf-8
Allow: GET,OPTIONS
Referrer-Policy: no-referrer
X-Content-Type-Options: nosniff
Server: 
X-Frame-Options: SAMEORIGIN
Content-Length: 23
Date: Wed, 21 Feb 2024 12:33:30 GMT

b''
2024-02-21 12:33:30.395 DEBUG (MainThread) [async_upnp_client.traffic.upnp] Sending request:
GET http://<HAS-IP>:8123/media/local/20240212_192423.jpg?authSig=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI2ZjFlN2JjZDdlNzM0MThmOWViY2ZmNzVjZmRkOTlmMiIsInBhdGgiOiIvbWVkaWEvbG9jYWwvMjAyNDAyMTJfMTkyNDIzLmpwZyIsInBhcmFtcyI6W10sImlhdCI6MTcwODUxODgxMCwiZXhwIjoxNzA4NjA1MjEwfQ.HHSdd75kwlNCmE9AX8AlTnR_ecOQ4eIx3SlGNZaVe0g
GetContentFeatures.dlna.org: 1
Range: bytes=0-0

It is more the process to setup the cast I am interested in.

Click Media on the Side Menu > Click My Media > Click a JPG I uploaded for testing purposes > the bottom bar has the blue loading wheel briefly and then returns the following:

I then click the Play button and get the following pop up:

I’ve tried this with different media, such as the Unifi Protect cameras, but even some of those come up as incompatible for live streams with the DLNA Samsung TV sources, but will cast using Chromecast. Dashboards too are unavailable via the DLNA casting devices, though this may be related to what you were saying about the HTTP resources and how the two casting methods work differently.

DLNA and Cast is not the same.
It is two different things.

Hi @openhorizon Did you get this working? I have a bunch of Samsung TVs that I want to be able to display pictures. (Club situation where I want an automation to lick them all off HDMI onto a bunch of inhouse jpg for advertising) and the back to HDMI (Also turn them all on/off rather than running around with a remote control)

From the DNLA debug

2024-07-09 14:41:56.948 DEBUG (MainThread) [async_upnp_client.traffic.upnp] Got response from POST http://10.12.54.85:9197/upnp/control/AVTransport1:
200
EXT:
Connection: close
Content-Type: text/xml; charset=“utf-8”
Server: UPnP/1.0, Samsung AllShare Server/1.0
Date: Tue, 09 Jul 2024 04:41:56 GMT
User-Agent: Samsung User-Agent DLNADOC/1.50
Content-Length: 443

b’<?xml version="1.0" encoding="utf-8"?><s:Envelope s:encodingStyle=“http://schemas.xmlsoap.org/soap/encoding/” xmlns:s=“http://schemas.xmlsoap.org/soap/envelope/”><s:Body><u:GetTransportInfoResponse xmlns:u=“urn:schemas-upnp-org:service:AVTransport:1”>STOPPED\r\nOK\r\n1\r\n</u:GetTransportInfoResponse></s:Body></s:Envelope>’
2024-07-09 14:41:56.948 DEBUG (MainThread) [async_upnp_client.client] Called action: GetTransportInfo, args: {‘InstanceID’: 0}, response_args: {‘CurrentTransportState’: ‘STOPPED’, ‘CurrentTransportStatus’: ‘OK’, ‘CurrentSpeed’: ‘1’}
2024-07-09 14:41:56.949 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved (None)
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 1048, in _async_update_entity_states
await entity.async_update_ha_state(True)
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 962, in async_update_ha_state
self._async_write_ha_state()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 1133, in _async_write_ha_state
state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 1091, in __async_calculate_state
if (entity_picture := self.entity_picture) is not None:
^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/media_player/init.py”, line 1068, in entity_picture
return self.media_image_local
^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/media_player/init.py”, line 1073, in media_image_local
if (image_hash := self.media_image_hash) is None:
^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/media_player/init.py”, line 639, in media_image_hash
if (url := self.media_image_url) is not None:
^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/dlna_dmr/media_player.py”, line 894, in media_image_url
return self._device.media_image_url
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/site-packages/async_upnp_client/profiles/dlna.py”, line 1212, in media_image_url
return absolute_url(device_url, res.url)
^^^^^^^
AttributeError: ‘Resource’ object has no attribute ‘url’. Did you mean: ‘uri’?