In blueprints there is a support of default values of input variables.
Do we have a similar support for scripts?
Here is an example:
script:
do_something:
fields:
input_FLAG_1:
selector:
entity:
domain: input_boolean
input_FLAG_2:
selector:
entity:
domain: input_boolean
sequence:
...
- service: script.do_something
data:
input_FLAG_1: input_boolean.flag_1
input_FLAG_2: input_boolean.flag_2
I wonder is it possible to define a default value for input_FLAG_2
and not pass it every call?
You can definitely set a default… Passing variables to scripts. I’ve never tried it with a selector, but it doesn’t seem to be expressly forbidden according to the docs.
This note confuses me:
And just for test I made this:
input_FLAG_2:
selector:
entity:
domain: input_boolean
default: binary_sensor.service_on_value ###which is ON always
and called the script w/o input_FLAG_2
:
- service: script.do_something
data:
input_FLAG_1: input_boolean.flag_1
and I see this error:
Error in 'choose[0]' evaluation: In 'template' condition: UndefinedError: 'input_FLAG_2' is undefined
So it seems that default
option is only for UI.
This is likely a solution for the original problem.
You can have variables in scripts & script Blueprints as well as fields, so…
fields:
thing_1:
---
variables:
thing_1: >
(% if thing_1 | default('') %}
thing_1
{% else %}
"default value"
{% endif %}