smoothr
(SmoothR)
November 18, 2019, 5:53am
1
Hi there! I have tried for hours but can’t figure this one out…
I added a sensor that returns the following value for below state_attr. I know it works because I can test it in Developer Tools > Template. What am I doing wrong? Thanks!
{{state_attr("sensor.gpodder","podcasts")[0]["episodes"][0]["url"]}}
Returns
https://play.podtrac.com/npr-500005/edge1.pod.npr.org/anon.npr-mp3/npr/newscasts/2019/11/18/newscast000816.mp3?awCollectionId=500005&awEpisodeId=780352798&orgId=1&d=300&p=500005&story=780352798&t=podcast&e=780352798&size=4500000&ft=pod&f=500005
When I try to add into this script, I get an error message.
alias: Test
sequence:
- data:
entity_id: media_player.office
media_content_id: >
{{state_attr("sensor.gpodder","podcasts")[0]["episodes"][0]["url"]}}
media_content_type: music
service: media_player.play_media
Error message:
2019-11-17 23:34:00 ERROR (SyncWorker_19) [homeassistant.components.sonos.media_player] Error on play_media with UPnP Error 714 received: Illegal MIME-Type from 10.0.0.105
When I change the state_attr to the URL above it works:
alias: Test
sequence:
- data:
entity_id: media_player.office
media_content_id: "https://play.podtrac.com/npr-500005/edge1.pod.npr.org/anon.npr-mp3/npr/newscasts/2019/11/18/newscast000816.mp3?awCollectionId=500005&awEpisodeId=780352798&orgId=1&d=300&p=500005&story=780352798&t=podcast&e=780352798&size=4500000&ft=pod&f=500005"
media_content_type: music
service: media_player.play_media
nickrout
(Nick Rout)
November 18, 2019, 6:57am
3
Try quotes around the template code?
smoothr
(SmoothR)
November 18, 2019, 12:33pm
4
I have tried single and double quotes around the template code, but that doesn’t work either. I keep getting the same error. I have also tried to put the template code in a systemlog.write service to see what comes out (with multiple variations), and it always looks like the original template code instead of the url. I’m wondering if template code is somehow disabled on scripts?
smoothr
(SmoothR)
November 19, 2019, 2:07pm
5
I figured it out. I had to use data_template: instead of data: … Simple enough but took me several hours to realize.
The UI script editor only uses the latter, so I had to add it manually in the scripts.yaml.
2 Likes
g92847
(g92847)
January 12, 2020, 6:19pm
6
I am having the same problem… I’ve been trying to figure it out for days but nothing is working.
I have a sensor to scrape a page and return a url which is working:
sensor:
- platform: scrape
resource: http://feeds.podtrac.com/zKq6WZZLTlbM
name: podcast_the_daily
select: 'enclosure:nth-of-type(1)'
attribute: url
scan_interval: 900
when I paste this into template:
{{ states.sensor.podcast_the_daily.state }}
it returns:
https://dts.podtrac.com/redirect.mp3/rss.art19.com/episodes/e163ee32-7ae9-453e-a81e-a8c4e60a4c96.mp3
But when I put that sensor into a script, it won’t play.
morning_podcast:
alias: Morning Podcast
sequence:
- service: media_player.play_media
entity_id:
- media_player.livingroom
data_template:
media_content_id: >
{{ states.sensor.podcast_the_daily.state }}
media_content_type: audio/mp3
I’ve checked the logs but I am not getting any sort of error either which is odd. I’ve also tested it by just pasting the media URL directly in there to verify that it works. Any idea what I am doing wrong?
1 Like
nickrout
(Nick Rout)
January 12, 2020, 7:12pm
7
Possibly due to the multiple redirects in the url?
Have you tried the gpodder custom integration?
g92847
(g92847)
January 12, 2020, 7:16pm
8
I have not, but I will give that a try now! Thank you!
smoothr
(SmoothR)
January 13, 2020, 4:40pm
9
Try if passing the URL directly works. I had to change the content type to music before it would start playing (I have Sonos media players).