I tried to create an automation: play music in the morning, music files was store in /local/morning. There are 4 songs, and I want to play all songs.
Here is automation code:
- id: '156823816799'
alias: morning
description: New day
trigger:
- at: 06:30:00
platform: time
condition:
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
- sat
action:
- data:
volume_level: 0.3
entity_id: media_player.master_room
service: media_player.volume_set
- service: script.play_musics_in_list
data:
hass_url: "https://xxx.duckdns.org"
file: >-
{%- set files = states.sensor.morning.attributes.file_list-%}
{%- set files = files|replace('/config/www/','')|replace('[','')|replace(']','')%}
{%- set files = files.replace('\'','').replace(', ',',') %}
{%- set files = files.split(',')-%}
{{files}}
number_of_files: "{{states.sensor.morning.attributes.number_of_files"
And here is script code:
play_musics_in_list:
alias: Play music in list
mode: restart
sequence:
- service: media_player.clear_playlist
entity_id: media_player.master_room
- repeat:
while:
- condition: template
value_template: "{{repeat.index <= number_of_files}}"
sequence:
- wait_template: "{{ is_state('media_player.master_room', 'paused') }}"
- delay: "00:00:02"
- service: media_player.play_media
entity_id: media_player.master_room
data_template:
entity_id: media_player.master_room
media_content_id: "{{hass_url}}/local/{{file[repeat.index]}}"
media_content_type: music
But when I tried to excute automation “morning”, just volume of speaker was set to 0.3.