How to manually control climate output

I have a custom device that is running on a d1 mini. I have a PID Climate that is outputting to a slow pwm relay. I also have that relay set up as a switch. When the PID Climate is set to mode “OFF”, I’d like to be able to control the relay via the switch. However right now when I turn the switch on, it immediately turns off (I’m assuming it is from the PID climate). Any idea how to control the relay when the PID Climate is off? Thanks.

Instead of directly controlling the relay from your PID climate or switch, create a switch in between where you can control the switching behavior. One option is to add a binary sensor in between.

binary_sensor:
  - platform: template
    id: relay_state
    filters:
      - lambda: return x || id(my_switch).state;
    on_press:
      then:
        - switch.turn_on: climate_relay
    on_release:
      then:
        - switch.turn_off: climate_relay

The filter evaluates the value against the state of your switch. When either is ON, will switch on the relay and only when both OFF then would switch off relay.

Setting binary sensor value from your climate and switch can be done with publish_state: (id(relay_state).publish_state(true);

1 Like

Thanks for pointing me on the track. The PID Climate has to output to a float, in this case a slow pwm output. The on/off of the output turns a climate binary sensor on and off. There switch controlling the same output that isn’t tied to a GPIO. The “controlling” binary sensor checks the switch state and climate binary sensor, then turns the output on and off accordingly…pretty much just as you described. Here is my relevant code:

dallas:
  - pin: D3
    update_interval: 1s

# Individual sensors
sensor:
  - platform: dallas
    address: 0x8203089779e2fd28
    name: "Brew Kettle Temp"
    id: kettle_temp

output:
  - platform: slow_pwm
    id: mash_slow_pwm
    period: 15s
    turn_on_action:
      - binary_sensor.template.publish:
          id: climate_relay_state
          state: ON
    turn_off_action:
      - binary_sensor.template.publish:
          id: climate_relay_state
          state: OFF    
  - platform: gpio
    pin: D6
    id: mash_relay

binary_sensor:
  - platform: template
    id: climate_relay_state
  
  - platform: template
    id: mash_relay_state
    name: 'Mash Element Active'    
    lambda: |-
          if (id(mash_switch).state || id(climate_relay_state).state) {
            return true;
          } else {
            return false;
          }
    on_press:
      then:
        - output.turn_on: mash_relay
    on_release:
      then:
        - output.turn_off: mash_relay

switch:
  - platform: template
    name: "Mash Element"
    optimistic: True
    id: mash_switch

climate:
  - platform: pid
    name: "eBIAB PID"
    sensor: kettle_temp
    id: pid_climate
    default_target_temperature: 66.667°C
    heat_output: mash_slow_pwm
    control_parameters:
      kp: 0.87308
      ki: 0.00353
      kd: 53.99995
      output_averaging_samples: 5      # smooth the output over 5 samples
      derivative_averaging_samples: 5  # smooth the derivative value over 10 samples
    visual:
      min_temperature: 60 °C
      max_temperature: 72 °C
      temperature_step: 0.1 °C