Script variables (fields) default value error (expected float for dictionary value)

Hi, I’m trying to use a script variable with a default value, but I get errors on default value:

alias: Nouveau script
fields:
  delai_fermeture:
    name: Délai de fermeture
    selector:
      number:
        min: 1
        max: 100
        step: 1
    default: 65
sequence:
  - delay:
      hours: 0
      minutes: 0
      seconds: "{{ delai_fermeture }}"
      milliseconds: 0
mode: single
description: ""

I get the following error: Erreur : expected float for dictionary value @ data[‘seconds’] fields

If I try: “{{ delai_fermeture | float }}”, I get “Erreur : UndefinedError: ‘delai_fermeture’ is undefined”

Any help will be more than welcome :slight_smile:

It’s my understanding that the selector’s default option is merely a suggestion displayed in the UI. If the user doesn’t supply a value, the variable has no value and is undefined. It explains why you got this error message:

Erreur: UndefinedError: ‘delai_fermeture’ is undefined

I suggest you do this:

sequence:
  - delay: 
      seconds: "{{ delai_fermeture | default(65) }}"

Reference

Important Template Rules (Second rule)


EDIT

Correction. Second suggestion removed because it’s not applicable for a script.

Thanks a lot for your answer.

Your first suggetion work fine!

I tried the second but there seem to be a syntax error with “- variables:”
When I save in the yaml editor and I come back, this part is removed.

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.

I removed the second suggestion from my previous post because I now realize it’s not applicable for a script (!input is used in a blueprint).

1 Like