Code Monkey home page Code Monkey logo

hc's Introduction

HomeControl

Build Status

HomeControl is an implementation of the HomeKit Accessory Protocol (HAP) to create your own HomeKit accessory and bridges. HomeKit bridges make non-HomeKit accessories available to HomeKit by acting as a middleman.

Overview

HomeKit is a set of protocols and libraries to access accessories for Home Automation. Unfortunately the protocol is not open source and the official documentation is only available to MFi members. HomeControl is a complete implementation of the protocol in Go and does not depend on any OS.

HomeKit Client

I've made an app for iPhone, iPad and Apple Watch called Home to control any HomeKit accessory. If you purchase Home on the App Store, you not only support my work but also get an awesome iOS app. Thank you.

Features

Getting Started

  1. Install Go

  2. Setup Go workspace

  3. 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
     
     # Install dependencies
     go get
     
     # Run the project
     go run hklightd.go
    
  4. Pair with your HomeKit App of choice (e.g. Home)

API Example

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/hap"
    "github.com/brutella/hc/model"
    "github.com/brutella/hc/model/accessory"
)

func main() {
	info := model.Info{
		Name: "Lamp",
	}
	sw := accessory.NewSwitch(info)
    
	t, err := hap.NewIPTransport("00102003", sw.Accessory)
	if err != nil {
		log.Fatal(err)
	}
    
    hap.OnTermination(func(){
        t.Stop()
    })
    
	t.Start()
}

You should change some default values for your own needs

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

Callbacks

You get a callback when the power state of a switch changed by a client.

sw.OnStateChanged(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.

sw.SetOn(true)

A complete example is available in _example/example.go.

Dependencies

HomeControl depends on the following libraries

  • github.com/tadglines/go-pkgs/crypto/srp for SRP algorithm
  • github.com/codahale/chacha20 for chacha20 poly1305 algorithm
  • github.com/golang/cryptofor chacha20 poly1305 algorithm and curve25519 key generation
  • github.com/agl/ed25519 for ed25519 signature
  • github.com/gosexy/to for type conversion
  • github.com/oleksandr/bonjour for mDNS

HomeKit Accessories

HomeControl currently supports the following accessory types

  • Switch
  • Outlet
  • Light Bulb
  • Thermostat
  • Thermometer (same as the Thermostat accessory which just readonly services)

The metdata dump in iOS 8.3 (found by @KhaosT) includes a list of required and optional characteristics.

ServiceRequiredOptional
Accessory Informationname, manufacturer, model, serial-number, identifyfirmware.revision, hardware.revision, software.revision
Switchonname
Outleton, outlet-in-usename
Fanonname, rotation.direction, rotation.speed
Thermostatheating-cooling.current, heating-cooling.target, temperature.current, temperature.target, temperature.unitsname, relative-humidity.current, relative-humidity.target, temperature.cooling-threshold, temperature.heating-threshold
Garage Door Openerdoor-state.current, door-state.target, obstruction-detectedlock-mechanism.current-state, lock-mechanism.target-state, name
Light Bulbonname, brightness, hue, saturation
Lock Managementversion, lock-management.control-pointadministrator-only-access, audio-feedback, door-state.current, lock-management.auto-secure-timeout, lock-mechanism.last-known-action, logs, motion-detected
Lock Mechanismlock-mechanism.current-state, lock-mechanism.target-statename

The HomeKit framework on iOS uses the same order as in the json. I assume that clients displays them in the same order to the user.

iOS 9

iOS 9 supports new type of accessories and includes new service and characteristic types. The new types are already available in model/service/constants.go and model/characteristic/constants.go.

Contact

Matthias Hochgatterer

Github: https://github.com/brutella

Twitter: https://twitter.com/brutella

License

HomeControl is available under a non-commercial license. See the LICENSE file for more info.

hc's People

Contributors

brutella avatar eaigner avatar mxlje avatar tomtaylor avatar

Stargazers

Mike Meaney avatar

Watchers

James Cloos avatar Mike Meaney avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.