Help with logical AND with the state of an ESPHome thermostat in an automation

I dont quite know how to go about this.

I want to logical AND the state of a binary_sensor and the state of a thermostat (ESPHome native, not home assistant) and dont really know how to do it or derive the state of the thermostat controller.

Lambdas? or is there an easier way of finding the state of the thermostat???

It would be a great help if someone could guide me.

binary_sensor:
  - platform: template
    name: "ds18b20 state"
    id: ds18_state
    lambda: |-
      if (id(temp_probe_error).state > 0) {
        return true;
      } else {
        return false;
      }
    on_state:
      then:
        - if:
            condition:
              binary_sensor.is_off: ds18_state
            then:
              do this script 1
                  ...
            else:
              do this script 2
              - if:
#######THIS PART##    AND'ing the relay and the state of the thermostat control ##########
                  condition:
                    and:
                    - switch.is_off: relay_1
                    - climate.mode_is_cooling: myclimatecontroller

                  then:
                    do this script 3

              - if:
                  condition:
                    and:
                      - switch.is_off: relay_1
                      - lambda: |-
                          return id(myclimatecontroller).mode == 'cooling';

Or possibly == 'Cooling', it is case sensitive.

1 Like

Bummer -

doesnt work no matter how I use it. ‘COOL’, ‘Cooling’, ‘cooling’

/config/esphome/display.yaml:1137:34: warning: character constant too long for its type
return id(controller).mode == 'Cooling';

Try:

return ( id(controller).mode == CLIMATE_MODE_COOL );

Yes, in all capitals and unquoted.

The API also gives some hints.

https://esphome.io/api/classesphome_1_1climate_1_1_climate#details

https://esphome.io/api/namespaceesphome_1_1climate#a8716cd7ed01ceb7ccedfa2f7b47a39d2

The reason these are public is for simple access to them from lambdas if (id(my_climate).mode == climate::CLIMATE_MODE_HEAT_COOL)

1 Like