HomeControl is an implementation of the HomeKit Accessory Protocol (HAP) to create your own HomeKit accessory in Go. HomeKit is a set of protocols and libraries to access devices for Home Automation. The actual protocol documentation is only available to MFi members.
You can use this library to make existing Home Automation devices HomeKit compatible. I've already developed the following HomeKit bridges with in:
HomeKit is fully integrated since iOS 8. Developers can use the HomeKit framework to communicate with HomeKit using high-level APIs. I've developed the Home app (for iPhone, iPad, Apple Watch) to control HomeKit accessories. If you purchase Home on the App Store, you not only support my work but also get an awesome iOS app. Thank you.
Once you've setup HomeKit, you can use Siri to interact with your accessories using voice command (Hey Siri, turn off the lights in the living room).
- Full implementation of the HAP in Go
- Built-in service announcement via mDNS using bonjour
- Runs on multiple platforms (already in use on Linux and OS X)
- Documentation: http://godoc.org/github.com/brutella/hc
-
Create your own HomeKit bridge or clone an existing one (e.g. hklight)
cd $GOPATH/src # Clone project git clone https://github.com/brutella/hklight && cd hklight # Run the project go run hklightd.go
-
Pair with your HomeKit App of choice (e.g. Home)
Create a simple on/off switch, which is accessible via IP and secured using the pin 00102003.
package main
import (
"log"
"github.com/brutella/hc"
"github.com/brutella/hc/accessory"
)
func main() {
info := accessory.Info{
Name: "Lamp",
}
acc := accessory.NewSwitch(info)
config := hc.Config{Pin: "00102003"}
t, err := hc.NewIPTransport(config, acc.Accessory)
if err != nil {
log.Panic(err)
}
hc.OnTermination(func(){
t.Stop()
})
t.Start()
}
You should change some default values for your own needs
info := accessory.Info{
Name: "Lamp",
SerialNumber: "051AC-23AAM1",
Manufacturer: "Apple",
Model: "AB",
Firmware: "1.0.1",
}
You get a callback when the power state of a switch changed by a client.
acc.Switch.On.OnValueRemoteUpdate(func(on bool) {
if on == true {
log.Println("Client changed switch to on")
} else {
log.Println("Client changed switch to off")
}
})
When the switch is turned on "the analog way", you should set the state of the accessory.
acc.Switch.On.SetValue(true)
A complete example is available in _example/example.go
.
The HomeKit model hierarchy looks like this:
Accessory
|-- Accessory Info Service
| |-- Identify Characteristic
| |-- Manufacturer Characteristic
| |-- Model Characteristic
| |-- Name Characteristic
| |-- Serial Characteristic
|
|-- * Service
| |-- * Characteristic
HomeKit accessories are container for services. Every accessory must provide the Accessory Information Service
. Every service provides one or more characteristics (a characteristic might be the power state of an outlet). HomeKit has predefined service and characteristic types, which are supported by iOS. You can define your own service and characteristic types, but it's recommended to use predefined ones.
This library provides all HomeKit characteristics (see characteristic
package) and services (see service
package).
You can also find common accessory types like lightbulbs, outlets, thermostats in the accessory
package.
HomeControl uses vendor directories (vendor/
) to integrate the following libraries
github.com/tadglines/go-pkgs/crypto/srp
for SRP algorithmgithub.com/agl/ed25519
for ed25519 signaturegithub.com/gosexy/to
for type conversiongithub.com/oleksandr/bonjour
for mDNS
Matthias Hochgatterer
Github: https://github.com/brutella
Twitter: https://twitter.com/brutella
HomeControl is available under a non-commercial license. See the LICENSE file for more info.