ESPHome Climate 'no match for 'operator=='' lambda error

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.

Sorry Tom - I don’t understand the post removed comment - I don’t believe I have removed it!

Nothing to do with your post. I removed my post because it was completely wrong. If you look at the top right corner of my post you will see a little orange pencil that shows the post history. If you click that you can see my mistake.

Aaaah. My first time here I think - thanks!

1 Like

I think your solution is going to involve converting id(hot_water_boiler).mode to a string before comparing it with ‘OFF’, but I have no idea how to do that.

esphome::climate::ClimateMode Is an enum. That’s means that the you need compare

if(id(hot_water_boiler).mode == esphome::climate::ClimateMode::CLIMATE_MODE_OFF )

I am not sure that syntax is correct it was 15 years since I programmed c++.

But I think it should also be possible do like this
id(hot_water_boiler).mode == 0)

The CLIMATE_MODE_OFF is defined as 0.

Hope it helps.

Mattias

4 Likes

Gents,

Brilliant - thank you. You’re spot on. Now works just as intended. Many thanks.

S.

I’m glad that it worked.
/Mattias