All Projects → brutella → Hc

brutella / Hc

Licence: apache-2.0
hc is a lightweight framework to develop HomeKit accessories in Go.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Hc

Homebridge Http Switch
Powerful http switch for Homebridge: https://github.com/homebridge/homebridge
Stars: ✭ 111 (-93.31%)
Mutual labels:  homekit, hap
Homekit Ws2812b Controller
ESP8266 based  Homekit controller for WS2812B lightstrips with WS2812FX support🌈
Stars: ✭ 110 (-93.37%)
Mutual labels:  homekit, hap
Ruby home
Ruby HAP Server - HomeKit support for the Rubyist
Stars: ✭ 155 (-90.66%)
Mutual labels:  homekit, hap
Secure Video Specification
Documentation and examples of the HomeKit Secure-Video Specification
Stars: ✭ 99 (-94.04%)
Mutual labels:  homekit, hap
Hap
Swift implementation of the Homekit Accessory Protocol
Stars: ✭ 309 (-81.39%)
Mutual labels:  homekit, hap
aiohomekit
asyncio for homekit
Stars: ✭ 37 (-97.77%)
Mutual labels:  homekit, hap
Hap Nodejs
Node.js implementation of the HomeKit Accessory Protocol (HAP)
Stars: ✭ 2,541 (+53.07%)
Mutual labels:  homekit, hap
Esp32 Homekit
ESP-32 implementation of Apple Homekit Accessory Protocol(HAP)
Stars: ✭ 331 (-80.06%)
Mutual labels:  homekit, hap
HAS
Homekit Accessory Server
Stars: ✭ 53 (-96.81%)
Mutual labels:  homekit, hap
ESP8266-HomeKit-Air-Quality-Sensor-Elgato-Eve-Room
ESP8266 based  Homekit Indoor Air Quality sensor that acts like Eve Room🌱
Stars: ✭ 58 (-96.51%)
Mutual labels:  homekit, hap
Homebridge
HomeKit support for the impatient
Stars: ✭ 19,073 (+1048.98%)
Mutual labels:  homekit, hap
Hap Python
A python implementation of the HomeKit Accessory Protocol (HAP)
Stars: ✭ 381 (-77.05%)
Mutual labels:  homekit, hap
Homekitcam
A project to make a Raspberry Pi driven, HomeKit Enabled camera.
Stars: ✭ 69 (-95.84%)
Mutual labels:  homekit
Homebridge Edomoticz
Domoticz Homebridge-Plugin
Stars: ✭ 104 (-93.73%)
Mutual labels:  homekit
Esp Homekit Devices
Project to add native Apple HomeKit support to any device with an ESP8266 chip
Stars: ✭ 1,153 (-30.54%)
Mutual labels:  homekit
Arduino Homekit Esp32
[Deprecated] Native Apple HomeKit accessory implementation for the ESP32 Arduino core.
Stars: ✭ 59 (-96.45%)
Mutual labels:  homekit
Particle Hap
Connect your Photon to HomeKit.
Stars: ✭ 50 (-96.99%)
Mutual labels:  homekit
Homebridge Hubitat Tonesto7
Hubitat Homebridge Plugin
Stars: ✭ 45 (-97.29%)
Mutual labels:  homekit
Homebridge Netatmo
This is a homebridge plugin for several netatmo devices
Stars: ✭ 99 (-94.04%)
Mutual labels:  homekit
Homebridge Loxone Ws
Websocket based Loxone plugin for homebridge
Stars: ✭ 37 (-97.77%)
Mutual labels:  homekit

hc

GoDoc Widget Travis Widget

hc is a lightweight framework to develop HomeKit accessories in Go. It abstracts the HomeKit Accessory Protocol (HAP) and makes it easy to work with services and characteristics.

hc handles the underlying communication between HomeKit accessories and clients. You can focus on implementing the business logic for your accessory, without having to worry about the protocol.

Here are some projects which use hc.

What is HomeKit?

HomeKit is a set of protocols and libraries from Apple. It is used by Apple's platforms to communicate with smart home appliances. A non-commercial version of the documentation is now available on the HomeKit developer website.

HomeKit is fully integrated into iOS since iOS 8. Developers can use HomeKit.framework to communicate with accessories using high-level APIs.

Home+.app

I've developed the Home+ app to control HomeKit accessories from iPhone, iPad, and Apple Watch. If you want to support hc, please purchase Home from the App Store. That would be awesome. ❤️

Checkout the official website.

Features

Getting Started

  1. Install and set up Go

  2. Create your own HomeKit accessory 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
     make run
    
  3. Pair with your HomeKit App of choice (e.g. Home)

Go Modules

hc supports Go module since v1.0.0. Make sure to set the environment variable GO111MODULE=on.

Example

See _example for a variety of examples.

Basic switch accessory

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() {
    // create an accessory
    info := accessory.Info{Name: "Lamp"}
    ac := accessory.NewSwitch(info)
    
    // configure the ip transport
    config := hc.Config{Pin: "00102003"}
    t, err := hc.NewIPTransport(config, ac.Accessory)
    if err != nil {
        log.Panic(err)
    }
    
    hc.OnTermination(func(){
        <-t.Stop()
    })
    
    t.Start()
}

You can define more specific accessory info, if you want.

info := accessory.Info{
    Name: "Lamp",
    SerialNumber: "051AC-23AAM1",
    Manufacturer: "Apple",
    Model: "AB",
    FirmwareRevision: "1.0.1",
}

Events

The library provides callback functions, which let you know when a clients updates a characteristic value. The following example shows how to get notified when the On characteristic value changes.

ac.Switch.On.OnValueRemoteUpdate(func(on bool) {
    if on == true {
        log.Println("Switch is on")
    } else {
        log.Println("Switch is off")
    }
})

When the switch is turned on "the analog way", you should set the state of the accessory.

ac.Switch.On.SetValue(true)

Multiple Accessories

When you create an IP transport, you can specify more than one accessory like this

bridge := accessory.NewBridge(...)
outlet := accessory.NewOutlet(...)
lightbulb := accessory.NewColoredLightbulb(...)

hc.NewIPTransport(config, bridge.Accessory, outlet.Accessory, lightbulb.Accessory)

By doing so, the bridge accessory will become a HomeKit bridge. The outlet and lightbulb are the bridged accessories.

When adding the accessories to HomeKit, iOS only shows the bridge accessory. Once the bridge was added, the other accessories appear automatically.

HomeKit requires that every accessory has a unique id, which must not change between system restarts. hc automatically assigns the ids for you based on the order in which the accessories are added to the bridge.

But I recommend that you specify the accessory id yourself, via the accessory.Config.ID field, like this.

bridge := accessory.NewBridge(accessory.Info{Name: "Bridge", ID: 1})
outlet := accessory.NewOutlet(accessory.Info{Name: "Outlet", ID: 2})
lightbulb := accessory.NewColoredLightbulb(accessory.Info{Name: "Light", ID: 3})

Accessory Architecture

HomeKit uses a hierarchical architecture to define accessories, services and characeristics. At the root level there is an accessory. Every accessory contains services. And every service contains characteristics.

For example a lightbulb accessory contains a lightbulb service. This service contains characteristics like on and brightness.

There are predefined accessories, services and characteristics available in HomeKit. Those types are defined in the packages accessory, service, characteristic.

Contact

Matthias Hochgatterer

Website: https://hochgatterer.me

Github: https://github.com/brutella

Twitter: https://twitter.com/brutella

License

hc is available under the Apache License 2.0 license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].