Hi, i use the latest Hass in a docker on a rpi 4b.
My question is how to define a variable in a script, only when there isnt already a usable value.
For example.
I call a script from a widget (app hass) and i define the variable in the widget.
Or the widget does not define the variables and the script uses its own declarion.
I made the script, but the variables in the script are always used instead conditionally…
alias: exec_script
variables:
scenenaam: "{{ scenenaam if scenenaam is defined else \"tuin_kerst_aan\" }}"
bolaction: "{{ bolaction if bolaction is defined else \"turn_on\" }}"
bolnaam: "{{ bolnaam if bolnaam is defined else \"scene_tuin\" }}"
sequence:
- service: scene.turn_on
target:
entity_id: scene.{{scenenaam}}
metadata: {}
- service: input_boolean.{{bolaction}}
data: {}
target:
entity_id: input_boolean.{{bolnaam}}
mode: single
icon: mdi:glass-wine
I tried this, but did not work
when starting the script without data/variables i like to set a default. For example, when i use a scheduler i cant set de data, so the script must uses defaults. Calling the script from a autoamtion i can use tghe data section and pass them to the script. In that case i dont need the defaults
variables:
dagtypesave: "{{ states('input_select.dagtypen') }}"
aantal: 1
keuze: |
{% if keuze == '' %} 'uit'
{% endif %}
dagtype: |
{% if dagtype == '' %} dagtypesave
{% endif %}
also tried
variables:
dagtypesave: "{{ states('input_select.dagtypen') }}"
aantal: 1
keuze: |
{ keuze if keuze is defined else uit }}
dagtype: |
{ dagtype if dagtype is defined else 'eco' }}