Unable to get my automation with template to work

I’ve previously had multiple automations set up, one for when the receiver is ON and one for when it’s OFF.
But that makes my coder brain hurt so I wanted to implement a simple if/else condition. But I’m apparently doing something wrong. Help?

Failed config automation: - Invalid config for [automation]: required key not provided @ data[‘trigger’][1][‘platform’].

- action:
  alias: Manage Receiver when casting (LIVINGROOM)
  id: '1521791104221'
  trigger:
  - entity_id: media_player.livingroom
    platform: state
    to: playing
  - service: script.turn_on
    data_template:
      entity_id: >
        {% if is_state('media_player.nad_receiver', 'on') %}
          script.irsend_receiver_key_two
        {% else %}
          script.receiver_startandset_cast
        {% endif %}

Your “action” part is missing an action, because you moved the service call into the “trigger” section. Try this:

- action:
  - service: script.turn_on
    data_template:
      entity_id: >
        {% if is_state('media_player.nad_receiver', 'on') %}
          script.irsend_receiver_key_two
        {% else %}
          script.receiver_startandset_cast
        {% endif %}
  alias: Manage Receiver when casting (LIVINGROOM)
  id: '1521791104221'
  trigger:
  - entity_id: media_player.livingroom
    platform: state
    to: playing
1 Like

I knew there was an easy solution! Thank you :smiley: