Template not working within automation

I have an automation which checks for a template in If clause. When I test the template in Developer Tools, it returns True. But, when the template condition is tested with the automation, it returns False. I am confused as to why this would happen.

if:
  - condition: template
    value_template: >-
      value_template: "{{ state_attr('media_player.bedroom_tv', 'app_name') !=
      'Plex'}}"
then:
  - action: script.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: script.dell_xps_9000_positive_hibernate

The automation is failing to run the action since If returns False. When the automation fails to run the action, I immediately tested the template in Developer Tools and it returns True. Any ideas?

Thanks…

You have twice value_template

As stated above, the main issue is the doubled value_template, but the template is also using both a block scalar identifier and quotes which will also cause issues. Use one or the other, not both.

FWIW, you could also use a not with is_state_attr():

if:
  - condition: template
    value_template: "{{ not is_state_attr('media_player.bedroom_tv', 'app_name', 'Plex') }}"
then:
  - action: script.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: script.dell_xps_9000_positive_hibernate
1 Like

Thanks vingerha for responding so quickly. Yes, value_template was the problem.

Thanks Didgeridrew. Your simplified construct worked well.