2014-11-03

config

More material love for interface

6 days ago

docs

Updated screenshots

16 hours ago

homeassistant

state-badge no longer sets url(undefined) as background-image

18 hours ago

.gitignore

Home Assistant contains pre-compiled version of polymer components

10 days ago

.gitmodules

Phue: Switched to GIT-version because pip version lacks behind

20 hours ago

Dockerfile

Starting home assistant is now done via __main__.py

19 hours ago

LICENSE

Added MIT license

a year ago

README.md

Starting home assistant is now done via __main__.py

19 hours ago

build_frontend

Renamed build_polymer to build_frontend

19 hours ago

pylintrc

Added pylint configuration

25 days ago

requirements.txt

Phue: Switched to GIT-version because pip version lacks behind

20 hours ago

Home Assistant is a home automation platform running on Python 3. The goal of Home Assistant is to be able to track and control all devices at home and offer a platform for automating control.

It offers the following functionality through built-in components:

Track if devices are home by monitoring connected devices to a wireless router (supportingOpenWrt, Tomato, Netgear)

Track and control Philips Hue lights

Track and control WeMo switches

Track and control Google Chromecasts

Track running services by monitoring ps output

Turn on the lights when people get home after sun set

Turn on lights slowly during sun set to compensate for light loss

Turn off all lights and devices when everybody leaves the house

Offers web interface to monitor and control Home Assistant

Offers a REST API for easy integration with other projects (see related projects for Android and Ruby support)

Ability to have multiple instances of Home Assistant work together

Home Assistant also includes functionality for controlling HTPCs:

Simulate key presses for Play/Pause, Next track, Prev track, Volume up, Volume Down

Download files

Open URLs in the default browser



The system is built modular so support for other devices or actions can be implemented easily. See also the section on architecture and the section on customizing.

Installation instructions / Quick-start guide

Running Home Assistant requires that python3 and the packages pyephem and requests are installed.

Run the following code to get up and running with the minimum setup:

This will start the Home Assistant server and create an initial configuration file in config/home-assistant.conf that is setup for demo mode. It will launch its web interface on http://127.0.0.1:8123. The default password is ‘password’.

If you’re using Docker, you can use

After you got the demo mode running it is time to enable some real components and get started. An example configuration file has been provided in /config/home-assistant.conf.example.

Philips Hue

To get Philips Hue working you will have to connect Home Assistant to the Hue bridge.

Run the following command from your config dir and follow the instructions:

After that add the following lines to your home-assistant.conf:

Wireless router

Your wireless router is used to track which devices are connected. Three different types of wireless routers are currently supported: tomato, netgear and luci (OpenWRT). To get started add the following lines to your home-assistant.conf (example for Netgear):

Note on tomato: Tomato requires an extra config variable called http_id. The value can be obtained by logging in to the Tomato admin interface and search for http_id in the page source code.

Note on luci: before the Luci scanner can be used you have to install the luci RPC package on OpenWRT:opkg install luci-mod-rpc.

Once tracking the device_tracker component will maintain a file in your config dir calledknown_devices.csv. Edit this file to adjust which devices have to be tracked.

Further customizing Home Assistant

Home Assistant can be extended by components. Components can listen for- or trigger events and offer services. Components are written in Python and can do all the goodness that Python has to offer.

Home Assistant offers built-in components but it is easy to built your own. An example component can be found in /config/custom_components/example.py.

Note: Home Assistant will use the directory that contains your config file as the directory that holds your customizations. The included file start.py points this at the /config folder but this can be placed anywhere on the filesystem.

A component will be loaded on start if a section (ie. [light]) for it exists in the config file or a module that depends on the component is loaded. When loading a component Home Assistant will check the following paths:

<config file directory>/custom_components/<component name>

homeassistant/components/<component name> (built-in components)

A component will be validated upon loading. It will only successfully Upon loading of a component it will be validated to see if the required fields (DOMAIN, DEPENDENCIES) and required method ( setup(hass, config) ) are available.

Once loaded, a component will only be setup if all dependencies can be loaded and are able to setup. Keep an eye on the logs to see if loading and setup of your component went well.

Warning: You can override a built-in component by offering a component with the same name in your custom_components folder. This is not recommended and may lead to unexpected behavior!

After a component is loaded the bootstrapper will call its setup method setup(hass, config):

Parameter

Description

hass

The Home Assistant object. Call its methods to track time, register services or listen for events. Overview of available methods.

config

A dict containing the configuration. The keys of the config-dict are component names and the value is another dict with configuration attributes.

Example on using the configuration parameter

If your configuration file containes the following lines:

Then in the setup-method of your component you will be able to refer to config[example][host] to get the value paulusschoutsen.nl.

Architecture

The core of Home Assistant exists of three parts; an Event Bus for firing events, a State Machine that keeps track of the state of things and a Service Registry to manage services.



For example to control the lights there are two components. One is the device_tracker that polls the wireless router for connected devices and updates the state of the tracked devices in the State Machine to be either ‘Home’ or ‘Not Home’.

When a state is changed a state_changed event is fired for which the device_sun_light_trigger component is listening. Based on the new state of the device combined with the state of the sun it will decide if it should turn the lights on or off:

By using the Bus as a central communication hub between components it is easy to replace components or add functionality. For example if you would want to change the way devices are detected you only have to write a component that updates the device states in the State Machine.

Components

sun Tracks the state of the sun and when the next sun rising and setting will occur. Depends on: config variables common/latitude and common/longitude Action: maintains state of weather.sun including attributes next_rising and next_setting

device_tracker Keeps track of which devices are currently home. Action: sets the state per device and maintains a combined state called all_devices. Keeps track of known devices in the fileconfig/known_devices.csv.

light Keeps track which lights are turned on and can control the lights. It has 4 built-in light profiles which you’re able to extend by putting a light_profiles.csv file in your config dir.

Registers services light/turn_on and light/turn_off to turn a or all lights on or off.

Optional service data:

entity_id – only act on specific light. Else targets all.

transition_seconds – seconds to take to swithc to new state.

profile – which light profile to use.

xy_color – two comma seperated floats that represent the color in XY

rgb_color – three comma seperated integers that represent the color in RGB

brightness – integer between 0 and 255 for how bright the color should be

wemo Keeps track which WeMo switches are in the network, their state and allows you to control them.

Registers services wemo/turn_on and wemo/turn_off to turn a or all wemo switches on or off.

Optional service data:

entity_id – only act on specific WeMo switch. Else targets all.

device_sun_light_trigger Turns lights on or off using a light control component based on state of the sun and devices that are home. Depends on: light control, track_sun, device_tracker Action:

Turns lights off when all devices leave home.

Turns lights on when a device is home while sun is setting.

Turns lights on when a device gets home after sun set.

chromecast Registers 7 services to control playback on a Chromecast: turn_off, volume_up,volume_down, media_play_pause, media_play, media_pause, media_next_track.

Registers three services to start playing YouTube video’s on the ChromeCast.

Service chromecast/play_youtube_video starts playing the specified video on the YouTube app on the ChromeCast. Specify video using video in service_data.

Service chromecast/start_fireplace will start a YouTube movie simulating a fireplace and thechromecast/start_epic_sax service will start playing Epic Sax Guy 10h version.

keyboard Registers services that will simulate key presses on the keyboard. It currently offers the following Buttons as a Service (BaaS): keyboard/volume_up, keyboard/volume_down andkeyboard/media_play_pause This actor depends on: PyUserInput

downloader Registers service downloader/download_file that will download files. File to download is specified in the url field in the service data.

browser Registers service browser/browse_url that opens url as specified in event_data in the system default browser.

Rest API

Home Assistent runs a webserver accessible on port 8123.

At http://127.0.0.1:8123/ it will provide an interface allowing you to control Home Assistant.

At http://localhost:8123/api/ it provides a password protected API.

In the package homeassistant.remote a Python API on top of the HTTP API can be found.

All API calls have to be accompanied by the header “HA-Access” with as value the api password (as specified in home-assistant.conf). The API returns only JSON encoded objects. Successful calls will return status code 200 or 201.

Other status codes that can occur are:

400 (Bad Request)

401 (Unauthorized)

404 (Not Found)

405 (Method not allowed)

The api supports the following actions:

/api – GET

Returns message if API is up and running.

/api/events – GET

Returns a dict with as keys the events and as value the number of listeners.

/api/services – GET

Returns a dict with as keys the domain and as value a list of published services.

/api/states – GET

Returns a dict with as keys the entity_ids and as value the state.

/api/states/<entity_id> – GET

Returns the current state from an entity

/api/states/<entity_id> – POST

Updates the current state of an entity. Returns status code 201 if successful with location header of updated resource and the new state in the body.

parameter: new_state – string

optional parameter: attributes – JSON encoded object

/api/events/<event_type> – POST

Fires an event with event_type

optional body: JSON encoded object that represents event_data

/api/services/<domain>/<service> – POST

Calls a service within a specific domain.

optional body: JSON encoded object that represents service_data

/api/event_forwarding – POST

Setup event forwarding to another Home Assistant instance.

parameter: host – string

parameter: api_password – string

optional parameter: port – int

/api/event_forwarding – DELETE

Cancel event forwarding to another Home Assistant instance.

parameter: host – string

optional parameter: port – int

If your client does not support DELETE HTTP requests you can add an optional attribute _METHOD and set its value to DELETE.

Connect multiple instances of Home Assistant

Home Assistant supports running multiple synchronzied instances using a master-slave model. Slaves forward all local events fired and states set to the master instance which will then replicate it to each slave.

Because each slave maintains its own ServiceRegistry it is possible to have multiple slaves respond to one service call.



A slave instance can be started with the following code and has the same support for components as a master-instance.

Related projects

Home Assistant API client in Ruby
Home Assistant API client for Tasker for Android

Show more