Turn off speakers and mixer when no one is present
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Dreaded_X 2022-11-15 04:42:32 +01:00
parent 656b040cdc
commit 644f038732
Signed by: Dreaded_X
GPG Key ID: 76BDEC4E165D8AD9

21
main.go
View File

@ -1,10 +1,11 @@
package main package main
import ( import (
"automation/device"
"automation/integration/hue" "automation/integration/hue"
"automation/integration/kasa"
"automation/integration/mqtt" "automation/integration/mqtt"
"automation/integration/ntfy" "automation/integration/ntfy"
"automation/device"
"automation/presence" "automation/presence"
"fmt" "fmt"
"log" "log"
@ -26,7 +27,8 @@ func main() {
h := hue.Connect() h := hue.Connect()
// Kasa // Kasa
// k := kasa.New("10.0.0.32") mixer := kasa.New("10.0.0.49")
speakers := kasa.New("10.0.0.182")
// ntfy.sh // ntfy.sh
n := ntfy.Connect() n := ntfy.Connect()
@ -50,12 +52,23 @@ func main() {
select { select {
case present := <-p.Presence: case present := <-p.Presence:
fmt.Printf("Presence: %t\n", present) fmt.Printf("Presence: %t\n", present)
h.SetFlag(41, present) // Notify users of presence update
n.Presence(present) n.Presence(present)
// Set presence on the hue bridge
h.SetFlag(41, present)
if !present { if !present {
// Turn off all the devices that we manage ourselves
provider.TurnAllOff() provider.TurnAllOff()
// Turn off kasa devices
mixer.SetState(false)
speakers.SetState(false)
// @TODO Turn off nest thermostat
} else { } else {
// In the future this is were we can do things like turning on the lights in the living room // @TODO Turn on the nest thermostat again
} }
case <-h.Events: case <-h.Events: