Automation - Templating does stop automation

All, I need help with my automations.
Basically I wrote a “Wake-Up Scene” in automations.
One of the steps is that - when I enter the living room the light turns on, but only when the sun is still under the horizon.
After this step, other steps are, e.g. letting me know when I need to leave for work.

The complete automation works as long as the sun is still under the horizon and thus needs to switch on the light.
But the moment the sun is already above horizon and the light does not need to switch on, the light does not switch on, but also all subsequent steps in the automation are stopped.

Below is the part of the automation that gives me issues:

- service_template: >
    {% if states.sun.sun.state == "below_horizon" %}
      switch.turn_on
    {% endif %}
  data:
    entity_id:
      - switch.kitchen_ceiling_67

I also tried below - with same issue:

 - service: switch.turn_on
   data_template: 
     entity_id: >
       {% if states.sun.sun.state == "below_horizon" %}
         - switch.kitchen_ceiling_67
       {% endif %}

Come on man, you’ve been a member of this forum for nearly 3 years. Format your code.

tom,

Any other input ??

Not until it’s formatted correctly :slight_smile:

Also the rest of your actions would help too.

You can’t use service_template with a template that results in nothing. The template must result in the name of a valid service, otherwise it will cause an error and the script (or automation actions) will abort.

One way to achieve this is to define a script that does “nothing.” Then call that when you don’t want the service_template to “do” anything.

hi pnbruckner,

Thanks for your input!
I didn’t know that.

Would there be another work around - so I don’t have to work with a "fake script?

Thanks!

I can think of a few, but it depends on overall what your script is doing, your preferences, etc.

E.g., you could turn the light off when the sun is above the horizon, but that may not be appropriate.

You could move this step to the end of the script and precede it with a condition step (instead of using a service_template), but that depends on whether or not you can rearrange the sequence.

You could call another script that has a condition step and a service call instead of using the service_template.

There may be others…

EDIT: You could use a python_script, which is more flexible, instead of a script for the entire sequence