node-homeassistant
Home Assistant API Node.js library.
It wraps the Home Assistant RESTful API in easy-to-use, Promise-based functions.
Install
npm install homeassistant
Usage
const HomeAssistant = require('homeassistant');
const hass = new HomeAssistant({
host: 'http://example.com',
port: 8123,
password: 'api_password',
ignoreCert: false
});
hass.services.call('toggle', 'switch', 'lights_3_0')
.then(res => console.log('Toggled lights', res))
.catch(err => console.error(err));
Interface
All functions return Promises.
Configuration
hass.status();
hass.config();
hass.discoveryInfo();
hass.bootstrap();
Camera
hass.camera.image('entityId');
Events
hass.events.list();
hass.events.fire('call_service', {
domain: 'switch',
service: 'toggle',
service_data: {
entity_id: 'switch.lights_3_0'
}
});
History
hass.history.state('2017-05-01T12:00:00-04:00', 'sensor.temperature');
Logs
hass.logs.errors();
Services
hass.services.list();
hass.services.call('toggle', 'switch', 'lights_3_0');
hass.services.call('toggle', 'switch', {
entity_id: 'switch.lights_3_0'
});
States
hass.states.list();
hass.states.get('sensor', 'temperature');
hass.states.update('sensor', 'temperature', {
state: 80,
attributes: {
unit_of_measurement: '°F'
}
});
Templates
hass.templates.render('Mike is at {{ states("device_tracker.mike") }}.');
License
MIT