Android TV state automation template error

Hi.

I am trying to create an automation to launch different scenes depending on what is playing on my android tv. I use the Android ADB integration to fetch the data. I want to create a longer list of apps with some more elif but this is just a start.

My automation looks like this.

- alias: Android TV Test
  id: '1699904778974'
  description: ''
  trigger:
  - platform: template
    value_template: '{% if is_state(''media_player.android_tv_2'', ''playing'')%}true{%
    endif %}'
  condition: []
  action:
    service: scene.turn_on
    data_template: >-
      {% if is_state_attr("media_player.android_tv_2", "app_name", "Netflix") %}
      scene.test1
      {% elif is_state_attr("media_player.android_tv_2", "app_name", "YouTube") %}
      scene.test2
      {% endif %}

It does not work at all and vscode also throws me an error.

String does not match the pattern of “DEPRECATED^”

I am very new to templating and I can not figure out why this does not work.

Any suggestions?

You don’t need a template trigger, change the teigger to this:

trigger:
  platform: state
  entity_id: media_player.android_tv_2
  to: 'playing'

also data_template: can be changed to data:, and are there other possible apps for the android tv then the two in your automation? You need an else clause there.

Thats a nice solution and also cuts down the automation, but i was specifically looking for something as to triggering depending on the source within 1 automation.

Thanks anyways!

I don’t understand what you mean, my trigger is exactly the same as yours (if it were a correct template).
Also the template in your action is missing entity_id.
Another solution would be a mapper, some thing like this:

trigger:
  platform: state
  entity_id: media_player.android_tv_2
  to: 'playing'
action:
  - variables:
      app: "{{ state_attr('media_player.android_tv_2', 'apo_name') }}"
  - service: scene.turn_on
    data:
      entity_id: >
        {% set map = {
          'Netflix': 'scene.test_1',
          'YouTube': 'scene.test_2'
        } %}
        {{ map[app] }}