Variable defaults in script

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' }}   




Found it, for those who need it…

alias: alles_aanuit
variables:
  dagtypesave: "{{ states('input_select.dagtypen') }}"
  aantal: 1
  keuze: "{{ keuze if keuze is defined else \"uit\" }}"
  dagtype: "{{ dagtype if dagtype is defined else dagtypesave }}"
sequence:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ keuze == 'aan_donker' }}"
        sequence:
          - service: input_select.select_option
            data:
              option: "{{ dagtype }}"
            target:
              entity_id: input_select.dagtypen
          - repeat:
              count: "{{aantal}}"
              sequence:
                - service: input_boolean.turn_on
                  data: {}
                  target:
                    entity_id:
                      - input_boolean.basisvoorzieningen
                      - input_boolean.scene_tuin
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 30
                    milliseconds: 0
                - service: input_boolean.turn_on
                  data: {}
                  target:
                    entity_id:
                      - input_boolean.scene_avond
          - service: input_select.select_option
            data:
              option: "{{ dagtypesave }}"
            target:
              entity_id: input_select.dagtypen
      - conditions:
          - condition: template
            value_template: "{{ keuze == 'aan_licht' }}"
        sequence:
          - repeat:
              count: "{{aantal}}"
              sequence:
                - service: input_boolean.turn_on
                  data: {}
                  target:
                    entity_id:
                      - input_boolean.basisvoorzieningen
      - conditions:
          - condition: template
            value_template: "{{ keuze == 'uit' }}"
        sequence:
          - repeat:
              count: "{{aantal}}"
              sequence:
                - service: script.turn_on
                  data: {}
                  target:
                    entity_id: script.irrigatie_allesstoppen
                  enabled: false
                - service: input_boolean.turn_off
                  data: {}
                  target:
                    entity_id:
                      - input_boolean.irrigatie_alles
                      - input_boolean.scene_avond
                      - input_boolean.scene_tuin
                      - input_boolean.scene_opstaan
                      - input_boolean.scene_ontbijten
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 5
                    milliseconds: 0
                - service: input_boolean.turn_off
                  data: {}
                  target:
                    entity_id:
                      - input_boolean.basisvoorzieningen
                - service: scene.turn_on
                  data: {}
                  target:
                    entity_id: scene.alles_uit
                - service: input_select.select_option
                  data:
                    option: afsluiten
                  target:
                    entity_id: input_select.nastypen
                  enabled: false
icon: mdi:home
mode: single

Or just use or :slight_smile:

variables:
  keuze: "{{ keuze or \"uit\" }}"