Climate pid activate automation

Hello Community,

I have a ESP controller which control my sauna using climate with pid and ac dimmer for a smooth control.
For a safety reason I would like to add a power contactor to cut off the 230 Vac line.

The idea is to turn the contactor once the climate is in mode “HEAT” and turn off when the climate is “OFF”.
I can not figure out how to do so. I’m can imagine something with lambda, but can not figure out where to put it.

Would you have iny suggestions?

sensor:
  - platform: dallas
    name: "Sauna temperature"
    address: 0x1E00000001BF7128
    id: sauna_temperature_sensor
    
output:
  - platform: ac_dimmer
    id: dimmer1
    max_power: 0.8
    min_power: 0.2
    gate_pin: GPIO32
    zero_cross_pin:
      number: GPIO33
      mode:
        input: true
      inverted: yes

switch:
  - platform: gpio
    pin: GPIO21
    id: Contactor
    name: "Contactor"
    
climate:
  - platform: pid
    id: pid_climate
    name: "PID Sauna Controller"
    visual:
      min_temperature: 40 °C
      max_temperature: 90 °C
      temperature_step: 1 °C
    sensor: sauna_temperature_sensor
    default_target_temperature: 70°C
    heat_output: dimmer1
    control_parameters:
      kp: 1.44
      ki: 13.5
      kd: 1.8

Maybe a on_state trigger with some lambdas?

1 Like

Thank you for the tip.

I have solved it like that.

on_state:
      lambda: !lambda |-
        if (id(pid_climate).mode == 3) {
          id(AC_contactor).turn_on();
        } else {
          id(AC_contactor).turn_off();
        } 

Detailed
I was disturbed by the variable definition.

From the component is a string type

From the lambda is a enum type

And I have found the needed values for OFF and HEAT under climate__mode_8h

enum  	esphome::climate::ClimateMode : uint8_t {
  esphome::climate::CLIMATE_MODE_OFF = 0, esphome::climate::CLIMATE_MODE_HEAT_COOL = 1, esphome::climate::CLIMATE_MODE_COOL = 2, esphome::climate::CLIMATE_MODE_HEAT = 3,
  esphome::climate::CLIMATE_MODE_FAN_ONLY = 4, esphome::climate::CLIMATE_MODE_DRY = 5, esphome::climate::CLIMATE_MODE_AUTO = 6
}
1 Like

Nice. Yeah the docs make you dig around a little more for this one!

It may be worth noting that I think your lambda will fire every time the temperature changes? Probably not a problem though?

Hi,

Not really. There is the Mode and the Action.
Mode is telling if it’s OFF, on HEAT or on COOL.
Action is telling if in HEAT mode your are HEATING or in STAND-BY because the temperature is reached.