Variables in a script

At the choose:

Executed: 11. januar 2023 kl. 19.24.49
Result:
choice: default

detector:
  light: light.gang_dimmer_3
  flag: input_boolean.aut_gang
  illuminance: sensor.gang_sensor_illuminance
  rooms_aut: true
  modes:
    morgen1: 40
    morgen2: 50
    dag1: 100
    aften1: 80
    aften2: 70
    aften3: 50
    aften4: 40
    nat1: 10

Which means it does nothin as “default” choice is empty.

But in addition to above, I get an error in the log, perhaps that is helpful?

Template variable warning: ‘rooms_aut’ is undefined when rendering ‘{{ rooms_aut }}’

That’s a very helpful message and explains why it didn’t work. I made a mistake; I forgot that rooms_aut is part of the detector variable! :man_facepalming:

Change this:

- "{{ rooms_aut }}"

to this:

- "{{ detector.rooms_aut }}"

I will correct the example posted above.

Perfect, that was it! Thanks.

The automation continues to work great, but since then I have made a helper called “input_number.luxgraense” which is just a slider that provides a number (for instance 180) to be used as a threshold for when the light should trigger or not.

conditions:
          - "{{ trigger.to_state.state == 'on' }}"
          - >-
            {{ states(detector.illuminance) | int(250) < states(input_number.luxgraense) }}
          - "{{ detector.rooms_aut }}"

The above doesn’t work this is what is in the log: “Error in ‘choose[1]’ evaluation: In ‘template’ condition: UndefinedError: ‘input_number’ is undefined”. Any ideas?

Your entity IDs need to be in single quotes.

{{ states(detector.illuminance) | int(250) < states('input_number.luxgraense') }}

Thanks a lot, that worked :slight_smile: