Hello. I am working on building a script to use to select a sound, select a google speaker and it then plays that sound on the selected speaker. That logic is working great. What I am having a difficult time with is passing custom metadata. I can successfully pass metadata to my Google HomeHub if I place that bit of code outside of the if statement, but based on my selected ambient sound, I want to pass different metadata, so I think it needs to be included within that if statement. I hope this makes sense.
Here is my code snippet and besides defining the proper MP3 to use for playback, I need to add the “extra” metadata options…
data_template:
entity_id: >
{% if is_state("input_select.google_speaker", "House") %} media_player.house
{% elif is_state("input_select.google_speaker", "Master Bedroom") %} media_player.lennys_speaker
{% elif is_state("input_select.google_speaker", "Office") %} media_player.office_speaker
{% elif is_state("input_select.google_speaker", "Office Display") %} media_player.office_display
{% endif %}
media_content_id: >
{% if is_state("input_select.ambient_mood", "Babbling Brook") %} /media/audio/babbling-brook.mp3
{% elif is_state("input_select.ambient_mood", "Country Nights") %} /media/audio/country-nights.mp3
{% elif is_state("input_select.ambient_mood", "Forest") %} /media/audio/forest.mp3
{% elif is_state("input_select.ambient_mood", "Inward Harmony") %} /media/audio/inward-harmony.mp3
extra:
metadata:
metadataType: 3
title: "Inward Harmony"
artist: "Marcey Hamm"
images:
- url: 'http://192.168.86.10:8123/local/images/inward-harmony.jpg'
{% elif is_state("input_select.ambient_mood", "Ocean") %} /media/audio/ocean.mp3
{% elif is_state("input_select.ambient_mood", "Rainstorm") %} /media/audio/rain.mp3
{% elif is_state("input_select.ambient_mood", "River") %} /media/audio/river.mp3
{% elif is_state("input_select.ambient_mood", "Thunderstorm") %} /media/audio/thunderstorm.mp3
{% endif %}
media_content_type: 'audio/mp3'