https://github.com/mawalu/node-homeassistant
Node.js wrapper for the home-assistant websocket api
https://github.com/mawalu/node-homeassistant
home-assistant home-automation nodejs npm websocket
Last synced: about 1 year ago
JSON representation
Node.js wrapper for the home-assistant websocket api
- Host: GitHub
- URL: https://github.com/mawalu/node-homeassistant
- Owner: mawalu
- License: mit
- Created: 2017-07-20T20:15:40.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-05-29T00:39:43.000Z (about 5 years ago)
- Last Synced: 2023-08-21T03:07:36.688Z (almost 3 years ago)
- Topics: home-assistant, home-automation, nodejs, npm, websocket
- Language: JavaScript
- Size: 30.3 KB
- Stars: 29
- Watchers: 6
- Forks: 10
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Node.js api for home-assistant [](https://www.npmjs.com/package/node-homeassistant)
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:
```javascript
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: 'http_api_password', // api_password is getting depricated by home assistant
token: 'access_token' // for now both tokens and api_passwords are suported
port: 8123
})
ha.connect().then(() => {
// do stuff
})
```
Access & subscribe to states:
```javascript
console.log(ha.state('sun.sun'))
ha.on('state:media_player.spotify', data => console.log)
```
Call services:
```javascript
ha.call({
domain: 'light',
service: 'turn_on'
})
```
You can subscribe to the 'connection' event to get information about the websocket connection.
```javascript
ha.on('connection', info => {
console.log('connection state is', info)
})
```
See the example folders for a working demo.
# License
MIT