A library to create automation for Home Assistant in nodeJS using the WebSocket API.
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.
listenForEntity("sun.sun", (entity) => {
if(entity.new_state.state === 'below_horizon')
callService('light', 'turn_on', undefined, 'light.living_room')
})
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'})
)
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'})
}
})