Splitting text out of an entity attribute

I have an entity attribute I currently display for entity: media_player.receiver
attribute: audio_information. It shows:

format: Dolby Atmos
input_frequency: 48 kHz
input_channels: ‘’
listening_mode: Dolby Atmos
output_channels: 7.1.2 ch
output_frequency: ‘’

That’s all from a single attribute. I want to split it out so I can display single attributes like “format” or “listening_mode” How do I extract the correct data out of multiple lines like that?

The value of the attribute audio_information appears to be a dictionary. Copy-paste the following template in to the Template Editor and see if it reports “Dolby Atmos” (or an error message).

{{ state_attr('media_player.receiver', 'audio_information').listening_mode }}

That worked! It returned “Dolby Atmos”. One more question since I haven’t used templates before… how do I get it to update whenever the attribute changes?

Create the following Template Sensor and confirm it always reports the latest value of listening_mode.

template:
  - sensor:
      - name: Listening Mode
        state: "{{ state_attr('media_player.receiver', 'audio_information').listening_mode }}"

Yep, that worked and it updates whenever the mode changes. Thanks a bunch!

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.