the script that creates the randomisation works great as you describe it , but with independent buttons that call the script, depending on the folder that is played. in my script, i am searching to use one button to play th random list, with before choosing the folder which will play, using radio buttons(i succeeded in defining these radio buttons). so, in my script i cannot call another script (or can i?) so i have to put the randomisation sequence somehow in the script i sent. is that possible?
What I would try at first, is to has an array for each subfolder, and an array of array for filelist of each subfolder. The first level of the latter would be the position of the subfolder. For example, if you select the third subfolder, this will point to the third array in the array of arrays.
i am looking on having the folders that will be accessed on the same levelā¦so no subfolder structure, which i already have in place. the only thing issing is for the same button to randomise the folder that is chosen via the radio buttons.
SOrry I didnāt get your point. What are you try to randomize, the file or the folder itself (in the latter case, isnāt it selected by the radiobutton)? If it is the file, this is done through the '{{ state_attr(''sensor.media'', ''file_list'')|random }}'
in the ālancement musiqueā script I gave. Good luck for your development and thanks for sharing!
I am trying to randomise the files in folders. if i call lancement musique script, the music should play from a folder. if i call another script the music should play from another folder. the current format allows me to do the above mentioned actions only if i press the stop button when switching from one script to the other. what i wanted was to be able to switch automatically the folder when the oppsite script than the one active was called.
thank You so much for Your time and explanations. it has been a great experience for me exchanging on this project. please continue developing it as it is a great idea you have with this project. Thank You again.
Thanks a lot for your kind feedback!
I understand your point now. Indeed, the music will change only at the next track. But what you can probably do when hitting the button to change the folder is to call the arret_musique
script which will stop the music, then update the folder if necessary, and then call the lancement_musique
. This will automate the process of stopping and launching again.
Thanks again for your support and great ideas!
Mick
Hello. i just wanted to share with You the use of Your principles in my tileboard dashboard. it warks flawlessly: radio button for selection of the folder/url link for online radio; play button randomising the selected music folder. perfect work. thank You
!
Yeah, really nice! Thanks a lot for sharing It has been a great pleasure discussing with you about this really cool development and great enhancement!
Hey, this looks great.
Can you please share the scripts and the code for the cards that make it all work per folder selection?
I have a question, if you could spare the time.
I tried reproducing your scripts and automation - and it worked beautifully. So thank you so much for sharing it with us, newbies
However, when I tried changing the path to config/www/media/jazz, I get an error in the log saying that it canāt reach the āconfig/www/media/jazz/Songsā
Iām not sure about the meaning of this. I changed the path of the sensor and the script, Iāve updated the āliste[18:]ā part to cut out the path I determined and the script does locate a random song from the right path - but the script that plays the song adds ā/Songsā to any inner path inside ā/media/ā.
When I tried creating ā/Songsā inside ā/media/ā and put some songs in there plus updating the path everywhere - it adds another /Songs and the error I get is that āconfig/www/media/jazz/Songs/Songsā might not be publicly available. and of course this path simply doesnāt exist.
I would imagine this new addition to the path comes from the āpiste: <DEFAULT FILE>
ā syntax, but I couldnāt find any documentation regarding this.
Can you please provide some guidance?
hello, plese find here bellow my configuration. please note that the interface is not the lovleace provided by HA but ātileboardā, an alternative to lovelace:
config.yaml
homeassitant
media_dirs:
media: /config/www/media
sensor:
- platform: folder
folder: /config/www/media/folder_muzica1
- platform: folder
folder: /config/www/media/folder_muzica2
input_boolean:
folder_muzica1:
name: folder_muzica1
icon: mdi:music-box
initial: true
folder_muzica2:
name: folder_muzica2
icon: mdi:music-box
initial: false
automations.yaml
#radio buttons
alias: Music Mode set
trigger:
- platform: state
entity_id: input_boolean.folder_muzica1, input_boolean.folder_muzica2, input_boolean.folder_muzica3,
input_boolean.radio_impuls, input_boolean.90s_radio, input_boolean.radio_renasterea
to: 'on'
action:
- service: input_boolean.turn_off
data_template:
entity_id: '{% set booleans = [ ''input_boolean.folder_muzica1'', ''input_boolean.folder_muzica2'',"input_boolean.radio_impuls","input_boolean.90s_radio",
"input_boolean.radio_renasterea", "input_boolean.folder_muzica3" ] | reject(''equalto'',
trigger.entity_id) %} {{ booleans | list | join('', '') }}'
mode: single
#play random selected music folder
alias: Melodia_urmatoare
description: ''
trigger:
- platform: state
entity_id: media_player.borsa_mini
from: play
to: idle
condition: []
action:
- choose:
- conditions:
- condition: state
entity_id: input_boolean.folder_muzica1
state: 'on'
sequence:
- event: script.muzica_folder1
event_data: {}
- conditions:
- condition: state
entity_id: input_boolean.folder_muzica2
state: 'on'
sequence:
- event: script.folder_muzica2
event_data: {}
- conditions:
- condition: state
entity_id: input_boolean.folder_muzica3
state: 'on'
sequence:
- event: script.folder_muzica3
event_data: {}
- conditions:
- condition: state
entity_id: input_boolean.radio_impuls
state: 'on'
sequence:
- event: script.radio_impuls
event_data: {}
- conditions:
- condition: state
entity_id: input_boolean.90s_radio
state: 'on'
sequence:
- event: script.90s_radio
event_data: {}
- conditions:
- condition: state
entity_id: input_boolean.radio_renasterea
state: 'on'
sequence:
- event: script.radio_renasterea
event_data: {}
default: []
mode: single
scripts.yaml
# this you already have; i would avise to name the folders the same and indexing 01, 02... that way the media content id format does not change for 100 folders that can be shaed. the name of the folder can be defined on the radio button level
#PLAY RANDOM FOLDER MUZICA1
folder_muzica1:
alias: Folder_muzica1
sequence:
- service: script.citire_folder_muzica1
data:
#corecteaza numarul in functie de numarul de caractere al caii catre folder
track: '{{ media_content_id[33:] }}'
mode: single
icon: mdi:music
variables:
media_content_id: '{{ state_attr(''sensor.folder_muzica1'', ''file_list'')|random }}'
#PREGATIRE FOLDER MUZICA1
citire_folder_muzica1:
alias: Citire_folder_muzica1
sequence:
- service: media_player.play_media
data:
media_content_id: http://192.168.33.163:8123/local/media/folder_muzica1/{{ track }}
media_content_type: audio/mp3
entity_id: '{{ player }}'
mode: single
icon: mdi:music
variables:
track: <DEFAULT FILE>
player: media_player.borsa_mini
#PLAY RANDOM FOLDER MUZICA2
folder_muzica2:
alias: Folder_muzica2
sequence:
- service: script.citire_folder_muzica2
data:
#corecteaza numarul in functie de numarul de caractere al caii catre folder
track: '{{ media_content_id[33:] }}'
mode: single
icon: mdi:music
variables:
media_content_id: '{{ state_attr(''sensor.folder_muzica2'', ''file_list'')|random }}'
#PREGATIRE FOLDER MUZICA2
citire_folder_muzica2:
alias: Citire_folder_muzica2
sequence:
- service: media_player.play_media
data:
media_content_id: http://192.168.33.163:8123/local/media/folder_muzica2/{{ track }}
media_content_type: audio/mp3
entity_id: '{{ player }}'
mode: single
icon: mdi:music
variables:
track: <DEFAULT FILE>
player: media_player.borsa_mini
#script for the play/random button(script) to play from the selected folder by the radio button
buton_play:
alias: buton_play
sequence:
- service: >
{% if is_state("input_boolean.folder_muzica1", "on" ) %} script.folder_muzica1
{% elif is_state("input_boolean.folder_muzica2", "on" ) %} script.folder_muzica2
{% elif is_state("input_boolean.folder_muzica3", "on" ) %} script.folder_muzica3
{% elif is_state("input_boolean.radio_impuls", "on" ) %} script.radio_impuls
{% elif is_state("input_boolean.90s_radio", "on" ) %} script.90s_radio
{% elif is_state("input_boolean.radio_renasterea", "on" ) %} script.radio_renasterea
{% endif %}
data_template:
entity_id: media_player.borsa_mini
media_content_type: audio
mode: single
that should be itā¦
Thank you so much!
I will try to implement this into my setup and see how I can use lovelace, maybe with a dropdown.
I saw your comment about naming the folders, but Iām still having problems with changing the path where the folders will reside. Thanks again
You do not need a dropdown in lovelace. You need an entities group inwhich you put the booleans. The automation does the magic of switching of all the others when one is chosen.
If you want a dropdown list then you will need to define the content of that list into input.select.yaml
As for the folder names, please check that the media dirs are defined once up to the media level. The sensors for the folders will then be giving the path to each folder independently.
I hope it helps.