mirror of
https://github.com/shouptech/tempgopher.git
synced 2026-02-03 16:49:42 +00:00
Fix some thermostat logic
This commit is contained in:
parent
f5838c3ebd
commit
f7d6456572
1 changed files with 9 additions and 3 deletions
|
|
@ -73,24 +73,30 @@ func ProcessSensor(sensor Sensor, state State) (State, error) {
|
||||||
duration := time.Since(state.Changed).Minutes()
|
duration := time.Since(state.Changed).Minutes()
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case temp > sensor.HighTemp && temp < sensor.HighTemp:
|
case temp > sensor.HighTemp && temp < sensor.LowTemp:
|
||||||
log.Println("Invalid state! Temperature is too high AND too low!")
|
log.Println("Invalid state! Temperature is too high AND too low!")
|
||||||
case temp > sensor.HighTemp && state.Heating:
|
// Temperature is high enough, turn off
|
||||||
|
case temp > sensor.LowTemp && state.Heating:
|
||||||
PinSwitch(hpin, false, sensor.HeatInvert)
|
PinSwitch(hpin, false, sensor.HeatInvert)
|
||||||
state.Heating = false
|
state.Heating = false
|
||||||
state.Changed = time.Now()
|
state.Changed = time.Now()
|
||||||
|
// Temperature is too high and the cooling switch is still on, do nothing
|
||||||
case temp > sensor.HighTemp && state.Cooling:
|
case temp > sensor.HighTemp && state.Cooling:
|
||||||
break
|
break
|
||||||
|
// Temperature is too high and the duration has been long enough, start cooling
|
||||||
case temp > sensor.HighTemp && duration > sensor.CoolMinutes:
|
case temp > sensor.HighTemp && duration > sensor.CoolMinutes:
|
||||||
PinSwitch(cpin, true, sensor.CoolInvert)
|
PinSwitch(cpin, true, sensor.CoolInvert)
|
||||||
state.Cooling = true
|
state.Cooling = true
|
||||||
state.Changed = time.Now()
|
state.Changed = time.Now()
|
||||||
case temp < sensor.LowTemp && state.Cooling:
|
// Temperature is low enough, stop cooling
|
||||||
|
case temp < sensor.HighTemp && state.Cooling:
|
||||||
PinSwitch(cpin, false, sensor.CoolInvert)
|
PinSwitch(cpin, false, sensor.CoolInvert)
|
||||||
state.Cooling = false
|
state.Cooling = false
|
||||||
state.Changed = time.Now()
|
state.Changed = time.Now()
|
||||||
|
// Temperature is too low and the heating switch is on, do nothing
|
||||||
case temp < sensor.LowTemp && state.Heating:
|
case temp < sensor.LowTemp && state.Heating:
|
||||||
break
|
break
|
||||||
|
// Temperature is too low and the duration has been long enough, start heating
|
||||||
case temp < sensor.LowTemp && duration > sensor.HeatMinutes:
|
case temp < sensor.LowTemp && duration > sensor.HeatMinutes:
|
||||||
PinSwitch(hpin, true, sensor.HeatInvert)
|
PinSwitch(hpin, true, sensor.HeatInvert)
|
||||||
state.Heating = true
|
state.Heating = true
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue