# node-homeassistant

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

Latest version **1.6.0** (published 2019-10-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-homeassistant
pnpm add node-homeassistant
yarn add node-homeassistant
bun add node-homeassistant
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.6.0 |
| Published | 2019-10-01 |
| First published | 2017-07-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 7.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | mawalu |

## Links

- npm: https://www.npmjs.com/package/node-homeassistant
- npm.io page: https://npm.io/package/node-homeassistant

## Dependencies (1)

- [ws](https://npm.io/package/ws.md) ^6.0.0

## Recent versions

- 1.6.0 (latest) — 2019-10-01
- 1.5.0 — 2018-09-28
- 1.4.1 — 2018-04-10
- 1.4.0 — 2018-04-10
- 1.3.1 — 2018-03-12
- 1.3.0 — 2017-07-29
- 1.2.0 — 2017-07-29
- 1.1.0 — 2017-07-28
- 1.0.0 — 2017-07-25

## README

# Node.js api for home-assistant [![](https://img.shields.io/npm/v/node-homeassistant.svg)](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

---
_Source: https://npm.io/package/node-homeassistant · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
