1.4.0 • Published 1 year ago

@herja/core v1.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

1.4.0

1 year ago

1.3.0

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago