#return value does not work

1 messages · Page 1 of 1 (latest)

hushed cloak
#

this works:

alias: foobar
sequence:
  - variables:
      test_var:
        value: 22
        other: 33
        sft: 44
  - stop: test
    response_variable: test_var
description: ""

but this does not, and i don't get why.
this is just an example, not the thing i am trying to make.

alias: foobar
sequence:
  - if:
      - condition: time
        after: "06:00:00"
    then:
      - variables:
          test_var:
            value: 22
            other: 33
            sft: 44
      - stop: test
        response_variable: test_var
description: ""

is that a design decission? it seems to stop working if you leafe the top level scope. but you cannot change variables from top level in a lower level, what makes them useless. seemingly you cannot return from a lower level.

peak birch
#

PS, please use code formatting for your YAML

marble oakBOT
#

To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

hushed cloak
hushed cloak
sacred field
#

Yup, variables have scope... You can't return like this.
However, you can do it with creating namespace var on top level and setting something into it inside if block, AFAIK.

peak birch
#

there is no thing like a namespace var on global level of an automation

sacred field
sacred field
# peak birch The response variable indeed only works at top level scope. There is a PR open f...

That's super dumb situation with var scope and no namespaces... One can use variables from parent scope, but never change anything or return from there. PR you've mentioned addresses latter, but i'd rather have something like this: https://github.com/home-assistant/architecture/discussions/888 - it's way more versatile.

GitHub

The current script variables scoping is very limiting. There are cases where it's helpful to build up values as branches are taken, loops iterate, etc. to then use later in the script. Jinja ha...