package module
Version: v0.2.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2022 License: Apache-2.0 Imports: 0 Imported by: 0



package gohmekit implements the HomeKit Accessory Protocol (hap).

See the Example to get started.

This library wouldn't have been possible without the amazing open-source work of Matthias Hochgatterer:

package main

import (


func main() {
	// store the state in a json file (secret key, pin, paired devices...)
	jsonFile, err := storage.NewJSONFile("db.json")
	if err != nil {
		fmt.Printf("could not get json file storage: %v\n", err)

	shellyPlug, _ := shelly.NewPlug("http://localhost/")

	// create an accessory handler.
	port := 51821 // same port used by homebridge (can be changed)
	accessoryServer := hapip.PrepareServer(
		&http.Server{Addr: ":" + strconv.Itoa(port)},
			// If multiple accessories are provided, the number 1 must be a bridge
			// (which is required per the spec to have the service.AccessoryInformation).
			1: accessory.Basic{
				Name: "Gohmebridge",
				Identify: func(bool) error {
					fmt.Println("TODO: blink a led or make a tone (not paired yet)")
					return errors.New("identify is not implemented")

				HAPProtocolVersion: "1.1.0",
			// bridged devices
			2: shellyPlug,

	// pairing server will manage connection encryption
	// and handle the decrypted requests to the given accessory server.
	pairingServer := pairing.NewServer(accessoryServer, jsonFile, jsonFile,
		pairing.WithIdentify(func() {
			fmt.Println("TODO: blink a led or make a tone (accessory is paired)")

	// announce the accessory as a bridge via bonjour (zeroconf)
	stopDiscovery, err := jsonFile.DiscoveryService(
	if err != nil {
		fmt.Printf("could not start announcing: %v\n", err)
	defer stopDiscovery()

	// start serving
	go pairingServer.ListenAndServe() //nolint:errcheck

	time.Sleep(10 * time.Millisecond)


Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL