@homeassistant-node/main
TypeScript icon, indicating that this package has built-in type declarations

2.2.3 • Public • Published

Homeassistant-node

A library to create automation for Home Assistant in nodeJS using the WebSocket API.

How to use

Initialize the connexion

const connection = await configure({
  url: process.env.API_URL,
  access_token: process.env.API_TOKEN,
});

Where API_URL is ws://${host:port}/api/websocket and your access_token can be generated from your account.

Listen for changes on an entity

listenForEntity("sun.sun", (entity) => {
    if(entity.new_state.state === 'below_horizon')
        callService('light', 'turn_on', undefined, 'light.living_room')
})

Describe a set of state and give it a callback

onEntitiesState([{entity_id: 'binary_sensor.garden_door_contact', state: 'on'}, {entity_id: 'light.living_room_light', state: 'on'}],
    () => callService('light', 'turn_on', undefined, {entity_id: 'light.garden'})
)

Manually subscribe to an event

connection.subscribeEvents( (event) => {
  if(event.data.entity_id === "binary_sensor.garden_door_contact" && event.data.new_state === 'on'){
    callService('light', 'turn_on', undefined, {entity_id: 'light.garden'})
  }
})

Thanks

Readme

Keywords

none

Package Sidebar

Install

npm i @homeassistant-node/main

Weekly Downloads

0

Version

2.2.3

License

MIT

Unpacked Size

16 kB

Total Files

5

Last publish

Collaborators

  • xorob0