Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Node.js wrapper for the home-assistant websocket api

License

Notifications You must be signed in to change notification settings

luke255/node-homeassistant

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js api for home-assistant

A simple package to access & controll home-assistant from node.js using the websocket api.

Installation

$ npm install node-homeassistant

Usage

Create a new Homeassistant object:

const Homeassistant = require('node-homeassistant')

let ha = new Homeassistant({
  host: '192.168.1.166',
  protocol: 'ws', // "ws" (default) or "wss" for SSL
  retryTimeout: 1000, // in ms, default is 5000
  retryCount: 3, // default is 10, values < 0 mean unlimited
  password: 'super_secure',
  port: 8123
})

ha.connect().then(() => {
  // do stuff
})

Access & subscribe to states:

console.log(ha.state('sun.sun'))


ha.on('state:media_player.spotify', data => console.log)

Call services:

ha.call({
     domain: 'light',
     service: 'turn_on'
   })

You can subscribe to the 'connection' event to get information about the websocket connection.

ha.on('connection', info => {
  console.log('connection state is', info)
})

See the example folders for a working demo.

License

MIT

About

Node.js wrapper for the home-assistant websocket api

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%