Skip to content

Instantly share code, notes, and snippets.

@kcollasarundell
Created July 29, 2020 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kcollasarundell/0769c59ff0c80ebe880363c5801cd94f to your computer and use it in GitHub Desktop.
Save kcollasarundell/0769c59ff0c80ebe880363c5801cd94f to your computer and use it in GitHub Desktop.
ring the doorbell
package main
import (
"sync"
"time"
"github.com/evalphobia/google-home-client-go/googlehome"
"github.com/hashicorp/mdns"
)
func main() {
wg := sync.WaitGroup{}
entriesCh := make(chan *mdns.ServiceEntry, 4)
wg.Add(1)
go func() {
defer wg.Done()
mdns.Lookup("_googlerpc._tcp", entriesCh)
close(entriesCh)
}()
for g := range entriesCh {
wg.Add(1)
go func(address string) {
defer wg.Done()
cli, err := googlehome.NewClientWithConfig(googlehome.Config{
Hostname: address,
Lang: "en",
Accent: "GB",
})
if err != nil {
panic(err)
}
oldvolume, _ := cli.GetVolume()
// Speak text on Google Home.
cli.SetVolume(0.5)
cli.Notify("There is someone at the door")
time.Sleep(4 * time.Second)
//Kills the running Application (Disconnects from Google Home)
cli.SetVolume(oldvolume)
cli.QuitApp()
}(g.AddrV4.String())
}
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment