Platform switch template lambda conditions

hi all,

I’m trying to figure out why this wont work:

    - platform: template
      name: "S Mode"
      lambda: !lambda |-
        if (id(jva_intake).state) == False and (id(jva_return).state) == True {
          return true;
        } else {
          return false;
        }
      turn_on_action:
        - switch.turn_on: jva_intake
        - switch.turn_on: jva_return
      restore_state: NO

I get

src/main.cpp: In lambda function:
src/main.cpp:670:30: error: expected primary-expression before '==' token
       if (jva_intake->state) == True and (jva_return->state) == False {
                              ^
src/main.cpp:670:33: error: 'True' was not declared in this scope
       if (jva_intake->state) == True and (jva_return->state) == False {
                                 ^
src/main.cpp:670:65: error: 'False' was not declared in this scope
       if (jva_intake->state) == True and (jva_return->state) == False {
                                                                 ^
src/main.cpp:675:3: warning: control reaches end of non-void function [-Wreturn-type]
   });
   ^

I’ve tried a few variations without the ‘and’, the only condition I can get to compile is if i do only

if (id(jva_intake).state)

Any help or advice is appreciated.

why are you using True and False instead of true and false?

I did try true and false too but getting the same result, that uppercase was a typo on my part just now

your parens are wrong too. Should be

        if (id(jva_intake).state == false && id(jva_return).state == true) {
          return true;
        } else {
          return false;
        }

or better yet

        return (!id(jva_intake).state && id(jva_return).state);
1 Like

This was extremely helpful, and now I’ve learned a bit more about the proper syntax, thanks a bunch.