Automation Help (state attribute)

Hi,

I am just trying to get a couple of my hue lights to turn blue when I launch Modern Warfare on the Playstation.

Here is the automation:

- id: '1594226957930'
  alias: 'MW Lights '
  description: ''
  trigger:
  - entity_id: media_player.playstation_4
    from: idle
    platform: state
    to: playing
  condition:
  - condition: state
    entity_id: media_player.playstation_4
    state: '{{ state_attr(''media_player.playstation_4'', ''source'', ''Call of Duty®:
      Modern Warfare®'')}}'
  action:
  - data:
      rgb_color:
      - 0
      - 98
      - 255
    entity_id: light.tv_backlight, light.tv_unit
    service: light.turn_on

Not sure if I’m handling the state attribute correctly?

I am using the “source:”

Does this automation look correct?

TIA

Try:

  condition:
    - condition: template
      value_template: "{{ state_attr('media_player.playstation_4', 'source') == 'Call of Duty®:
      Modern Warfare®' }}"
2 Likes

That’s done it, many thanks.

Welcome anytime! :slight_smile:

Also you could have changed state_attr to is_state_attr.

1 Like

Yep, even better, thanks!