OR condition in automation not working

I try to use an OR condition in an automation for my media player.
However it returns an error. Can someone see what is wrong? When I only use one condition without the OR it works fine.

action:
  - service: media_player.select_source
    data_template:
      entity_id: media_player.kkken
      source: '{{ states.input_select.select_radio_ihc.state }}'
  - service: media_player.media_play
  - delay: '00:00:05'
  - condition:
      condition: or
      conditions:
        - condition: template
          value_template: '{{ states.media_player.kkken.attributes.source == "CD" }}'
        - condition: template
          value_template: '{{ states.media_player.kkken.attributes.source == "DVD" }}'
  - service: media_player.volume_up
    data:
      entity_id: media_player.kkken

[homeassistant.components] Invalid config for [automation]: [condition] is an invalid option for [automation]. Check: automation->action->4->condition. (See /home/homeassistant/.homeassistant/configuration.yaml, line 18). Please check the docs at https://home-assistant.io/components/automation/

This is not a condition in the automation, but a condition in the action part of an automation. So it should be:

  - condition: or
    conditions:
      - condition: template
        value_template: '{{ states.media_player.kkken.attributes.source == "CD" }}'
      - condition: template
        value_template: '{{ states.media_player.kkken.attributes.source == "DVD" }}'

Better yet:

  - condition: template
    value_template: >
      {{ states.media_player.kkken.attributes.source == 'CD' or
         states.media_player.kkken.attributes.source == 'DVD' }}

Or even better yet:

  - condition: template
    value_template: "{{ state_attr('media_player.kkken', 'source') in ['CD', 'DVD'] }}"

should have thought about this before!
This seems to be the answer to the issue we discussed here with @NotoriousBDG of phones device_trackers triggering on all attribute changes too, when one uses the platform: state, and to/from: home.

sometimes the obvious stares you in the eyes…
simply add:

value_template: >
  {{ trigger.to_state.state is in ['home', 'not_home'] and
     trigger.to_state.state != trigger.from_state.state }}

or:

  - alias: Send notification when sun changes state
    id: 'Send notification when sun changes state'
    trigger:
      platform: state
      entity_id: sun.sun
    condition:
      - condition: template
        value_template: >
          {{ trigger.to_state.state is in ['above_horizon', 'below_horizon'] and
             trigger.to_state.state != trigger.from_state.state }}
      - condition: state
        entity_id: input_boolean.notify_notify
        state: 'on'
    action:
      service: notify.notify
      data_template:
        message: >
         Sun state change - {{as_timestamp(now()) | timestamp_custom("%X") }} The Sun is 
         {{'up' if is_state('sun.sun','above_horizon') else 'down'}}

:wink:

I will try it out :slight_smile:

I think your issue might have been that there is no trigger defined… I’m not sure there’s anything wrong with the conditions as such…

It now works like a charm :slight_smile: thanks

But it worked fine with only one condition. But after following the change that pnbruckner suggested it Works.