Giter Site home page Giter Site logo

homey-socket.io's Introduction

Homey Socket IO

Adds support for Socket.IO to Homey.

Example

This app for Homey exposes all devices to Socket.IO. Below is a small example how to listen to a sensor and turning on/off a lamp using Node.

const {io} = require("socket.io-client");

class App {

	constructor() {
		// Connect to Homey socket. It is your Homey name plus your Athom Cloud-ID.
		// You can find it under system settings in the Homey App. 
		// The port is currently fixed to 3987.
		this.socket = io("http://your-homey-id:3987");
		
		this.socket.on("connect", () => {
			// Successful socket.io connection
			console.log(`Connected to socket ID ${this.socket.id}.`);		
		});

		this.socket.on('homey', (payload) => {
			// Now connected to Homey. The payload is all zones and devices
			console.log(`Connected to Homey.`);		

			// Payload contains all Homey devices and zones
			let {devices, zones} = payload;

			this.devices = devices;
			this.zones = zones;

			// Show all devices for debugging purposes.
			console.log(JSON.stringify(this.devices, null, '  '));
		});

		// Listen to a sensor. The format is "zone-name/device-name/capabilityID"
		// This example listens to a motion sensor named "Philips" in a zone named "Hem".
		// See https://tools.developer.homey.app/tools/devices for your device capabilities. 
		this.socket.on(`Hem/Philips/alarm_motion`, (value) => {
			// Turn a light on/off. Same format.
			// In this case a lamp in zone "Kontoret" named "Kontoret D".
			this.socket.emit(`Kontoret/Kontoret D/onoff`, !value, () => {
				console.log(`The lamp is now ${value ? "OFF" : "ON"}.`);
			});
		});
	}
}

const app = new App();

homey-socket.io's People

Contributors

meg768 avatar

Stargazers

 avatar  avatar

Watchers

 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.