Start party light when playing spotify, but only from one "source"

Hi wonderful community!

I have two mediacenter computers (NUC with windows7 and mediacenter" with spotify installed. They share the same account and in frontend in hass.io I can select which sorce to control. I have two selections “NUCMEDIACENTER_LIVINGROOM” and “NUCMEDIACENTER_KIDSROOM”. Same names as I have named the computers.

I would like to create an automation that cycles random colors on a lamp in the kids room when they play spotify. But not when playing in the living room.
I have the following automation that I am trying to do just that. I have not come that far to test that the action works yet. I need to somehow make a condition using the “source” parameter.
The condition below is obviusly not working… Any ideas?

- alias: "Media player playing"
  trigger:
    - platform: state
      entity_id: media_player.spotify_vardagsrum
      to: 'playing'
      from: 'idle'
  condition:
    - condition: sun
      after: sunset
    - condition: state
      source: "NUCMEDIACENTER_KIDSROOM"
  action:
       service: homeassistant.turn_on
       entity_id: light.light_9
       data:
         brightness: 100
         effect: random

can you please format your code by highlighting it and pressing the </> button. Or you can encapsulate your code in 3 ` (upper left keyboard btn below esc).

Ok, done. So any ideas?

to access attributes inside media players, you need to use template_sensors. I don’t believe there is a condition that allows you to use an attribute as a state condition, I could be wrong though. Either way, the template way to do this is:

- condition: template
  value_template: "{{ media_player.spotify_vardagsrum.attributes.source == 'NUCMEDIACENTER_KIDSROOM' }}"

There are many other ways to do this as well and you will have to single out the media player you don’t want playing. This value template only checks if your current media player is set to NUCMEDIACENTER_KIDSROOM.

Great, thanks! Will try this as soon as I get home.

Hi again.
The condition does not seem to work. If I remove the condition, the light turns on regardless which mediacenter I use. With the condition nothing works. So it is the condtion that is never true.

Any more ideas? I have renamed the mediaplayer since last post.

- alias: "Disco mode on"
  trigger:
    - platform: state
      entity_id: media_player.spotify_mediacenter
      from: 'paused'
      to: 'playing'
  condition:
    - condition: template
      value_template: "{{ media_player.spotify_mediacenter.attributes.source == 'BARNMEDIA-DATOR' }}"
  action:
       service: homeassistant.turn_on
       entity_id: light.switch

- alias: "Disco mode off"
  trigger:
    - platform: state
      entity_id: media_player.spotify_mediacenter
      from: 'playing'
      to: 'paused'
  condition:
    - condition: template
      value_template: "{{ media_player.spotify_mediacenter.attributes.source == 'BARNMEDIA-DATOR' }}"
  action:
       service: homeassistant.turn_off
       entity_id: light.switch

Is your source set to BARNMEDIA-DATOR on your media player?

Yepp.
image

my bad, left out a keyword!

    - condition: template
      value_template: "{{ states.media_player.spotify_mediacenter.attributes.source == 'BARNMEDIA-DATOR' }}"

Success!

Thanks alot!!!