A library to enable automation of / communication with a Home Assistant installation from a node application.
This library makes it possible to, from a node application communicate with one or more Home Assistant systems. Based on the library any type of node application can query the state of a Home Assistant, subscribe to state changes and and call services in the system.
npm i hass-node-scripting-host
To access the system you will have to generate a long lived access token.
Connect to Home Assistant
const instance = await HAInstance.create( 'hostname:port', 'long-lived-access-token' );
Get object instances representing entities in Home Assistant.
const sun = instance.getEntity<Sun>(Sun.ENTITY_ID, Sun); const patioLight = instance.getEntity<Light>('light.patio', Light);
Turn the patio light on whe the sun sets.
sun.state$ .pipe( startWith(await sun.state), distinctUntilChanged(), filter((s) => s === 'below_horizon') ) .subscribe(() => void patioLight.turnOn());
Classes derrived from
Entity are Observables that exposes a set of different
streams that emits when the state of the entity changes in Home Assistant. They
also implement relevant services for the different entity types making it
possible to change the state of the entities.
Copyright (c) 2020 Jonas Andreasson
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.