Automation trigger on device attributes?

Hi All,

I have a Marantz amp set up, but I would like to trigger an automation (to adjust it’s volume) based on the source it’s playing.

I know it’s a very basic question, but I’m tearing my hair out trying to find the answer. I’ve been playing around for a few months and have the hang of automating most of the house, but I’m stuck on one fundamental. I also can’t work out the right terminology to search for an answer, so I thought I’d give up and ask.

In device manager I can see a bunch of ‘variables’ for the device, and I’d like to trigger on the current source. I have automations on the ‘state’ but need the next layer down. What is the correct way to reference these ‘variables’?

I tried using media_player.marantz_sr5008_source and media_player.marantz_sr5008|source for the device name to reference (approaches I found in random unverified code snippets online) but with no luck.

I’e seen some examples of setting up a separate variable for these attributes in the config and then referencing that. Is that what I should be doing, or is there a way to do it directly from the device variables using templates or similar?

Entity
media_player.marantz_sr5008
 
State
on

source_list:
  - <list>
sound_mode_list:
  - <list>
volume_level: 0.22
is_volume_muted: false
media_content_type: channel
media_title: LMS
source: LMS
sound_mode: STEREO
sound_mode_raw: STEREO
friendly_name: Marantz_sr5008
supported_features: 69004

You need to use template trigger with source as attribute, similar to the following:

- alias: 'Adjust volume'
  id: '01'
  trigger:
    - platform: template
      value_template: "{{ is_state_attr('media_player.marantz_sr5008', 'source, 'LMS') }}"
1 Like

You sir are a legend. This is already helping me streamline all of my automations as this was one example of many where I couldn’t work out the attribute format. Thank you.

For any one who stumbles on this thread in the future, my ultimate solution finished up as the below. Note: The True/False sections allow me to trigger it for changing source away from “LMS” rather than onto it.

- id: '1590613481040'
  alias: Marantz Volume down when turning off LMS
  description: ''
  trigger:
    platform: template
    value_template: >
      {% if is_state_attr('media_player.marantz_sr5008', 'source', 'LMS') %}
      false
      {% else %}
      true
      {% endif %}
  condition: []
  action:
  - data:
      entity_id: media_player.marantz_sr5008
      volume_level: '0.22'
    entity_id: media_player.marantz_sr5008
    service: media_player.volume_set

FWIW, this is slightly more compact:

    value_template: >
      {{ not is_state_attr('media_player.marantz_sr5008', 'source', 'LMS') }}

Thanks. I did see the not command was being updated in the recent release notes but wasn’t brave enough to give it a go :slight_smile:

You’re welcome.

The Jinja2 not operator has been around forever. It has nothing to do with:

condition: not
conditions:
...

I feel like I really should have a better handle on the automations side of things after 4 months using this… that will teach me for spending my time making a pretty floor map front end, and flashing sonoff switches, to visually convince the wife this automation is a good idea :).