Hi, I have a sensor that randomly extracts a single music file from a local folder.
I would like to associate a cover for each file and to do this I created two other sensors to have the file synchronized with the cover.
These are my sensors:
- platform: folder
folder: "/config/www/musica/studioghibli/"
- platform: template
sensors:
file_studioghibli:
value_template: >
{{ state_attr('sensor.studioghibli', 'file_list') |random |regex_replace(find='config/www', replace='local',
ignorecase=False) }}
- platform: template
sensors:
cover_studioghibli:
value_template: >
{{ states('sensor.file_studioghibli') |regex_replace(find='mp3', replace='png', ignorecase=False) }}
This is the result:
I want to play on my google home these files and I tried to do it with this script, but it doesn’t work:
suona_musica_studioghibli:
sequence:
repeat:
count: 27
sequence:
- service: media_player.turn_on
target:
device_id: 38b7837d52b074699c7d1c490d0757e8
- service: media_player.play_media
data_template:
entity_id: media_player.salotto
media_content_type: audio/mp3
media_content_id: >
'{{ states(sensor.file_studioghibli) }}'
extra:
thumb: >
'{{ states(sensor.cover_studioghibli) }}'
title: 'Studio Ghibli' #'{{((state_attr("media_player.salotto", "media_title")))}}'
- delay:
hours: 0
minutes: 0
seconds: 11
milliseconds: 0
- wait_template: '{{ is_state(''media_player.salotto'', ''idle'') }}'
Is there a correct way to make the script work?
thank you