mirror of
https://github.com/shouptech/tempgopher.git
synced 2026-02-03 08:39:43 +00:00
Merge branch '8-change-temperature-logic' into 'master'
Resolve "Change temperature logic" Closes #8 Changes temperature logic to: If temperature exceeds threshold, enable cooling/heating. If temperature is below desired threshold, turn off cooling/heating if duration has been exceeded. See merge request shouptech/tempgopher!1
This commit is contained in:
commit
b3d0ebd4b0
2 changed files with 30 additions and 32 deletions
|
|
@ -49,8 +49,8 @@ function renderThermostats() {
|
||||||
var hightemp = parseFloat(configData.hightemp).toFixed(1) + "°C";
|
var hightemp = parseFloat(configData.hightemp).toFixed(1) + "°C";
|
||||||
var lowtemp = parseFloat(configData.lowtemp).toFixed(1) + "°C";
|
var lowtemp = parseFloat(configData.lowtemp).toFixed(1) + "°C";
|
||||||
}
|
}
|
||||||
configText = "Chills when > " + hightemp + " for " + configData.coolminutes + " minutes.<br />";
|
configText = "Chills for " + configData.coolminutes + " minutes when > " + hightemp + ".<br />";
|
||||||
configText += "Heats when < " + lowtemp + " for " + configData.heatminutes + " minutes.";
|
configText += "Heats for " + configData.heatminutes + " minutes when < " + lowtemp + ".";
|
||||||
|
|
||||||
var configp = $("<p></p>").html(configText);
|
var configp = $("<p></p>").html(configText);
|
||||||
var configdiv = $("<div></div>").addClass("seven columns").append(configp);
|
var configdiv = $("<div></div>").addClass("seven columns").append(configp);
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,11 @@ func ProcessSensor(sensor Sensor, state State) (State, error) {
|
||||||
log.Panicln(err)
|
log.Panicln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When things reach the right temperature, set the duration to the future
|
||||||
|
// TODO: Better handling of this. Changed should maintain when the state changed.
|
||||||
|
// Probably need a new flag in the State struct.
|
||||||
|
future := time.Date(2999, 1, 1, 0, 0, 0, 0, time.UTC)
|
||||||
|
|
||||||
state.When = time.Now()
|
state.When = time.Now()
|
||||||
|
|
||||||
// Initialize the pins
|
// Initialize the pins
|
||||||
|
|
@ -74,45 +79,38 @@ func ProcessSensor(sensor Sensor, state State) (State, error) {
|
||||||
// Calculate duration
|
// Calculate duration
|
||||||
duration := time.Since(state.Changed).Minutes()
|
duration := time.Since(state.Changed).Minutes()
|
||||||
|
|
||||||
// When things reach the right temperature, set the duration to the future
|
|
||||||
// TODO: Better handling of this. Changed should maintain when the state changed.
|
|
||||||
// Probably need a new flag in the State struct.
|
|
||||||
future := time.Date(2999, 1, 1, 0, 0, 0, 0, time.UTC)
|
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case temp > sensor.HighTemp && temp < sensor.LowTemp:
|
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!")
|
||||||
// Temperature is high enough, turn off
|
// Temperature too high, start cooling
|
||||||
case temp > sensor.LowTemp && state.Heating:
|
case temp > sensor.HighTemp:
|
||||||
PinSwitch(hpin, false, sensor.HeatInvert)
|
|
||||||
state.Heating = false
|
|
||||||
state.Changed = future
|
|
||||||
// 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 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)
|
PinSwitch(cpin, true, sensor.CoolInvert)
|
||||||
state.Cooling = true
|
state.Cooling = true
|
||||||
state.Changed = time.Now()
|
PinSwitch(hpin, false, sensor.HeatInvert) // Ensure the heater is off
|
||||||
// Temperature is low enough, stop cooling
|
state.Heating = false
|
||||||
case temp < sensor.HighTemp && state.Cooling:
|
state.Changed = future
|
||||||
|
// Temperature too low, start heating
|
||||||
|
case temp < sensor.LowTemp:
|
||||||
|
PinSwitch(hpin, true, sensor.HeatInvert)
|
||||||
|
state.Heating = true
|
||||||
|
PinSwitch(cpin, false, sensor.CoolInvert) // Ensure the chiller is off
|
||||||
|
state.Cooling = false
|
||||||
|
state.Changed = future
|
||||||
|
// Temperature is good and cooling has been happening long enough
|
||||||
|
case temp < sensor.HighTemp && state.Cooling && duration > sensor.CoolMinutes:
|
||||||
PinSwitch(cpin, false, sensor.CoolInvert)
|
PinSwitch(cpin, false, sensor.CoolInvert)
|
||||||
state.Cooling = false
|
state.Cooling = false
|
||||||
state.Changed = future
|
state.Changed = future
|
||||||
// Temperature is too low and the heating switch is on, do nothing
|
// Temperature is good and heating has been happening long enough
|
||||||
case temp < sensor.LowTemp && state.Heating:
|
case temp > sensor.LowTemp && state.Heating && duration > sensor.HeatMinutes:
|
||||||
break
|
PinSwitch(hpin, false, sensor.HeatInvert)
|
||||||
// Temperature is too low, but duration hasn't been counted
|
state.Heating = false
|
||||||
case temp < sensor.LowTemp && duration < 0:
|
state.Changed = future
|
||||||
|
// Temperature just crossed high threshold
|
||||||
|
case temp < sensor.HighTemp && state.Cooling && duration < 0:
|
||||||
state.Changed = time.Now()
|
state.Changed = time.Now()
|
||||||
// Temperature is too low and the duration has been long enough, start heating
|
// Temperature just crossed low threshold
|
||||||
case temp < sensor.LowTemp && duration > sensor.HeatMinutes:
|
case temp > sensor.LowTemp && state.Heating && duration < 0:
|
||||||
PinSwitch(hpin, true, sensor.HeatInvert)
|
|
||||||
state.Heating = true
|
|
||||||
state.Changed = time.Now()
|
state.Changed = time.Now()
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue