diff -r dc88583a068d -r df81d583c2c3 thermferm/thermferm.c --- a/thermferm/thermferm.c Tue Aug 26 14:45:03 2014 +0200 +++ b/thermferm/thermferm.c Sat Aug 30 13:06:07 2014 +0200 @@ -252,6 +252,7 @@ /* Allways turn everything off after a mode change */ current_unit->PID_I_err = current_unit->PID_err_old = 0.0; current_unit->heater_state = current_unit->cooler_state = current_unit->fan_state = 0; + current_unit->heater_wait = current_unit->cooler_wait = current_unit->fan_wait = 0; device_out(current_unit->heater_address, current_unit->heater_state); device_out(current_unit->cooler_address, current_unit->cooler_state); device_out(current_unit->fan_address, current_unit->fan_state); @@ -915,6 +916,7 @@ * Safety, turn everything off */ unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = 0; + unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0; if (unit->mode == UNITMODE_PROFILE) { if (!unit->profile) syslog(LOG_NOTICE, "Starting unit %s in profile mode, no profile defined.", unit->name); @@ -1285,26 +1287,43 @@ sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out); } if (unit->heater_address) { - if (Out >= 2) { - if (! unit->heater_state) - syslog(LOG_NOTICE, "Heater Off => On"); - unit->heater_state = 100; + if (unit->heater_wait < unit->heater_delay) { + unit->heater_wait++; + syslog(LOG_NOTICE, "heater_wait %d/%d", unit->heater_wait, unit->heater_delay); } else { - if (unit->heater_state) - syslog(LOG_NOTICE, "Heater On => Off"); - unit->heater_state = 0; + if (Out >= 2) { + if (! unit->heater_state && ! unit->cooler_state) { + syslog(LOG_NOTICE, "Heater Off => On"); + unit->heater_wait = 0; + unit->heater_state = 100; + } + } else { + if (unit->heater_state) { + syslog(LOG_NOTICE, "Heater On => Off"); + unit->heater_wait = 0; + unit->heater_state = 0; + } + } } device_out(unit->heater_address, unit->heater_state); } if (unit->cooler_address) { - if (Out <= -2) { - if (! unit->cooler_state) - syslog(LOG_NOTICE, "Cooler Off => On"); - unit->cooler_state = 100; + if (unit->cooler_wait < unit->cooler_delay) { + unit->cooler_wait++; } else { - if (unit->cooler_state) - syslog(LOG_NOTICE, "Cooler On => Off"); - unit->cooler_state = 0; + if (Out <= -2) { + if (! unit->cooler_state && ! unit->heater_state) { + syslog(LOG_NOTICE, "Cooler Off => On"); + unit->cooler_wait = 0; + unit->cooler_state = 100; + } + } else { + if (unit->cooler_state) { + syslog(LOG_NOTICE, "Cooler On => Off"); + unit->cooler_wait = 0; + unit->cooler_state = 0; + } + } } device_out(unit->cooler_address, unit->cooler_state); } @@ -1422,6 +1441,7 @@ * Turn everything off */ unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = 0; + unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0; device_out(unit->heater_address, unit->heater_state); device_out(unit->cooler_address, unit->cooler_state); device_out(unit->fan_address, unit->fan_state);