1
0
Fork 0
mirror of https://github.com/shouptech/tempgopher.git synced 2026-02-03 08:39:43 +00:00

Backend for selectively disabling heating/cooling

This commit is contained in:
Emma 2018-10-19 14:41:44 -06:00
parent 64ca5a3bfd
commit 0bd6c9bf73
3 changed files with 79 additions and 50 deletions

91
cli.go
View file

@ -8,7 +8,6 @@ import (
"strings" "strings"
"github.com/howeyc/gopass" "github.com/howeyc/gopass"
"github.com/yryz/ds18b20" "github.com/yryz/ds18b20"
) )
@ -101,54 +100,72 @@ func PromptForConfiguration() Config {
panic("Alias cannot be blank") panic("Alias cannot be blank")
} }
fmt.Print("High temperature: ") fmt.Print("Disable cooling? [false]: ")
s.HighTemp, err = strconv.ParseFloat(ReadInput(reader, ""), 64) s.CoolDisable, err = strconv.ParseBool(ReadInput(reader, "false"))
if err != nil { if err != nil {
panic(err) panic(err)
} }
fmt.Print("Cooling minutes: ") if !s.CoolDisable {
s.CoolMinutes, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
fmt.Print("High temperature: ")
s.HighTemp, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
if err != nil {
panic(err)
}
fmt.Print("Cooling minutes: ")
s.CoolMinutes, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
if err != nil {
panic(err)
}
fmt.Print("Cooling GPIO: ")
resp, err := strconv.ParseInt(ReadInput(reader, ""), 10, 32)
s.CoolGPIO = int32(resp)
if err != nil {
panic(err)
}
fmt.Print("Invert cooling switch [false]: ")
s.CoolInvert, err = strconv.ParseBool(ReadInput(reader, "false"))
if err != nil {
panic(err)
}
}
fmt.Print("Disable heating? [false]: ")
s.HeatDisable, err = strconv.ParseBool(ReadInput(reader, "false"))
if err != nil { if err != nil {
panic(err) panic(err)
} }
fmt.Print("Cooling GPIO: ") if !s.HeatDisable {
resp, err := strconv.ParseInt(ReadInput(reader, ""), 10, 32)
s.CoolGPIO = int32(resp)
if err != nil {
panic(err)
}
fmt.Print("Invert cooling switch [false]: ") fmt.Print("Low temperature: ")
s.CoolInvert, err = strconv.ParseBool(ReadInput(reader, "false")) s.LowTemp, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
if err != nil { if err != nil {
panic(err) panic(err)
} }
fmt.Print("Low temperature: ") fmt.Print("Heating minutes: ")
s.LowTemp, err = strconv.ParseFloat(ReadInput(reader, ""), 64) s.HeatMinutes, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
if err != nil { if err != nil {
panic(err) panic(err)
} }
fmt.Print("Heating minutes: ") fmt.Print("Heating GPIO: ")
s.HeatMinutes, err = strconv.ParseFloat(ReadInput(reader, ""), 64) resp, err := strconv.ParseInt(ReadInput(reader, ""), 10, 32)
if err != nil { s.HeatGPIO = int32(resp)
panic(err) if err != nil {
} panic(err)
}
fmt.Print("Heating GPIO: ") fmt.Print("Invert heating switch [false]: ")
resp, err = strconv.ParseInt(ReadInput(reader, ""), 10, 32) s.HeatInvert, err = strconv.ParseBool(ReadInput(reader, "false"))
s.HeatGPIO = int32(resp) if err != nil {
if err != nil { panic(err)
panic(err) }
}
fmt.Print("Invert heating switch [false]: ")
s.HeatInvert, err = strconv.ParseBool(ReadInput(reader, "false"))
if err != nil {
panic(err)
} }
fmt.Print("Enable verbose logging [false]: ") fmt.Print("Enable verbose logging [false]: ")

View file

@ -27,9 +27,11 @@ type Sensor struct {
Alias string `json:"alias" yaml:"alias"` Alias string `json:"alias" yaml:"alias"`
HighTemp float64 `json:"hightemp" yaml:"hightemp"` HighTemp float64 `json:"hightemp" yaml:"hightemp"`
LowTemp float64 `json:"lowtemp" yaml:"lowtemp"` LowTemp float64 `json:"lowtemp" yaml:"lowtemp"`
HeatDisable bool `json:"heatdisable" yaml:"heatdisable"`
HeatGPIO int32 `json:"heatgpio" yaml:"heatgpio"` HeatGPIO int32 `json:"heatgpio" yaml:"heatgpio"`
HeatInvert bool `json:"heatinvert" yaml:"heatinvert"` HeatInvert bool `json:"heatinvert" yaml:"heatinvert"`
HeatMinutes float64 `json:"heatminutes" yaml:"heatminutes"` HeatMinutes float64 `json:"heatminutes" yaml:"heatminutes"`
CoolDisable bool `json:"cooldisable" yaml:"cooldisable"`
CoolGPIO int32 `json:"coolgpio" yaml:"coolgpio"` CoolGPIO int32 `json:"coolgpio" yaml:"coolgpio"`
CoolInvert bool `json:"coolinvert" yaml:"coolinvert"` CoolInvert bool `json:"coolinvert" yaml:"coolinvert"`
CoolMinutes float64 `json:"coolminutes" yaml:"coolminutes"` CoolMinutes float64 `json:"coolminutes" yaml:"coolminutes"`

View file

@ -70,11 +70,18 @@ func ProcessSensor(sensor Sensor, state State) (State, error) {
state.When = time.Now() state.When = time.Now()
var cpin rpio.Pin
var hpin rpio.Pin
// Initialize the pins // Initialize the pins
cpin := rpio.Pin(sensor.CoolGPIO) if !sensor.CoolDisable {
cpin.Output() cpin = rpio.Pin(sensor.CoolGPIO)
hpin := rpio.Pin(sensor.HeatGPIO) cpin.Output()
hpin.Output() }
if !sensor.HeatDisable {
hpin = rpio.Pin(sensor.HeatGPIO)
hpin.Output()
}
// Calculate duration // Calculate duration
duration := time.Since(state.Changed).Minutes() duration := time.Since(state.Changed).Minutes()
@ -83,14 +90,14 @@ func ProcessSensor(sensor Sensor, state State) (State, error) {
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 too high, start cooling // Temperature too high, start cooling
case temp > sensor.HighTemp: case temp > sensor.HighTemp && !sensor.CoolDisable:
PinSwitch(cpin, true, sensor.CoolInvert) PinSwitch(cpin, true, sensor.CoolInvert)
state.Cooling = true state.Cooling = true
PinSwitch(hpin, false, sensor.HeatInvert) // Ensure the heater is off PinSwitch(hpin, false, sensor.HeatInvert) // Ensure the heater is off
state.Heating = false state.Heating = false
state.Changed = future state.Changed = future
// Temperature too low, start heating // Temperature too low, start heating
case temp < sensor.LowTemp: case temp < sensor.LowTemp && !sensor.HeatDisable:
PinSwitch(hpin, true, sensor.HeatInvert) PinSwitch(hpin, true, sensor.HeatInvert)
state.Heating = true state.Heating = true
PinSwitch(cpin, false, sensor.CoolInvert) // Ensure the chiller is off PinSwitch(cpin, false, sensor.CoolInvert) // Ensure the chiller is off
@ -126,13 +133,16 @@ func ProcessSensor(sensor Sensor, state State) (State, error) {
// TurnOffSensor turns off all switches for an individual sensor // TurnOffSensor turns off all switches for an individual sensor
func TurnOffSensor(sensor Sensor) { func TurnOffSensor(sensor Sensor) {
cpin := rpio.Pin(sensor.CoolGPIO) if !sensor.CoolDisable {
cpin.Output() cpin := rpio.Pin(sensor.CoolGPIO)
PinSwitch(cpin, false, sensor.CoolInvert) cpin.Output()
PinSwitch(cpin, false, sensor.CoolInvert)
hpin := rpio.Pin(sensor.HeatGPIO) }
hpin.Output() if !sensor.HeatDisable {
PinSwitch(hpin, false, sensor.HeatInvert) hpin := rpio.Pin(sensor.HeatGPIO)
hpin.Output()
PinSwitch(hpin, false, sensor.HeatInvert)
}
} }
// TurnOffSensors turns off all sensors defined in the config // TurnOffSensors turns off all sensors defined in the config