In the future please just post your actual automation/script, instead of one filled with dummy information.
You are trying to use variables in the data section that aren’t defined for that section. You need to either add them to that section or move them so they are available to the whole sequence. (Variable Scope)
data_template and service_template are deprecated, just use data and service.
In most cases the output of a template is a string, so converting them to strings likely isn’t necessary. I’m leaving them in the example below, because there are too many “dummies” to guess about…
Because you cannot use a Jinja2 template to generate YAML. In data, a Jinja2 template uses an if-else to determine the appearance of the entity_id and/or color_temp options (which is YAML). That’s an invalid operation and is the reason for the error message.
You need to restructure this script to use a choose.
Sorry about that, in my haste I didn’t properly change the data section… Anyway, do what Taras said and use a Choose action.
The only part that needs special treatment is light.turn_on because you want to vary the color_temp. Everything else will work with the generic homeassistant.turn_on/off so use that for the default instead of writing so many “elses”.
sequence:
- variables:
name: 'light.led'
state: 'ein'
entity: '{{ name | string }}'
case: '{{ entity.split(".")[0] }}'
this_state: '{{ state | string }}'
- choose:
- conditions:
- condition: template
value_template: "{{ case == 'light' and this_state == 'ein' }}"
sequence:
- service: light.turn_on
data:
color_temp: "{{ 500 if (15 < now().hour or now().hour < 4) else 153 }}"
target:
entity_id: "{{ name }}"
default:
- service: "homeassistant.turn_{{on if this_state == 'ein', else off}}"
data:
target:
entity_id: "{{ name }}"
mode: single
alias: 'Dummy Script'