diff -r f436d826de4b -r b863e0147296 thermferm/thermferm.c --- a/thermferm/thermferm.c Sun Aug 31 17:51:04 2014 +0200 +++ b/thermferm/thermferm.c Sun Aug 31 18:25:32 2014 +0200 @@ -1287,40 +1287,47 @@ sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out); } if (unit->heater_address) { - 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 (Out >= 2) { + if (Out >= 2) { + 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 && ! unit->cooler_state) { - syslog(LOG_NOTICE, "Heater Off => On"); - unit->heater_wait = 0; - unit->heater_state = 100; + syslog(LOG_NOTICE, "Heater Off => On"); + unit->heater_state = 100; } - } else { + } + } else { + if (unit->heater_wait > 0) { + 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_wait = 0; - unit->heater_state = 0; + syslog(LOG_NOTICE, "Heater On => Off"); + unit->heater_state = 0; } - } + } } device_out(unit->heater_address, unit->heater_state); } if (unit->cooler_address) { - if (unit->cooler_wait < unit->cooler_delay) { - unit->cooler_wait++; - } else { - if (Out <= -2) { + if (Out <= -2) { + if (unit->cooler_wait < unit->cooler_delay) { + unit->cooler_wait++; + syslog(LOG_NOTICE, "cooler_wait + %d/%d", unit->cooler_wait, unit->cooler_delay); + } else { 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_wait > 0) { + unit->cooler_wait--; + syslog(LOG_NOTICE, "cooler_wait - %d/%d", unit->cooler_wait, unit->cooler_delay); } else { if (unit->cooler_state) { syslog(LOG_NOTICE, "Cooler On => Off"); - unit->cooler_wait = 0; unit->cooler_state = 0; } }