This is my first post. Please apologize if I am not using the forum corectly.
Question:
I want to set the variable “result” in the following script but the statement “result: “hall”” is not working
How can I manipulate a script wide variable?
alias: Testscript
sequence:
- variables:
result: "asdf"
test: 20
- if: "{{ test == 20 }}"
then:
result: "hall"
- service: notify.marty1945
data:
message: "{{ result }}"
mode: single
I am still struggling with the principal functionality of Yaml and I am not sure whether I understand the concept correctly
The solution you are suggesting is working but seems rather limited and would not work if the user wants to calculated something.
The kind of “workaround” I found is the use this Jinja inline language.
Example:
alias: Test working
sequence:
- variables:
yamlkey: |
{% set result="hallo" %}
{% if (states("switch.living_room") == "off") %}
{% set result="Hallo2" + "Test" %}
{% else %}
{% set result="asdfasdf" %}
{% endif %}
{% print(result) %}
- service: notify.marty1945
data:
message: "{{ yamlkey }}"
mode: single
Is my understanding correct?
Mixing this two different “languages” (Yaml and JInja) with pretty different syntax is a bit strange.
The alternative would be to use Phython as a scripting language but this seems not to be encouraged.
What have been the reason for this appraoch?
Has this historical reasons or is there a hidden concept with great benefits I do not understand?