How to use service_template

Hi

I am working on a script that will lit the light “light.sovrummet” if “input_select.torsten_status” is set to “not_sleep”.
Its hard to figure out how to use service_template, can someone help me out?

sequence: 
- service: homeassistant.turn_on 
  entity_id: group.grp_windows

- service_template: >
         {% if is_state('input_select.torsten_status', 'not_sleep') %}
           light.turn_on
         {% else %}
           light.turn_off
         {% endif %}
       entity_id: light.sovrummet

Use service_template like you would service. Looks like your entity_id is indented too far - it should be at the same level as service_template. It’s also possible that you’re introducing whitespace with your carriage returns. A minus (-) removes whitespace.

- service_template: >
         {%- if is_state('input_select.torsten_status', 'not_sleep') -%}
           light.turn_on
         {%- else -%}
           light.turn_off
         {%- endif %}
  entity_id: light.sovrummet
5 Likes

Thank you for you response.
I will check that out.

Thanks for this! Lots of thanks!