-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
play_media_file_script.yaml
146 lines (130 loc) · 5.02 KB
/
play_media_file_script.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
blueprint:
name: Media Player Script Blueprint 2023-12-09
author: SirGoodenough
description: >
This provides a way to play canned media files with the big
long list of YAML entries but keep the main script or automation clean.
All that is required there would be a simple line like:
'- service: script.media_player_doorbell_sound'
[Community link for this blueprint](https://community.home-assistant.io/t/script-blueprint-to-play-media-player-files-not-an-automation-blueprint/371988)
## 🗿Notice👮🏿♂️:
* Copies of the original Blueprint that were converted via the 'Take Control'
feature or other means are officially not supported by me.
* I may or may not be able to support you when you have a problem after you make changes
to my code, as some of the code is no longer mine.
* I & my license also require attribution as a link back to the original
should you use this code in your own creation.
* [Here is a link to my license & the original github post](https://github.com/SirGoodenough/HA_Blueprints?tab=License-1-ov-file)
expected to be followed & referenced as attribution should you use this code elsewhere.
source_url: https://github.com/SirGoodenough/HA_Blueprints/blob/master/Scripts/play_media_file_script.yaml
domain: script
homeassistant:
min_version: 2023.8.0
input:
speaker_target:
name: Device(s) to send the file to
description: >
Add the media_player that you want to play this on.
You can manually edit this to include multiple media players, or just
use the pick list to pick one.
selector:
entity:
multiple: true
filter:
- domain: media_player
file_2_play:
name: Media File to play
description: >
The file name needs to be put here.
Please include the path that is accessable to the media player.
A sample path may be 'media-source://media_source/local/sample_file.mp3'.
See more information here:
(https://www.home-assistant.io/more-info/local-media/add-media/)
(https://www.home-assistant.io/more-info/local-media/setup-media/)
(https://www.home-assistant.io/integrations/media_source/)
default: "media-source://media_source/local/mp3/Door-chime-sound.mp3"
selector:
text:
media_type:
name: Media_Content_type
description: >
This is where you match how the content is encoded with
how the player will play it. Trial and error here can be your friend
unless you are much better at figuring this stuff out than me.
I generally only use 'audio/mp3' and occasionally 'image/jpg'.
More detailed information available here:
(https://www.home-assistant.io/integrations/cast/)
(https://developers.google.com/cast/docs/media/)
default: "audio/mp3"
selector:
text:
fields:
otf_speaker_target:
name: on-the-fly Device(s) to send the file to
description: Change the default media player on the fly
required: false
example: "media_player.basement_speaker"
selector:
entity:
multiple: true
filter:
domain: media_player
otf_file_2_play:
name: on-the-fly Media File to play
description: This will change the default sound file on-the-fly
required: false
example: "media-source://media_source/local/mp3/Door-chime-sound.mp3"
selector:
text:
multiline: false
type: text
otf_media_type:
name: on-the-fly Media_Content_type
description: This will change the default Media_Content_type on-the-fly
required: false
example: "audio/mp3"
selector:
text:
multiline: false
type: text
variables:
# Get the speaker to select from !input or live data
speaker_target: !input speaker_target
my_speaker: >
{% if otf_speaker_target | default("") %}
{{ otf_speaker_target }}
{% elif speaker_target | default("") %}
{{ speaker_target }}
{% else %}
unknown: No speaker entity provided. play_media_file_script.yaml
{% endif %}
# Get the media file to select from !input or live data
file_2_play: !input file_2_play
my_file_2_play: >
{% if otf_file_2_play | default("") %}
{{ otf_file_2_play }}
{% elif file_2_play | default("") %}
{{ file_2_play }}
{% else %}
unknown: No filename provided. play_media_file_script.yaml
{% endif %}
# Get the media type to select from !input or live data
media_type: !input media_type
my_media_type: >
{% if otf_media_type | default("") %}
{{ otf_media_type }}
{% elif media_type | default("") %}
{{ media_type }}
{% else %}
unknown: No media_type name provided. play_media_file_script.yaml
{% endif %}
sequence:
- alias: Media Player Blueprint Script
service: media_player.play_media
data:
entity_id: "{{my_speaker}}"
media_content_id: "{{my_file_2_play}}"
media_content_type: "{{my_media_type}}"
mode: queued
icon: mdi-music-clef-bass
max: 2