• Stars
    star
    390
  • Rank 110,242 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🗼 A simple server allowing you to query/control multiple local Harmony Home Hubs over HTTP or MQTT

Harmony API!!

Harmony API is a simple server allowing you to query/control multiple local Harmony Home Hubs and their devices over HTTP or MQTT.

With HTTP, you can simply turn on and off activities, check hub status, and send commands to individual devices with simple HTTP requests from almost any other project.

With MQTT, you can easily monitor the state of your devices as well as set the current activity of your hub or send specific commands per device. This makes it super easy to integrate into your existing home automation setup.

Features

  • Control multiple Harmony hubs.
  • List activities.
  • Get current status, including if everything is off, or what the current activity is.
  • Turn everything off.
  • Start a specific activity.
  • List devices.
  • List device commands.
  • Execute discrete commands for each device.

Setup

script/bootstrap

Settings

Harmony API discovers your hubs automatically. You can optionally add your MQTT broker's host to connect to it.

{
  "mqtt_host": "mqtt://192.168.1.106",
  "mqtt_options": {
      "port": 1883,
      "username": "someuser",
      "password": "somepassword",
      "rejectUnauthorized": false
  },
  "topic_namespace": "home/harmony"
}

mqtt_options is optional, see the mqtt project for allowed host and options values.

Running It

Get up and running immediately with script/server.

Note:

On some distros, you might get an error when running it: /usr/bin/node: No such file or directory

That can probably be fixed by creating a symlink: sudo ln -s `which nodejs` /usr/bin/node

Harmony API will run on port 8282 by default. Use the PORT environment variable to use your own port.

Forever

harmony-api has support for Forever. It uses launchd on OS X to kick it off so that it starts on boot.

Development

You can simply run it by calling script/server. This will run it in development mode with logging to standard out.

Install as Service on OS X

script/install

Install as systemd unit on Linux

sudo script/install-linux

Docker

Installation with Docker is straightforward. Adjust the following command so that /path/to/your/config points to the folder where your want to store your config and run it:

$ docker run --name="harmony-api" -v /path/to/your/config:/config \
    -p 8282:8282 -d jonmaddox/harmony-api

This will launch Harmony API and serve the web interface from port 8282 on your Docker host. Hub discovery requires host networking (--net=host). However, you can specify your Harmony Hub IP address in config.json as hub_ip.

Logging

Harmony API logs all of its requests. In production, it logs to a file at log/logs.log. In development mode, it just logs to stdout.

How to Upgrade to 2.0

Simply run script/upgrade from the root of the project and Harmony API will upgrade to the newest version.

You are then going to have to change anything you integrate with Harmony API to reflect the change in HTTP endpoints and MQTT topics. Read the docs in this README to see how they have changed.

Development

Launch the app via script/server to run it in the development environment.

MQTT Docs

harmony-api can report its state changes to your MQTT broker. Just edit your config file in config/config.json to add your MQTT host and options.

By default harmony-api publishes topics with the namespace of: harmony-api. This can be overriden by setting topic_namespace in your config file.

State Topics

When the state changes on your harmony hub, state topics will be immediately broadcasted over your broker. There's quite a few topics that are broadcasted.

State topics are namespaced by your Harmony hub's name, as a slug. You can rename your hub in the Harmony app.

Here's a list:

Current State

This topic describes the current power state. Message is on or off.

harmony-api/hubs/family-room/state on

Current Activity

This topic describes what the current activity of the hub is. The message is the slug of an activity name.

harmony-api/hubs/family-room/current_activity watch-tv

Activity States

These topics describe the state of each activity that the hub has. The message is on or off. There will a topic for every activity on your hub.

harmony-api/hubs/family-room/activities/watch-tv/state off
harmony-api/hubs/family-room/activities/watch-apple-tv/state on
harmony-api/hubs/family-room/activities/play-xbox-one/state off

Command Topics

You can also command harmony-api to change activities, and issue device and acivity commands by publishing topics. harmony-api listens to these topics and will change to the activity, or issue the command when it sees it.

Switching activities

Just provide the slug of the hub and activity you want to switch to and on as the message. Any use of this topic with the message off will turn everything off.

harmony-api/hubs/family-room/activities/watch-tv/command on

Device commands

Just provide the slug of the hub and the device to control with the command you want to execute. harmony-api/hubs/family-room/devices/tv/command volume-down

To optionally repeat the command any number of times, provide an optional repeat integer. harmony-api/hubs/family-room/devices/tv/command volume-down:5

Current activity commands

Just provide the slug of the hub and the command you want to execute. harmony-api/hubs/family-room/command volume-down

To optionally repeat the command any number of times, provide an optional repeat integer. harmony-api/hubs/family-room/command volume-down:5

HTTP API Docs

This is a quick overview of the HTTP service. Read app.js if you need more info.

Resources

Here's a list of resources that may be returned in a response.

Activity Resource

The Activity resource returns all the information you really need for an Activity set up in your Harmony Hub.

{
  "id": "15233552",
  "slug": "watch-tv",
  "label": "Watch TV",
  "isAVActivity": true
}

Device Resource

The Device resource returns all the information you need to know about the devices set up for the hub.

{
  "id": "38343689",
  "slug": "tivo-premiere",
  "label": "TiVo Premiere"
}

Command Resource

The Command resource returns all the information you really need for a Command to let you execute it.

{
  "name": "ChannelDown",
  "slug": "channel-down",
  "label":"Channel Down"
}

Status Resource

The Status resource returns the current state of your Harmony Hub.

{
  "off": false,
  "current_activity": {
    "id": "15233552",
    "slug": "watch-tv",
    "label": "Watch TV",
    "isAVActivity": true
  }
}

Methods

These are the endpoints you can hit to do things.

Info

Use these endpoints to query the current state of your Harmony Hub.

GET /hubs => {"hubs": ["family-room", "bedroom"] }
GET /hubs/:hub_slug/status => StatusResource
GET /hubs/:hub_slug/commands => {"commands": [CommandResource, CommandResource, ...]}
GET /hubs/:hub_slug/activities => {"activities": [ActivityResource, ActivityResource, ...]}
GET /hubs/:hub_slug/activities/:activity_slug/commands => {"commands": [CommandResource, CommandResource, ...]}
GET /hubs/:hub_slug/devices => {"devices": [DeviceResource, DeviceResource, ...]}
GET /hubs/:hub_slug/devices/:device_slug/commands => {"commands": [CommandResource, CommandResource, ...]}

Control

Use these endpoints to control your devices through your Harmony Hub.

PUT /hubs/:hub_slug/off => {message: "ok"}
POST /hubs/:hub_slug/commands/:command_slug => {message: "ok"}
POST /hubs/:hub_slug/commands/:command_slug?repeat=3 => {message: "ok"}
POST /hubs/:hub_slug/activities/:activity_slug => {message: "ok"}
POST /hubs/:hub_slug/devices/:device_slug/commands/:command_slug => {message: "ok"}
POST /hubs/:hub_slug/devices/:device_slug/commands/:command_slug?repeat=3 => {message: "ok"}

Contributions

  • fork
  • create a feature branch
  • open a Pull Request

More Repositories

1

dasher

🔘 A simple way to bridge your Amazon Dash buttons to HTTP services
JavaScript
707
star
2

magic-cards

🎩 Queue music, play movies, or trigger events with RFID cards.
JavaScript
566
star
3

magick-installer

ImageMagick installer script because macports sucks
Shell
486
star
4

actions

A collection of useful GitHub Actions
Dockerfile
393
star
5

kart

🎮 Frontend for RetroArch
CoffeeScript
367
star
6

itunes-api

🎵 A simple server providing a RESTful service for controlling iTunes
JavaScript
193
star
7

wallop

📺 A transcoding server for your HDHomeRun Prime
Ruby
167
star
8

imdb-party

IMDB client using the IMDB API that their iPhone app uses
Ruby
116
star
9

tvdb_party

Simple Ruby library to talk to thetvdb.com
Ruby
72
star
10

pluto-for-channels

📺 M3U generator optimized for Channels' custom channels.
JavaScript
69
star
11

imdb

Don't use this anymore, use maddox/imdb-party
Ruby
46
star
12

mac-api

Command your Mac from afar
Shell
32
star
13

categories

Community driven repo for awesome Objective-C categories
28
star
14

mgtwitterengine

Git fork of MGTwitterEngine
Objective-C
26
star
15

piano

Because you know you hate Apple's Stats
Ruby
26
star
16

arcade1up-tools

Arcade1Up Modding
20
star
17

freelancer

For your freelancing yo!
JavaScript
19
star
18

channels-strmlnks

Example stream links for Channels
18
star
19

gpi-tools

GPI Case Resources
18
star
20

instagrammer

Get personal RSS feed access to your Instagrams
JavaScript
15
star
21

impawards

Simple library to find high quality posters for movies
Ruby
10
star
22

regexkit

a fork of the objective-c RegexKit regular expression framework
10
star
23

tvdb

Ruby library for the TVDB
Ruby
8
star
24

movieposterdb

a simple ruby client for the MoviePosterDB api
Ruby
7
star
25

cbs_sports

A quickie library to read in sports scores
Ruby
6
star
26

trailers

library for retrieving trailer movies
Ruby
6
star
27

aim_status_helper

Rails plugin that will display a user's AIM status
Ruby
6
star
28

xbmc-library

Ruby library to talk to the XBMC sqlite database
Ruby
5
star
29

broadcatcher

find your favorite shows via nzb
Ruby
5
star
30

magic-cards-docker

Simple repo to get started with Magic Cards & Sonos right away.
Shell
5
star
31

college-humor-plex

Plex plugin for College Humor
Python
4
star
32

star-search

Cache, feed, and search your Campfire stars
Ruby
4
star
33

cocoaheads_gltouches

iPhone GL example app
Objective-C
3
star
34

giant_bomb

A simple Ruby library to talk to GiantBomb
Ruby
3
star
35

xbmc-remote

XBMC iPhone Remote
3
star
36

webcam-resolver

📺 Fetch m3u8 URLs for hosted webcams.
Ruby
3
star
37

bracket_busters

Provides scores for NCAA tournament
JavaScript
3
star
38

wrapper

GIT Mirror of The Worlds Worst Project
2
star
39

app_wiki

a place to store your app stuff
Ruby
2
star
40

broken.com

2
star
41

iphone2itunes

Browse and Watch the videos in your iTunes library from your iPhone.
JavaScript
2
star
42

test

2
star
43

mobile_scores

Finally, a simple freaking way to get your scores via your mobile
JavaScript
2
star
44

mschrag.github.com

mschrag.github.com
2
star
45

SiriProxy-Pugme

A simple SiriProxy plugin that will return a random photo of a pug
Ruby
2
star
46

star-searcher

Simple Ruby Client for Star Search - http://github.com/maddox/star-search
Ruby
2
star
47

slideshower

Simple way to generate the json that will power a future iPhone app that does simple slide shows
Ruby
2
star
48

Aeon-Slim

Slimified Aeon skin adjusted just for Plex
Python
2
star
49

nightscout-s3-proxy

🩸 Simple proxy for Nightscout data to S3
Shell
2
star
50

vlc

C
1
star
51

noodle

JavaScript
1
star
52

npe

npe
1
star
53

lol

JavaScript
1
star
54

rpi-docker-node-sonos-http-api

Docker wrapper for node-sonos-http-api for the Raspberry Pi
1
star
55

twictures

The code behind Twictur.es
Ruby
1
star