enkama / hass-variables

Home Assistant variables component
91 stars 11 forks source link

Timer Example throws out an 'UndefinedError' [SOLVED] #7

Closed 3ative closed 3 years ago

3ative commented 3 years ago

I've setup the Variable (_variable.testingone) and can change the state, so that bit is working.

Any ideas?

enkama commented 3 years ago

So I narrowed it down to being the value: | {{ [((variable.state | int) - 1), 0] | max }} part. Didnt have any more time yet. Tbh that part was just copy pasted from the rogro repo.

enkama commented 3 years ago

Try it like this:


value: >
    {{ [((states.variable.testing_one.state | int) - 1), 0] | max }}```
3ative commented 3 years ago

value: > {{ [((states.variable.testing_one.state | int) - 1), 0] | max }}```

I tried that, it worked-ish. 👍 I edited your code to:

value: |
  {{ [((states.variable.testing_one.state | int) - 1), 0] | max }}

I removed the trailing 'tick' marks ( I guessed it was a typo😉) and now it works - Thank you for your time.

3ative commented 3 years ago

@Wibias Should I make a PR to update the code examples ? Or, now that you know about it, will you make the necessary edits.

enkama commented 3 years ago

I will do it in some minutes. Thanks for the response!

3ative commented 3 years ago

@Wibias Addition: I just looked at the yaml again, after a reload and HA changed it to this:

  action:
    - service: variable.set_variable
      data:
        variable: testing_one
        value: "{{ [((states.variable.testing_one.state | int) - 1), 0] | max }}"

Notice the quotes on the 'value:' line.

enkama commented 3 years ago

For me it doesnt add the quotes but I am also using '>'

3ative commented 3 years ago

@Wibias

For me it doesnt add the quotes but I am also using '>'

If I save using the '>' that gets changed to a pipe '|' !

Well that's weird, I just checked again and for some reason it's changed it to single quotes now!!!

  action:
  - service: variable.set_variable
    data:
      variable: testing_one
      value: '{{ [((states.variable.testing_one.state | int) - 1), 0] | max }}'