I have tried several attempts to get my template which works in the template editor inside a new Script
Aim is to make a random number then use a if else to choose scripts (I can use code but cannot get it to work)
alias: test
sequence:
{% set randomNumber = range(1, 3) | random %}
{% if 6 == 1 %}
- service: script.iron_man_on
{% elif 2 == 2 %}
- service: script.arc_reactor_on
{% else %}
- service: script.iron_man_on
- service: script.arc_reactor_on
{% endif %}
mode: single
icon: mdi:alarm-light
tried
bob:
alias: test
sequence:
- service: script.turn_on
data_template:
{% set randomNumber = range(1, 3) | random %}
{% if 6 == 1 %}
- service: script.iron_man_on
{% elif 2 == 2 %}
- service: script.arc_reactor_on
{% else %}
- service: script.iron_man_on
- service: script.arc_reactor_on
{% endif %}
mode: single
icon: mdi:alarm-light
When you have a lot of possible choices, it’s better to use a mapping method instead of a bunch of “if/elifs”. For just a few choices, something like this will work: