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:
parent
64ca5a3bfd
commit
0bd6c9bf73
3 changed files with 79 additions and 50 deletions
21
cli.go
21
cli.go
|
|
@ -8,7 +8,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/howeyc/gopass"
|
||||
|
||||
"github.com/yryz/ds18b20"
|
||||
)
|
||||
|
||||
|
|
@ -101,6 +100,14 @@ func PromptForConfiguration() Config {
|
|||
panic("Alias cannot be blank")
|
||||
}
|
||||
|
||||
fmt.Print("Disable cooling? [false]: ")
|
||||
s.CoolDisable, err = strconv.ParseBool(ReadInput(reader, "false"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !s.CoolDisable {
|
||||
|
||||
fmt.Print("High temperature: ")
|
||||
s.HighTemp, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
|
||||
if err != nil {
|
||||
|
|
@ -125,6 +132,15 @@ func PromptForConfiguration() Config {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Print("Disable heating? [false]: ")
|
||||
s.HeatDisable, err = strconv.ParseBool(ReadInput(reader, "false"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if !s.HeatDisable {
|
||||
|
||||
fmt.Print("Low temperature: ")
|
||||
s.LowTemp, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
|
||||
|
|
@ -139,7 +155,7 @@ func PromptForConfiguration() Config {
|
|||
}
|
||||
|
||||
fmt.Print("Heating GPIO: ")
|
||||
resp, err = strconv.ParseInt(ReadInput(reader, ""), 10, 32)
|
||||
resp, err := strconv.ParseInt(ReadInput(reader, ""), 10, 32)
|
||||
s.HeatGPIO = int32(resp)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
@ -150,6 +166,7 @@ func PromptForConfiguration() Config {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Print("Enable verbose logging [false]: ")
|
||||
s.Verbose, err = strconv.ParseBool(ReadInput(reader, "false"))
|
||||
|
|
|
|||
|
|
@ -27,9 +27,11 @@ type Sensor struct {
|
|||
Alias string `json:"alias" yaml:"alias"`
|
||||
HighTemp float64 `json:"hightemp" yaml:"hightemp"`
|
||||
LowTemp float64 `json:"lowtemp" yaml:"lowtemp"`
|
||||
HeatDisable bool `json:"heatdisable" yaml:"heatdisable"`
|
||||
HeatGPIO int32 `json:"heatgpio" yaml:"heatgpio"`
|
||||
HeatInvert bool `json:"heatinvert" yaml:"heatinvert"`
|
||||
HeatMinutes float64 `json:"heatminutes" yaml:"heatminutes"`
|
||||
CoolDisable bool `json:"cooldisable" yaml:"cooldisable"`
|
||||
CoolGPIO int32 `json:"coolgpio" yaml:"coolgpio"`
|
||||
CoolInvert bool `json:"coolinvert" yaml:"coolinvert"`
|
||||
CoolMinutes float64 `json:"coolminutes" yaml:"coolminutes"`
|
||||
|
|
|
|||
|
|
@ -70,11 +70,18 @@ func ProcessSensor(sensor Sensor, state State) (State, error) {
|
|||
|
||||
state.When = time.Now()
|
||||
|
||||
var cpin rpio.Pin
|
||||
var hpin rpio.Pin
|
||||
// Initialize the pins
|
||||
cpin := rpio.Pin(sensor.CoolGPIO)
|
||||
if !sensor.CoolDisable {
|
||||
cpin = rpio.Pin(sensor.CoolGPIO)
|
||||
cpin.Output()
|
||||
hpin := rpio.Pin(sensor.HeatGPIO)
|
||||
}
|
||||
|
||||
if !sensor.HeatDisable {
|
||||
hpin = rpio.Pin(sensor.HeatGPIO)
|
||||
hpin.Output()
|
||||
}
|
||||
|
||||
// Calculate duration
|
||||
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:
|
||||
log.Println("Invalid state! Temperature is too high AND too low!")
|
||||
// Temperature too high, start cooling
|
||||
case temp > sensor.HighTemp:
|
||||
case temp > sensor.HighTemp && !sensor.CoolDisable:
|
||||
PinSwitch(cpin, true, sensor.CoolInvert)
|
||||
state.Cooling = true
|
||||
PinSwitch(hpin, false, sensor.HeatInvert) // Ensure the heater is off
|
||||
state.Heating = false
|
||||
state.Changed = future
|
||||
// Temperature too low, start heating
|
||||
case temp < sensor.LowTemp:
|
||||
case temp < sensor.LowTemp && !sensor.HeatDisable:
|
||||
PinSwitch(hpin, true, sensor.HeatInvert)
|
||||
state.Heating = true
|
||||
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
|
||||
func TurnOffSensor(sensor Sensor) {
|
||||
if !sensor.CoolDisable {
|
||||
cpin := rpio.Pin(sensor.CoolGPIO)
|
||||
cpin.Output()
|
||||
PinSwitch(cpin, false, sensor.CoolInvert)
|
||||
|
||||
}
|
||||
if !sensor.HeatDisable {
|
||||
hpin := rpio.Pin(sensor.HeatGPIO)
|
||||
hpin.Output()
|
||||
PinSwitch(hpin, false, sensor.HeatInvert)
|
||||
}
|
||||
}
|
||||
|
||||
// TurnOffSensors turns off all sensors defined in the config
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue