This is a SCRIPT Blueprint. 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.
2022-04-11: Add multiple to Speaker Selection and changed minimum HA to 2022.4.0
2021-12-28: First blueprint version
I decided I wanted to clean up a bunch of my automations by removing the several lines of YAML every time I wanted to play an mp3 file. In addition to that, playing specific sound files and other things becomes a simple call to a script file, so really a function. The actual meat and potatoes of the function is exactly the same for all the sounders and if a change needs to be made, it only has to be made in 1 place in a multiple re-use scenario.
Option 1: My Home Assistant
Click the badge to import this Blueprint
Please Click the at the end of the Post if you find this Useful
Option 2: Direct Link
Copy this link if you want to import the blueprint in your installation. https://github.com/SirGoodenough/HA_Blueprints/blob/master/Scripts/play_media_file_script.yaml
First, let’s go over Blueprints and what they are. Blueprints are a way to share scripts (in this case) and is built into Home Assistant. Simple as that. You can import my template code and a copy of it will reside in your configuration. Once there, you can can edit it (if you need changes only) or you can call up that Blueprint to build a script. It will collect the information needed based on your entities and your personal adjustments, and provide a working script. You will have to have or add the required hardware and entities that the Blueprint needs to function.
Open Home Assistant with administrator privileges and on a Lovelace screen, click anywhere in the main entity area and type the letter ‘c’. A selection box should pop up. Type blue and select the button to navigate to blueprints. You can also find blueprints by selecting configuration from the left menu and then blueprints from the center menu.
Once there, click on the ‘Import Blueprint’ button in the lower right side of the main screen.
In the ‘URL of the blueprint’ line type or paste in the URL of my Blueprint. I have the blueprint stored on my Public REPO on GitHub:
Once you have the entities created or decided upon you can build the Automation.
To build the script:
Click on ‘Create Script’ and ‘Use Blueprint’
Add a Description so you can tell what this one is for
Use the Drop-downs to select the Entities for the listed purposes
The media_player field will pull from a pick list but you can extend that with multiple media_players or groups as needed by typing them in. Use the links above to help get your system able to play media files.
The media type 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 in the Google Developers link above.