Solidity
(Arnaud Cresp)
February 26, 2023, 9:02am
1
Hello,
I use this part of code to select a webradio in an action.
But as the list is short, there is often multiple time the same source.
I’d like to select the radio one by one following.
How can I adjust the syntax ?
Thanks for your help !
service: media_player.play_media
data_template:
entity_id: media_player.audiobureau
media_content_id: >
{{ ["http://strm112.1.fm/ajazz_mobile_mp3",
"https://radios.rtbf.be/classic21-128.mp3",
"https://radios.rtbf.be/laprem1ere-64.aac",
"http://icecast.vrtcdn.be/stubru-high.mp3",
"http://stream.funradio.sk:8000/fun128.mp3",
"http://belrtl.ice.infomaniak.ch/belrtl-mp3-192.mp3"] | random }}
media_content_type: audio/mpeg
Solidity
(Arnaud Cresp)
February 26, 2023, 10:22am
2
I modified my code to exclude the current playing radio. I think it’s the best solution.
service: media_player.play_media
data_template:
entity_id: media_player.audiobureau
media_content_id: >
{% set current_radio = state_attr('media_player.audiobureau', 'media_title') %}
{% set radios = ["http://strm112.1.fm/ajazz_mobile_mp3",
"https://radios.rtbf.be/classic21-128.mp3",
"https://radios.rtbf.be/laprem1ere-64.aac",
"http://icecast.vrtcdn.be/stubru-high.mp3",
"http://stream.funradio.sk:8000/fun128.mp3",
"http://belrtl.ice.infomaniak.ch/belrtl-mp3-192.mp3"] %}
{% set available_radios = radios | reject('equalto', current_radio) | list %}
{{ available_radios | random }}
media_content_type: audio/mpeg
finity
February 26, 2023, 6:18pm
3
I helped someone else with a similar request a while back.
it might help you in your situation:
What I currently have is a script that, when called, picks a playlist randomly from a list of playlists (called by name) and plays this playlist on our Sonos.
What I’d like is to extend this so that it cycles through the list of playlists and resets.
So it selects a random playlist from the list of playlists, removes it from that list so that next time it can’t pick it anymore, until the list is empty and then it resets the list to the original contents minus the just selected playlist.
My co…