Template sensor help - adding text

Hi all,
Can someone please help me understand how to template the following correctly?

I’m trying too extract the attributes “media_title” and “media_artist” from media_player.bedroom into one template sensor to display: Song - Artist
I can “add” the two attributes together but I am struggling with inserting " - " between the attribute:

sensor:
  #GET ARTIST AND SONG TITLE FROM BEDROOM SONOS MEDIA PLAYER
  - platform: template
    sensors:
      bedroom_now_playing:
        entity_id: media_player.bedroom
        value_template: "{{ (state_attr('media_player.bedroom', 'media_title') + state_attr('media_player.bedroom', 'media_artist')) }}"
        friendly_name: "Bedroom - Now Playing"

The above gives me: SongArtist
I need it to give me: Song - Artist

Appreciate any help

Thanks

Paul

value_template: "{{ (state_attr('media_player.bedroom', 'media_title') + ' - ' + state_attr('media_player.bedroom', 'media_artist')) }}"

1 Like

Many thanks for your prompt help @DavidFW1960

NP! I tripped over my feet for hours over something similar last week before I realised it was staring me in the face!

An update version, that hide None when some is not used.

value_template: >-
  {{ [
    state_attr('media_player.kontor', 'media_playlist'),
    state_attr('media_player.kontor', 'media_channel'),
    state_attr('media_player.kontor', 'media_artist'),
    state_attr('media_player.kontor', 'media_title')
  ] | select("string") | join(' - ') }}