0.1.0-alpha.4 • Published 4 years ago
@hubhazard/hubitat-api v0.1.0-alpha.4
Hubitat API - HubHazard module
A module for the HubHazard automation server. This module enables easy communication with Hubitat using the Maker API.
Installation
Using npm or yarn:
npm install @hubhazard/hubitat-api
yarn add @hubhazard/hubitat-api
Usage
First of all import it to the module where you want to use it:
import { Module } from '@nestjs/common';
import { HubitatApiModule } from '@hubhazard/hubitat-api';
@Module({
imports: [HubitatApiModule],
controllers: [],
providers: [SomeService],
exports: [SomeService],
})
export class SomeModule {}
Remember to inject the HubitatApiService
:
import { Injectable } from '@nestjs/common';
import { HubitatApiService } from '@hubhazard/hubitat-api';
@Injectable()
export class SomeService {
constructor(private readonly hubitatApiService: HubitatApiService) {}
}
Listen to device update events
You can listen to device update events sent by Hubitat.
this.hubitatApiService
.deviceUpdateObservable
.subscribe(
(event) => console.log( JSON.stringigy(event))
);
Get a list of all devices
const devices = await this.hubitatApiService.getDevicesList();
Get details of one device
const deviceId = 36
const device = await this.hubitatApiService.getDeviceInfo(deviceId);
Send a command to a device
A command without a value:
const deviceId = 102;
const command = 'off';
await this.hubitatApiService.sendDeviceCommand(deviceId, command);
A command with a value:
const deviceId = 243;
const command = 'setLevel';
const value = 50;
await this.hubitatApiService.sendDeviceCommand(deviceId, command, value);
The Hubitat Maker API doesn't support second value, therefore the HubHazard Hubitat API doesn't support it either.
Change Log
See Changelog for more information.
Contributing
Contributions welcome!
License
Licensed under the MIT License - see the LICENSE file for details.
0.1.0-alpha.5
4 years ago
0.1.0-alpha.4
4 years ago