Jinja2 OR operation

all,
I’d appreciate if one of you can point me to what is wrong in this simple OR operation:

{{(states('input_boolean.a_call4h')) or (states('input_boolean.a_hvac'))}}

I know for sure one is ON and second is OFF, however the result is OFF, when is should be ON

TIA

I figured it out that piping the states output to bool does make it work…

{{(states('input_boolean.a_call4h') | bool) or (states('input_boolean.a_hvac') | bool )}}

Don’t fully understand the logic of why, but it works :slight_smile:

Your question isn’t very clear. For example, when you say what is wrong, do you mean you are getting the wring result, in which case what is the result? …or do you mean you are getting in an error with the template itself or…

Have you put it into Developer tools ➜ templates? …what is the result?

It looks OK to me, but you don’t need all those brackets though:

{{ states('input_boolean.a_call4h') or states('input_boolean.a_hvac') }}

Edit: I can see you have fixed with with |bool, but it should work without it (or at least it works for me without it).

OK, my version gives you on or off as a result. The |bool turns that into true or false, respectfully. However, you can use either.

The problem was that you were ORing strings. States are strings. The strings ‘off’ and ‘on’ will both register as true. By converting them to boolean types you have fixed this. Though you have a lot of unnecessary parentheses. Could be simplified to:

{{ states('input_boolean.a_call4h') | bool or states('input_boolean.a_hvac') | bool }}
2 Likes

Good info - thanks!

…but when I do this with 2 input_booleans on dev tools ➜ template, I still get off as a result when both individual entities are off, and on as a result when at least one is on …without using |bool.

The template editor interprets types. This has lead to a lot of confusion, as templates don’t. I’ve asked for this to be removed but it was rejected by the developers. :man_shrugging:

1 Like

ugh - good to know - thanks for that :+1:

…I always thought the template editor performed in exactly the same way as templates. …seems somewhat counter-intuitive that it isn’t an exact representation.

edit: This probably explains a few headaches I’ve had on the past trying to fault-find :sob:

Yeah, here’s how I discovered it:

2 Likes