diff --git a/thermostat.go b/thermostat.go index b9f92c4..62bff2b 100644 --- a/thermostat.go +++ b/thermostat.go @@ -83,11 +83,9 @@ func ProcessSensor(sensor Sensor, state State) (State, error) { // Temperature is too high and the cooling switch is still on, do nothing case temp > sensor.HighTemp && state.Cooling: break - // Temperature is too high, but duration hasn't been met - case temp > sensor.HighTemp: - if state.Changed.After(time.Now()) { - state.Changed = time.Now() - } + // Temperature is too high, but duration hasn't been counted + case temp > sensor.HighTemp && duration < 0: + state.Changed = time.Now() // Temperature is too high and the duration has been long enough, start cooling case temp > sensor.HighTemp && duration > sensor.CoolMinutes: PinSwitch(cpin, true, sensor.CoolInvert) @@ -101,11 +99,9 @@ func ProcessSensor(sensor Sensor, state State) (State, error) { // Temperature is too low and the heating switch is on, do nothing case temp < sensor.LowTemp && state.Heating: break - // Temperature is too low, but duration hasn't been met - case temp < sensor.LowTemp: - if state.Changed.After(time.Now()) { - state.Changed = time.Now() - } + // Temperature is too low, but duration hasn't been counted + case temp < sensor.LowTemp && duration < 0: + state.Changed = time.Now() // Temperature is too low and the duration has been long enough, start heating case temp < sensor.LowTemp && duration > sensor.HeatMinutes: PinSwitch(hpin, true, sensor.HeatInvert)