Trigger automation depending on denon source

I use the state of the TV to dim the lighting. Unfortunately this is not very reliable. The status of the TV is regularly set to ‘off’ while it is on. Because the status of the denon receiver is correct, I want to use that as trigger. Just somehow it doesn’t work. Anyone any idea.

value_template: "{{ states.media_player.denon_avr_x1200w.attributes.source }}"

{% if is_state('media_player.denon_avr_x1200w.attributes.source', 'TV Audio') %} 
            script.dim
          {% else %}
            script.normaal
          {% endif %}   

And the output of the template
image

{% if is_state_attr('media_player.denon_avr_x1200w', 'source', 'TV Audio') %}
  script.dim
{% else %}
  script.normaal
{% endif %}

Yes, that works. Thank you mf_social.
I always find it very confusing when I need to use states, is_state or is_state_attr

1 Like

states(‘light.bob’) = the current state of light bob (on, off, unavailable etc)

is_state(‘light.bob’, ‘on’) = true if light bob is on, false if not.

is_state_attr(‘light.bob’, ‘brightness_pct’, 100) = true if light bob’s brightness percentage attribute is currently 100, false for any other value.

Hope this helps.

1 Like

Thanks for the explanation

1 Like

The automation to turn on the light when it is dark works. If the TV is already on then the light will be switch on dimmed and if the TV is off it switch on normally.
Now only the trigger for when the light is already on and the TV is turned on or off. The following will pass the check, but when I reload the automation I get an error message.

- alias: "Media player playing TV Audio"
  trigger:
  - platform: state
    entity_id: media_player.denon_avr_x1200w.source
    attribute: source
    to: 'TV Audio'
  condition:
  - condition: state
    entity_id: timer.hold_when_off
    state: 'idle'
  - condition: state
    entity_id: timer.timer_program_hold
    state: 'idle'    
  - condition: state
    entity_id: switch.schemerschakelaar
    state: 'on'
  - condition: time
    after: '16:00'
    before: '23:59'
  action:
      service: homeassistant.turn_on
      entity_id: switch.dim

The last two lines aren’t correctly indented.

What’s the error message?

Invalid config

The following integrations and platforms could not be set up:

  • automation

Please check your config.

The entity_id was wrong.
must be: ‘entity_id: media_player.denon_avr_x1200w’ without ‘source’

1 Like