klausahrenberg / WThermostatBeca

Replaces original Tuya firmware on Beca thermostat with ESP8266 wifi module
395 stars 96 forks source link

PWM workaround #325

Open Funkenschuhster opened 1 month ago

Funkenschuhster commented 1 month ago

Due to the big hysteresis of the thermostat and the slow reaction of my floor heating I was never happy with the thermostat. It was periodically to hot or to cold in the room. Now I found a crude workaround, to make PWM PID happen. The trick is to set the temperature higher or lower than the actual value to trigger the hysteresis.

Here is how I did it in node-red:

  1. I set up a standard PID controller. Analog input is the room temperature reading of the BHT-002. Analog output has a dynamic range of 0.0...1.0
  2. The analog output goes into a PWM node converting the analog 0.0...1.0 into a PWM at very slow frequency e. g. 200s on / 800s off = 0.25 = 25%
  3. The pulse goes to a converter which is generating a dynamic setpoint for BHT-002 based on the actual room temperature. See codebox below.
  4. The dynamic setpoint is calculated and sent to the BHT-002 frequently every two minutes. Frequently to make sure its always +-1K off even if the actual temperature just changed during calculation.

Code of the Setpoint generator:

// Open thermostat: set setpoint temperature higher than actual temperature
if (msg.pulseOut == 1) {
    msg.becaSetpoint = msg.becaRoomTemperature + 1K;
}

// Close thermostat: set setpoint temperature lower than actual temperature
if (msg.pulseOut == 0) {
    msg.becaSetpoint = msg.becaRoomTemperature - 1K;
}

return msg;

Used Nodes: PID: node-red-contrib-pid PWM: node-red-contrib-timeprop

I wonder if you could implement a PID workaround directly in the thermostat. Recommended features: