I’m trying to check (test) whether a value for a variable (field) has been passed to a script and execute the correct choose
sequence.
It’s my understanding that all script variables are optional. Just to emphasise: When I say variable, I refer to what’s defined under a script’s fields
and are passed to a service
like this (and not variables
that are defined within a script):
service: script.turn_on
target:
entity_id: script.test
data:
variables: # <--- this is a script field
param1: "ignore"
Here is my current script:
test:
description: "Test script"
fields:
param1:
description: "Parameter 1"
example: "Any text"
sequence:
- choose:
- conditions:
- condition: template
value_template: "{{ true if param1 == 'ignore' else false }}"
sequence:
- service: persistent_notification.create
data:
title: "Testing"
message: "Test: no param"
default:
- service: persistent_notification.create
data:
title: "Testing"
message: "Test: '{{ param1 }}'"
- condition: variable_value # like a state but not really
variable: param1
state: "" # or None or something else?
I don’t think it’s possible (yet) and if not, I’d log a feature request but thought I’d ask because maybe there are other workarounds or clever tricks.
My options as it stands seem to be:
- Use a dummy value but then I need to pass this value everywhere I use the script which defeats the purpose of having an optional value (i.e. my script above).
- Make two separate scripts but at the cost of some duplication.
These posts were the closest I could find but they’re solving different issues:
I did see in the second post this is used but I was unable to confirm whether this actually works (I read and re-read the script docs several times to see if I’m missing something:
- conditions:
- condition: state
entity_id: variable.scene_arbeitszimmer
state: 'Hell'
Docs:
A second, somewhat related question is why this would result in the following errors:
test:
description: "Test script"
fields:
param1:
description: "Parameter 1"
example: "Any text"
required: false
default: "nothing"
Errors:
[required] is an invalid option for [script]
[default] is an invalid option for [script]
I know these are purely for the UI and won’t solve my issue but I was curious to understand where I’m going wrong as I’m unable to spot the difference compared to the docs.