Now i want to take some actions based on gpio (id) status, ON or OFF.
For example, if id(relai_ein_aus).state is ON and id(heizkoerper).state is ON, ok, it’s working, but if id(relai_ein_aus).state is ON and id(heizkoerper).state is OFF, there is an error and i want to switch.toggle: relai_ein_aus.
I’m not finding the right way to do it. How to compare if ON or OFF?
so, when id(gpio).state = ON or OFF i’ll take actions.
and i get:
Compiling .pioenvs/ek3117-severin/src/main.cpp.o
<unicode string>: In lambda function:
<unicode string>:118:33: error: expected primary-expression before '==' token
<unicode string>:121:31: error: expected primary-expression before '==' token
<unicode string>:124:30: error: expected primary-expression before '==' token
<unicode string>:127:3: error: no return statement in function returning non-void [-Werror=return-type]
cc1plus: some warnings being treated as errors
*** [.pioenvs/ek3117-severin/src/main.cpp.o] Error 1
========================== [FAILED] Took 3.06 seconds ==========================
i really get confused. i just want to compare states and set a variable with a number, fro 0 to 7 depending on each status, for a later case and actions.
You have a problem with the braces for the if statements. All braces are closed before == but the whole test needs to be in braces. If you move the closing brace to before the { it should compile.
Also, some return statements have unmatched braces. They close a brace that was never opened.
Also, are you aware you are both assigning a value and returning the result in one statement? It is easily confused with a compare statement (in which case you would return true or false. If you meant to compare, you would need to use == and not =
If assigment is what you intend, this is best avoided by writing an assignment statement separate from the return statement. It is allowed to do though.
The + in the statement is obsolete. At other places you write “=+ 2”. Here it seems like the + belongs to the = and not the 2. This is also a confusing notation, because += has a special meaning in c++ but =+ has no special meaning. += means you add something to the original value (increment). You now wrote = +2; In that case I would write = 2.
Last but not least, you say the state would be a value from 0 to 7. The way you wrote it, every return statement would stop further execution. The highest value you would get now is 4. If you meant to add values, you would likely start with 0 and use += to add values, not =+ which is just assign a positive number. You would only use return at the end, when the result is complete, and not halfway, before you are done. I would also use a temporary variable and only set the state at the end. Now you’d have many state changes that are possibly incomplete states.