Script condition: value_template

I am trying to Power on my TV and launch Plex.
I have a Broadlink to send the IR codes, and they work (even the wait_template).

I don’t want the script to execute if either of two media players already has a state of ‘playing’. (It’s a roku tv, and discovery enumerates them differently each time. Sometimes the Roku is media_player.tvliving and Plex is media_player.tvliving_2. Other times they’re reversed, so I need to check both).

My condition, however, throws: ERROR (MainThread) [homeassistant.bootstrap] Invalid config for [script]: [condition] is an invalid option for [script]. Check: script->script->tv_plex->sequence->0->condition.

I’ve tried many variations of syntax with no success. Please help?

script:
  tv_plex:
    sequence:
      - condition:
        - platform: template
          value_template: >
            {% if is_state('media_player.tvliving', 'playing') %}
              false
            {% elif is_state('media_player.tvliving_2', 'playing') %}
              false
            {% else %}
              true
            {% endif %}
      - service: broadlink.send_packet_192_168_3_80
        data:
          packet:
            - "JgBQAAABK5MSExI4EjgSExITEhQRFBE5ETkRFBE5ERQRFBEUERQRFBE5ETkRORE5ERQRFBEUERQSExITEhMSExI4EjgSOBI4EgAFngABKUoSAA0FAAAAAAAAAAA="
      - wait_template: "{{ states.device_tracker.hostone.state == 'home' }}"
        timeout: 00:00:30
      - delay: 00:00:04
      - service: broadlink.send_packet_192_168_3_80
        data:
          packet:
            - "JgBQAAABKZUSExI4EjgSExITEhMSExQ2EjgSExQ2EhMSFBEUERQRFBEUERQTNxEUETkRFBEUERQRORE5ExIROREUETkSOBI4EgAFnQABKUsTAA0FAAAAAAAAAAA="
            - "JgBQAAABKZUSExI4EjgSExITEhMSExQ2EjgSExQ2EhMSFBEUERQRFBEUERQTNxEUETkRFBEUERQRORE5ExIROREUETkSOBI4EgAFnQABKUsTAA0FAAAAAAAAAAA="
            - "JgBQAAABKZUTEhI4EjgSExITExISFBE5ETkRFBE5ERQRFBEUERQSExA6ERQROREUETkRFBEUERQRFBE5ERQRORMSEjgTNxM3EgAFngABKEsTAA0FAAAAAAAAAAA="
            - "JgBQAAABKZUSExE5ETkSExEUERQRFBE5ETkSExE5EhMSExITEhMSExITEhMTEhI4EzcTEhIUERQRORI4EDoRFBEUETkSOBE5EQAFngABKEwSAA0FAAAAAAAAAAA="
1 Like

I think you’re close, but have the syntax wrong for conditions.

- condition: template
  value_template: >
    {% if is_state('media_player.tvliving', 'playing') %}
      false
    {% elif is_state('media_player.tvliving2', 'playing') %}
      false
    {% else %}
      true
    {% endif %}

THANK YOU! It is working now.

One note, though: when it stops due to the condition being false, the control toggle on the tile remains on, whereas in all other cases, it returns to off once complete. Is that normal behavior?

This is working:

tv_plex:
  sequence:
    - condition: template
      value_template: >
        {% if is_state('media_player.tvliving', 'playing') %}
          false
        {% elif is_state('media_player.tvliving_2', 'playing') %}
          false
        {% else %}
          true
        {% endif %}
    - service: broadlink.send_packet_192_168_3_80
      data:
        packet:
          - "JgBQAAABK5MSExI4EjgSExITEhQRFBE5ETkRFBE5ERQRFBEUERQRFBE5ETkRORE5ERQRFBEUERQSExITEhMSExI4EjgSOBI4EgAFngABKUoSAA0FAAAAAAAAAAA="
    - wait_template: "{{ states.device_tracker.hostone.state == 'home' }}"
      timeout: 00:00:30
    - delay: 00:00:04
    - service: broadlink.send_packet_192_168_3_80
      data:
        packet:
          - "JgBQAAABKZUSExI4EjgSExITEhMSExQ2EjgSExQ2EhMSFBEUERQRFBEUERQTNxEUETkRFBEUERQRORE5ExIROREUETkSOBI4EgAFnQABKUsTAA0FAAAAAAAAAAA="
          - "JgBQAAABKZUSExI4EjgSExITEhMSExQ2EjgSExQ2EhMSFBEUERQRFBEUERQTNxEUETkRFBEUERQRORE5ExIROREUETkSOBI4EgAFnQABKUsTAA0FAAAAAAAAAAA="
          - "JgBQAAABKZUTEhI4EjgSExITExISFBE5ETkRFBE5ERQRFBEUERQSExA6ERQROREUETkRFBEUERQRFBE5ERQRORMSEjgTNxM3EgAFngABKEsTAA0FAAAAAAAAAAA="
          - "JgBQAAABKZUSExE5ETkSExEUERQRFBE5ETkSExE5EhMSExITEhMSExITEhMTEhI4EzcTEhIUERQRORI4EDoRFBEUETkSOBE5EQAFngABKEwSAA0FAAAAAAAAAAA="

Not sure. Scripts usually only get the toggle when they involve a delay, right? Maybe wait_template triggers the same functionality? Dunno - you’ve got both.

I don’t know; it’s my first script. I just assumed they showed as on while running and off when complete.

If they don’t include a delay, they typically just present the word “ACTIVATE”. Clicking on that runs the script.

Just tested to confirm: the presence of either delay or wait_template changes the tile display from activate to a toggle.

Yeah, thats how they all are. If its just a quick action its just an activate button, if there is a delay itll be a toggle switch thing