Automation with template not working

Hi

I have the below automation but it’s not working at all. Can anyone please advise why it may not be working?


- id: office_test

  alias: Office Test

  trigger:

  - platform: template

    value_template: "{% if 'News' in state_attr('media_player.sky_q' ,'media_series_title') %}"

  action:

  - service: script.turn_on

    data:

      entity_id: script.officetest

Your value template is incorrect, you have an if there without an else or end if, also and if is not needed in this case at all and you need to curly brackets arpund the template. Change your value template to:

"{{ 'News' in state_attr('media_player.sky_q' ,'media_series_title') }}"

Also you can call a script directly by putting it into the swrvice field, this way you can simply your action to:

action:
  service: script.officetest
1 Like

Worked perfectly. I also noted you changed the {% for {{ so I’ll need to look into what the difference is. I’ve not delved too deep into templating and this was my first attempt.

Thank you for your help.

You’re welcome. Read the templating docs to get started. And to test templates use the template editor found in the sidebar under Developer Tools.

1 Like