So I want a script which will kick-off 1 or another script depending on the status of a switch.
I tried many many things but don’t succeed.
Currently I have this as a script:
tea:
alias: Tea
sequence:
- service_template: script.turn_on
data_template: >-
{% if is_state('switch.Sonoff20a', 'off') %}
tea1
{% elif is_state('switch.Sonoff20a', 'on') %}
tea2
{% endif %}
When put in the Templates test <> thing this is the result:
tea:
alias: Tea
sequence:
- service_template: script.turn_on
data_template: >
tea1
Seems good to me, no?
However when trying to start Hass with this, I get the error:
2017-12-21 22:47:35 ERROR (MainThread) [homeassistant.config] Invalid config for [script]: expected a dictionary for dictionary value @ data['script']['tea']['sequence'][0]['data_template']. Got "{% if is_state('switch.Sonoff20a', 'off') %}\n tea1\n{% elif is_state('switch.Sonoff20a', 'on') %}\n tea2\n{% endif %}". (See /home/homeassistant/.homeassistant/configuration.yaml, line 475). Please check the docs at https://home-assistant.io/components/script/
2017-12-21 22:47:35 ERROR (MainThread) [homeassistant.setup] Setup failed for script: Invalid config.
Also tried these but all gave errors:
sequence:
- service: script.turn_on
data_template:
{% if is_state('switch.Sonoff20a', 'off') %}
entity_id: script.tea1
{% elif is_state('switch.Sonoff20a', 'on') %}
entity_id: script.tea2
{% endif %}
sequence:
- service_template: script.turn_on
data_template: >-
{% if is_state('switch.Sonoff20a', 'off') %}
script.tea1
{% elif is_state('switch.Sonoff20a', 'on') %}
script.tea2
{% endif %}
And a few others.
Who knows how to crack this one?