Promise based node implementation of the WattBox control API
Using NPM:
npm install wattbox
Using Yarn:
yarn add wattbox
Turn on an outlet on the WattBox
import { WattBoxPromise } from 'wattbox';
var wattbox = new WattBoxPromise('username', 'password', '192.168.1.25');
wattbox.powerOn(2).catch((err) => {
console.log(err);
});
Reset an outlet with a custom period of time
import { WattBoxPromise } from 'wattbox';
var wattbox = new WattBoxPromise('username', 'password', '192.168.1.25');
// Turns the outlet off, waits for 5 seconds, then turns the outlet back on
wattbox.powerResetTimeout(2, 5000).catch((err) => {
console.log(err);
});
Subscribe to status updates from the WattBox
import { WattBoxPromise } from 'wattbox';
var wattbox = new WattBoxPromise('username', 'password', '192.168.1.25');
wattbox.subscribeStatus(5000);
wattbox.on('status', (status) => {
console.log(status);
});
wattbox.on('error', (error) => {
console.log(error);
});
Power on the selected outlet:
wattbox.powerOn(<outlet>)
Power off the selected outlet:
wattbox.powerOff(<outlet>)
Power cycle the selected outlet:
wattbox.powerReset(<outlet>)
Power cycle the outlet with a custom period of time:
wattbox.powerResetTimeout(<outlet>, <time>)
Enable auto reboot:
wattbox.autoRebootOn()
Disable auto reboot:
wattbox.autoRebootOff()
Get info about the wattbox. Returns a JSON object containing device info:
wattbox.getInfo()
Subscribe to device status updates. Returns a JSON object containing the device status:
wattbox.subscribeStatus(<time>)
Receive the status and errors thusly:
wattbox.on('status', (status) => {
console.log(status)
})
wattbox.on('error', (error) => {
console.log(error)
})
Unsubscribe from status updates:
wattbox.unsubscribeStatus()
Please open an issue on the GitHub page
This project is licensed under the MIT license