sunnyhd / homeintouch

A home automation project using socket.io
2 stars 0 forks source link

Home In Touch

Install

git clone git@github.com:sunnyhd/homeintouch.git
cd homeintouch
npm install

Run

The Node application connects to a "HIT" server from which it syncs home automation and media data. Since this server is not exposed directly to the internet you'll need to forward some of your local ports through an SSH tunnel.

The Node app connects to the following local ports (the values can be changed in config/dev.json):

To forward these ports to the HIT server run the following command and leave the shell open:

ssh -N -L 8080:localhost:8080 -L 8090:localhost:8090 user@marisamigliazzi.selfhost.eu

The Node app caches media data in a local MongoDB database (you can set the database to which the server connects in config/dev.json). With MongoDB running we can start the Node server (listens on port 8081).

In another shell, run:

node server.js

The application can also be run using the following files (.sh on Linux, .cmd on Windows):

startDev
startProd
startEnv <custom-environment>

There will not be any media data initially so you'll need to trigger an import. This can either be done via the web UI (login is admin/admin) or by running:

curl -X POST http://admin:admin@localhost:8081/api/imports

The import process runs in the background.

All the images are saved using another application. The application is located in image-cache. Inside there is a shell script to run the server. It needs to be executed along with the HiT client.

Config

The application has a per environment configuration. The default environments are dev and prod, but custom environments can be created. To have a configuration for the custom environment, a file with the environment name has to be created in the folder config, eg: You want to create a new environment called stage:

Flow

  1. Server startup

    • sets up socket connections
    • exposes http and socket.io
  2. Client startup

    • loads all resources from server
    • renders root app
    • connects to server
  3. Communication

    • server emits "homes" event with all data
    • server/client emit "address" event when an address changes
    • client emits "save" with same format as "homes" to save state
    • client updates views whenever a device state changes

Models

The models are pretty straightforward, mostly forming a hierarchy in which each model contains a list of its submodels. Each model needs to be able to be added and deleted. Modifying is a nice-to-have that can be accomplished with by deleting and re-adding.

Home

Floor

Room

DeviceGroup

Device

Address

DeviceType

App

User interface

The UI should look something like this. A navbar allows the user to select the home they're viewing in the upper right, and from that home select a given room using the floor dropdowns.

Logo [Ground Floor \/ | Basement \/ | New floor...]        [ Home 1 \/ ]

+----------------------------------------------------------------------+
| Bedroom                                                          | + |
+----------------------------------------------------------------------+
+--------------------+   +--------------------+
| Lights             |   | New Light          |
|                    |   |                    |
| Lamp 1 [ON]  OFF   |   | Light name         |
| Lamp 2  ON  [OFF]  |   | ____________       |
|                    |   | Read address       |
|                    |   | ____________       |
|                    |   | Write address      |
|                    |   | ____________       |
|                    |   |                    |
+--------------------+   +--------------------+
|                | + |   | Cancel |    | Save |
+--------------------+   +--------------------+

Each room consists of a sub-navbar showing the room name and a button for adding a new group, and n rows of up to three device groups. Each device group panel has two modes: a read mode (shown in the left group) in which the status of each device can be viewed and changed, and a write mode (shown in the middle group) in which a given device within the group can be modified.

Communication

All interaction with the server is performed via Socket.IO.

socket.on("connect", function(){})
socket.on("disconnect", function(){})
socket.on("homes", function(homes){})
socket.on("address", function(id, value){})

socket.emit("save", home)

Sample addresses

Lights/Motion/Szenes/Window(open/closed):

Dimmer:

Thermostat:

Shutters: