I updated the script originally shared to include friendly fields when using the script in your automations.
- Copy the script below.
- Create a new script in HA.
- Go to the … menu and select Edit in YAML.
- Select everything and Paste the script you copied from below.
- Use the “Cast Media…” script as an action in your automations.
alias: Cast Media with no Chime 🔕
sequence:
- choose:
- conditions:
- condition: template
value_template: "{{ is_state(media_file.entity_id,'off') }}"
sequence:
- service: media_player.volume_set
target:
entity_id: "{{ media_file.entity_id }}"
data:
volume_level: 0
- service: media_player.turn_on
target:
entity_id: "{{ media_file.entity_id }}"
data: {}
- if:
- condition: template
value_template: "{{ not is_state(media_file.entity_id, 'idle') }}"
then:
- wait_template: "{{ is_state(media_file.entity_id, 'idle') }}"
timeout: "0:00:05"
- conditions:
- condition: template
value_template: "{{ is_state(media_file.entity_id, 'idle') }}"
sequence: []
- service: media_player.volume_set
target:
entity_id: "{{ media_file.entity_id }}"
data:
volume_level: "{{ volume }}"
- service: media_player.play_media
target:
entity_id: "{{ media_file.entity_id }}"
data:
media_content_id: "{{ media_file.media_content_id }}"
media_content_type: "{{ media_file.media_content_type }}"
mode: single
fields:
media_file:
selector:
media: {}
name: Media File
required: true
volume:
selector:
number:
min: 0
max: 1
step: 0.05
name: Volume
default: 0.5
required: true