Automation trigger - Media Player - trigger.to_state.attributes

Hello,

I’m trying to create an automation trigger when my media player “is_voume_muted = true”

I tried this so far…

- id: '1552854853963'
  alias: Main Floor Mute triggered by Onkyo
  trigger:
  - platform: state
    entity_id: media_player.main
  condition:
  - condition: template
    value_template: '{{ trigger.to_state.attributes.is_volume_muted == "true" }}'
  action:
  - data:
      entity_id: input_boolean.main_floor_mute
    service: input_boolean.turn_on  

Any help would be greatly appreciated! Thanks.

Use a Template Trigger.

  trigger:
  - platform: template
    value_template: "{{ is_state_attr('media_player.main', 'is_volume_muted', 'true') }}

Disclaimer:
I’m not familiar with the media_player component so I’m making an assumption that the attribute’s name and state, as you’ve described them, are correct.

thanks for the suggestion. but when i try that nothing happens…same as my original code. I’ve tried a couple different media players with no luck. Nothing shows up in the logs either.

Go to Home Assistant’s States page and get a screenshot of media_player.main and all its attributes. Post the image here so we can review it. The problem may be due to the choice of the attribute’s state.

image

Thanks, that gives me a clue.

The attribute’s state should not be delimited by quotes because it’s a boolean value (not a string). Change 'true' to true

  trigger:
  - platform: template
    value_template: "{{ is_state_attr('media_player.main', 'is_volume_muted', true) }}"

EDIT
Corrected the template. Added missing " at the end of the template.

1 Like

That worked! Thank you!

I just had to add " at the end

  trigger:
  - platform: template
    value_template: "{{ is_state_attr('media_player.main', 'is_volume_muted', true) }}"