Value Template for multiple entities

I am trying to create a value template that pulls the media_state attribute from multiple media_player entities. Is this possible? This is what I have in my configuration.yaml file. Ignore the *, but that is essentially what I am trying to achieve.

sensor:
  - platform: template
   sensors:
     song_title:
      friendly_name: "Title"
      value_template: "{{ states.media_player.*****.attributes.media_title }}"

So you want more than one sensor? If the answer to that case is “yes”, then you need to create each one individually.

Well, currently I have 2/4 Google Home devices and setup nfandroidtv to send messages to 2 of my android TVs. I want to setup the other 2 devices, but wondering if there is a way to get the media_title attribute from the media_player entities as a group instead of individually in my automation.yaml file. Hope this makes sense

This is what I have in my automation.yaml file that works for the 2 assistants that are setup:

- id: Assistant_Notification
alias: Media Notification
trigger:
- platform: template
value_template: '{% if is_state(''media_player.livingroom'',''playing'') 
%}true{%endif%}'
- platform: template
  value_template: '{% if is_state(''media_player.office'',''playing'') %}true{%endif%}'
  action:
  - data_template:
  message: "{{ trigger.to_state.attributes.media_artist }} :  {{ 
 trigger.to_state.attributes.media_title\
    \ }} \n"
  title: '{{ trigger.to_state.attributes.friendly_name }} Started Playing'
service: notify.sony
 - data_template:
  message: '{{ trigger.to_state.attributes.media_artist }} :  {{ 
trigger.to_state.attributes.media_title
    }}'
  title: '{{ trigger.to_state.attributes.friendly_name }} Started Playing'
service: notify.sheild
1 Like

This trigger might work in your automation, by replacing all your current triggers:

trigger:
  - platform: template
    value_template: "{% for player in states.media_player if player.state == 'playing' %}true{% endfor %}"

Then you shouldn’t have to do anything. Not sure if you’ll get an error though.

Just tried your suggestion and getting an error:

http://10.10.10.10:8123/frontend_latest/core-aa5473dbea8ac5b75ae0e8239f8e0e38.js:1:6882 Uncaught TypeError: Cannot read property 'attributes' of undefined

Still trying some other things.

Not sure. That doesn’t make sense because you aren’t referencing an attribute… unless player.state accesses an attribute. Typically, when accessing attributes with this method, it would be player.attributes.attr

My fault. I was reloading groups this entire time instead of automations and it works! Thanks for your help.

oh cool! I had no clue if it would work. :joy: