npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fibaro-home-center2-client

v0.3.0

Published

Javascript client for communicating with Fibaro HomeCenter2 smart home controllers

Downloads

15

Readme

Fibaro HomeCenter2 client

Build Status

Javascript client for communicating with Fibaro HomeCenter2 smart home controllers.

Requirements

  • NodeJS (>=10)
  • Fibaro Home Center 2

Installation

yarn add fibaro-home-center2-client

or

npm install --save fibaro-home-center2-client

Usage

Get rooms:

const Fibaro = require('fibaro-home-center2-client');

const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.getRooms().subscribe((rooms) => {
   console.log(rooms);
});

Get all available devices:

const Fibaro = require('fibaro-home-center2-client');

const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.getDevices().subscribe((devices) => {
   console.log(devices);
});

Poll devices properties' updates:

const Fibaro = require('fibaro-home-center2-client');

const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.events().subscribe((event) => {
   console.log(event);
});

Control devices:

const Fibaro = require('fibaro-home-center2-client');

const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.getDevices().subscribe((devices) => {
   const light = devices.find(device => device.identifiers.includes('kitchen/lights/main-light'));
   light.turnOff().subscribe(() => {
       console.log('Kitchen light has turned off');
   });
});

Control devices based on events from other devices:

const Fibaro = require('fibaro-home-center2-client');

const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.getDevices().subscribe((devices) => {
    const fan = devices.find(device => device.identifiers.includes('bedroom/climate/fan'));

    client.events().subscribe((event) => {
        if (event.identifiers.includes('bedroom/climate/temperature') && event.property === 'value') {
            if (event.newValue > 22) {
                fan.turnOn().subscribe();
            } else {
                fan.turnOff().subscribe();
            }
        }
    })
});

Dump all devices' identifiers

const Fibaro = require('fibaro-home-center2-client');

const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.getDevices().subscribe((devices) => {
    const map = {};
    for (const device of devices) {
        for (const identifier of device.identifiers) {
            map[identifier] = device.id;
        }
    }

    for (const key of Object.keys(map).sort()) {
        console.log(key + ': ' + map[key]);
    }
});

List all powered devices

const Fibaro = require('fibaro-home-center2-client');

const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.getDevices().subscribe((devices) => {
    devices
        .filter(device => device.properties.power > 0)
        .map(device => console.log(device.identifiers.join(', ') + ': ' + device.properties.power + 'w'));
});

Output example:

hall/lights/lamp: 39.4w
garage/lights/lamp: 79.1w

List all devices' actions and their possible arguments

const Fibaro = require('fibaro-home-center2-client');

const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.getDevices().subscribe((devices) => {
    for (const device of devices) {
        console.log(device.identifiers.join(', '), device.actions);
    }
});

Output example:

...
bedroom/blinds/curtains {
    close: 0,
    open: 0,
    reconfigure: 0,
    reset: 0,
    sceneActivationSet: 0,
    setValue: 1,
    setValue2: 1,
    startLevelDecrease: 0,
    startLevelIncrease: 0,
    stop: 0,
    stopLevelChange: 0
}
bathroom/safety/flood-sensor {
    abortUpdate: 1,
    forceArm: 0,
    meetArmConditions: 0,
    reconfigure: 0,
    retryUpdate: 1,
    setArmed: 1,
    setInterval: 1,
    startUpdate: 1,
    updateFirmware: 1
}
bedroom/lights/led-strip {
    abortUpdate: 1,
    reconfigure: 0,
    reset: 0,
    retryUpdate: 1,
    setB: 1,
    setBrightness: 1,
    setColor: 1,
    setFavoriteProgram: 2,
    setG: 1,
    setR: 1,
    setValue: 1,
    setW: 1,
    startLevelDecrease: 0,
    startLevelIncrease: 0,
    startProgram: 1,
    startUpdate: 1,
    stopLevelChange: 0,
    turnOff: 0,
    turnOn: 0,
    updateFirmware: 1
}
...

API Reference

Classes

Constants

Typedefs

Client

Kind: global class

new Client(options)

Creates a new client.

| Param | Type | | --- | --- | | options | CLIENT_OPTIONS | Object |

client.events() ⇒ Observable.<DevicePropertyUpdateEvent>

Subscribe on device property update events

Kind: instance method of Client
Properties

| Name | Type | Description | | --- | --- | --- | | criteria | EventCriteria | Optional event filtering |

client.system() ⇒ Observable.<SystemEvent>

Subscribe on client system events

Kind: instance method of Client

client.query(query, retry) ⇒ Observable.<Object>

Make a GET API request to HC2

Kind: instance method of Client

| Param | Type | Default | | --- | --- | --- | | query | string | | | retry | boolean | false |

client.getRooms() ⇒

Get rooms

Kind: instance method of Client
Returns: Observable<Room[]>
Example

const Fibaro = require('fibaro-home-center2-client');

const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.getRooms().subscribe((rooms) => {
   console.log(rooms);
});

client.getDevices() ⇒

Returns devices with properties and actions

Kind: instance method of Client
Returns: Observable<Device[]>
Example

const Fibaro = require('fibaro-home-center2-client');

const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.getDevices().subscribe((devices) => {
   console.log(devices);
});

client.getDevices().subscribe((devices) => {
   const light = devices.find(device => device.identifiers.includes('kitchen/lights/main-light'));
   light.turnOff().subscribe(() => {
       console.log('Kitchen light has turned off');
   });
});

client.callAction(deviceId, action, options) ⇒

Low level method to call an action on a given device. Applications are supposed to call actions on devices instead of this function.

Kind: instance method of Client
Returns: Observable

| Param | Type | | --- | --- | | deviceId | number | | action | string | | options | array |

Example

const Fibaro = require('fibaro-home-center2-client');

// call an action on an ID known device
const client = new Fibaro.Hc2Client({host: '192.168.1.69', user: 'foo', password: 'bar'});
client.callAction(21, 'turnOn');

// call an action on a device object
client.getDevices().subscribe((devices) => {
   // control light
   const light = devices.find(device => device.identifiers.includes('kitchen/lights/main-light'));
   light.turnOn().subscribe(() => {
       console.log('Kitchen light has turned on');
   });

   // control RGBW devices
   const led = devices.find(device => device.identifiers.includes('living-room/lights/rgb-led-strip'));
   led.setBrightness(50).subscribe(() => {
       console.log('Brightness set to 50');
   });
});

CLIENT_OPTIONS

Client options

Kind: global constant
Read only: true
Properties

| Name | Type | Default | Description | | --- | --- | --- | --- | | host | string | "192.168.1.69" | HC2 controller ip-address | | port | number | 80 | HC2 controller port | | user | string | "admin" | username | | password | string | | user password | | connectTimeout | number | 7000 | Reconnect to controller if no success timeout | | pollingInterval | number | 1000 | Controller devices properties polling interval | | pollingTimeout | number | 3000 | Controller devices properties polling timeout | | debug | boolean | false | Trace debug information |

DevicePropertyUpdateEvent : Object

Kind: global typedef
Properties

| Name | Type | Description | | --- | --- | --- | | id | number | Room id provided by HC | | identifier | number | Generated literal identifier | | property | string | Updated property | | newValue | string | updated value | | oldValue | string | previous value |

EventCriteria : Object

Kind: global typedef
Properties

| Name | Type | Description | | --- | --- | --- | | device | Device | null | Subscribe only on a specific device events | | properties | Array.<string> | null | Subscribe only on a specific property change events |

SystemEvent : Object

Kind: global typedef
Properties

| Name | Type | Description | | --- | --- | --- | | id | number | Room id provided by HC | | name | number | Room name provided by HC | | identifier | number | Generated literal identifier |

Room : Object

Kind: global typedef
Properties

| Name | Type | Description | | --- | --- | --- | | id | number | Room id provided by HC | | name | number | Room name provided by HC | | identifier | number | Generated literal identifier |

Device : Object

Kind: global typedef
Properties

| Name | Type | Description | | --- | --- | --- | | id | number | Device id provided by HC | | name | number | Device name provided by HC | | room | Room | Device room | | identifiers | Array.<string> | Generated literal identifiers | | properties | Object | Device properties | | actions | Object | Available device actions |

License

This project is licensed under the GNU GPLv3 - see the LICENSE file for details