I have put together my first automation - an event which gets triggered through the API and tunes my media player to a preset radio station. It works fine when there is no templating involved. However, when I introduce a conditional template, it just fails. Nothing in the log.
The code below looks for a value of “radio national” in the event data variable (“station”) and sends the relevant URL to my player if found. Otherwise it sends an alternative URL. According to the conditional logic, at least something should play… but zilch. Once again, if I remove the templated conditional code and hard code in a single URL, it works fine.
Anyone see what might be up with the code below?
alias: "Tune to ... on Squeezebox"
trigger:
platform: event
event_type: squeeze_tuneto
action:
- service: media_player.volume_set
data:
entity_id: media_player.lil_black_box
volume_level: 0
- service: logbook.log
data_template:
name: "Station"
message: "{{ trigger.event.data['station'] }}"
- service: media_player.play_media
data_template:
entity_id: media_player.lil_black_box
media_content_type: "audio/mp3"
media_content_id: >-
{%- if trigger.event.data['station'] == "radio national" %}
"http://opml.radiotime.com/Tune.ashx?id=s20269&formats=ogg,mp3,wma,wmvoice&partnerId=16&serial=a2918f74f5ea42bd33dec6436e682687"
{%- else %}
"http://opml.radiotime.com/Tune.ashx?id=s7018&formats=aac,ogg,mp3,wma,wmvoice&partnerId=16&serial=a2918f74f5ea42bd33dec6436e682687"
{%- endif %}