Morning all,
I’m by no means gifted when it comes to programming and have been trying to get my head around the following with no luck. I believe it’s because I’m trying to compare dissimilar operators, but can’t figure out how to resolve it within a lambda.
I’m using ESPHome’s Climate component. The snippet of code below is intended to take a physical button and use it to toggle the mode between off and auto each time it’s pressed. I can get it to turn on or off with on_press, but the if / and argument to toggle it is the problem.
Here’s the code:
on_press:
then:
- lambda: |-
if (id(hot_water_boiler).mode == 'OFF'){
auto call = id(hot_water_boiler).make_call();
call.set_mode("AUTO");
call.perform();
} else {
auto call = id(hot_water_boiler).make_call();
call.set_mode("OFF");
call.perform();
}
Here’s the error:
src/main.cpp: In lambda function:
src/main.cpp:472:36: error: no match for 'operator==' (operand types are 'esphome::climate::ClimateMode' and 'const char [4]')
if ((hot_water_boiler->mode) == "OFF"){
^
*** [/data/test_display/.pioenvs/test_display/src/main.cpp.o] Error 1
Anyone able to offer any insight? Very happy to be directed towards the proper resource to sort it for myself if it’s worded for morons!
Yours,
Steve.