I am trying to provide a basic dashboard for our SONOS speakers.
I have followed the excellent video from Smart Home Junkie, https://www.youtube.com/watch?v=ksBxcRgPo_
I am planning to just use a few radio stations and have a grid card that uses the custom-button card to switch between them. That works fine. However, what I would also like to do is highlight the button of the radio station that is active.
One station is BBC radio 2 which I can trigger with:-
media_content_id: media-source://radio_browser/b8006996-10de-4369-8565-85cce4426879
Using the template editor with the following:-
{% set station = states ['media_player.kitchen_play3'].attributes.media_content_id %}
{{station}}
I get the result:-
So I tried to set the button ‘green’ when the station is active and grey if not using the following:-
card:
- background-color: |
[[[
if (states ['media_player.kitchen_play3'].attributes.media_content_id === 'hls-radio://http://as-hls-ww-live.akamaized.net/pool_904/live/ww/bbc_radio_two/bbc_radio_two.isml/bbc_radio_two-audio%3d96000.norewind.m3u8')
return 'green'
else
return 'grey';
]]]
However, the function always sets the button ‘green’ no matter what station i have picked. I guess the logic of the if statement is wrong, but I cant work out why? Any help will be gratefully received, even if it is to say I am a complete numb scull.
The full yaml of one button to play BBC Radio 2 that I am using is:-
type: custom:button-card
entity: media_player.kitchen_play3
tap_action:
action: call-service
service: media_player.play_media
target:
entity_id: media_player.kitchen_play3
data:
media_content_id: media-source://radio_browser/b8006996-10de-4369-8565-85cce4426879
enqueue: replace
media_content_type: music
entity_picture: /local/Radio/radio2.jpeg
show_entity_picture: true
name: Radio 2
show_name: true
styles:
card:
- background-color: |
[[[
if (states ['media_player.kitchen_play3'].attributes.media_content_id === 'hls-radio://http://as-hls-ww-live.akamaized.net/pool_904/live/ww/bbc_radio_two/bbc_radio_two.isml/bbc_radio_two-audio%3d96000.norewind.m3u8')
return 'green'
else
return 'grey';
]]]