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

hc-node-homie-smarthome

v0.6.2

Published

Smartome extension for homie-homecontrol based on the node-homie library

Downloads

13

Readme

hc-node-homie-smarthome

works with MQTT Homie

NOTE: This is a BETA version

Base library for homie homecontrol based on node-homie. This lib defines a set of standard smarthome nodes like switch, dimmer, weather sensor,... Using these minimalistic defaults applications can take 'assumptions' about the purpose of the properties used in these nodes.

Each node can be configured and properties can be finetuned to specific needs.

The following nodes are defined:

  • Switch
  • Contact
  • Weather
  • Button
  • Tiltsensor
  • Motionsensor
  • Thermostat
  • Mediaplayer
  • Powermeter
  • Dimmer
  • Colorlight
  • Shutter
  • Text
  • Battery
  • Maintenance

Installation

# npm
npm install hc-node-homie-smarthome

# yarn
yarn add hc-node-homie-smarthome

Usage

This library offers a set of HomieNodes which can either be subclassed or used directly in a HomieDevice to provide standardized behaviour and structure.

Benefits of this is library are:

  • properties do not have to be defined manually - faster implementation
  • node offers convinience accessors to property values with typescript types
  • all nodes follow a defined standard, so results are all comparable

Below you find a usage example with a theoretical hardware sensor api implementing a homie device with a weather node.


    import { WeatherNode } from "node-homie-smarthome";

    // example hardware temperature and humidity sensor
    const tempHumSensor = getHardwareSensorAPI();

    // Homie device
    const device = new HomieDevice({ id: 'my-weather-sensor', name: 'My weather sensor' }, mqttOpts);

    // add a smarthome weather node
    const node = device.add(new WeatherNode(device));

    // Set current state
    node.temperature = tempHumSensor.getCurrentTemp();
    node.humidity = tempHumSensor.getCurrentHum();

    // Subscribe to the sensors dataUpdates (in this example it is ab Observable emitting messages)
    tempHumSensor.dataUpdates$.pipe(takeUntil(node.onDestroy$)).subscribe(
        {
            next: message => {
                if (message.type === 'temp') {
                    node.temperature=message.value;
                }
        
                if (message.type === 'hum') {
                    node.humidity=message.value;
                }
            },
            error: (err) => {
                log.error(`Error process api message for [${node.pointer}].`, { error: err });
            }
        }
    )

Node documenation

The following sections describe the available nodes and their specifics.

Documentation is not yet completeted (sorry - I will work on it...) - however the code is pretty self explanatory.

Switch

type: "homie-homecontrol/v1/type=switch"

Example usages: Represent a switchable actor, e.g. wall socket plug, light bulb.

Properties

|id|type|settable (defualt)|retained|unit|format|comment |-|-|-|-|-|-|-| |state|boolean|yes|yes|-|-|true = ON, false = OFF |action|enum|yes|no|-|toggle|

Configuration

  • common config options available

Contact

type: "homie-homecontrol/v1/type=contact"

Example usages: Represent a open/close sensor, e.g. window or door contact.

Properties

|id|type|settable (defualt)|retained|unit|format|comment |-|-|-|-|-|-|-| |state|boolean|yes|yes|-|-|true = OPEN, false = CLOSED

Configuration

  • common config options available

Weather

type: "homie-homecontrol/v1/type=weather"

Example usages: Represent a weather or humidity sensor.

Properties

|id|type|settable (defualt)|retained|unit (default)|format|comment |-|-|-|-|-|-|-| |temperature|float|no|yes|°C|-| |humidity|float|no|yes|%|-| |pressure|float|no|yes|kPa|-|

Specifics

By default the weather node is read only.

Configuration

  • common config options available
  • tempUnit can be either "C" of "F" to configure the temperature unit (default: "C")
  • all 3 properties are optional and can be configured with boolean flags whether they should be present or not:
    • temperature
    • humidity
    • pressure
export interface WeatherhNodePropertyConfig extends BaseNodePropertyConfig {
    temperature: boolean;
    tempUnit: "C" | "F";
    humidity: boolean;
    pressure: boolean;

}

Button

type: "homie-homecontrol/v1/type=button"

Example usages: Represent a sender with a button, e.g. wall light switch.

Properties

|id|type|settable (defualt)|retained|unit (default)|format (default)|comment |-|-|-|-|-|-|-| |action|enum|no|no|-|press,long-press|

Specifics

Homie-Homecontrol supports 6 different button actios:

  • press
  • long-press
  • double-press
  • release
  • long-release
  • continuous

Configuration

  • common config options available
  • buttonStates: an array of actions, valid values see above
export type ButtonState = 'press' | 'long-press' | 'double-press' | 'release' | 'long-release' | 'continuous';

export interface ButtonNodePropertyConfig extends BaseNodePropertyConfig {
    buttonStates: ButtonState[];
}

Tilt Sensor

type: "homie-homecontrol/v1/type=tiltsensor"

Example usages: Represent a tilt sensor on a box lid or tiltable window.

Properties

|id|type|settable (defualt)|retained|unit|format|comment |-|-|-|-|-|-|-| |state|boolean|yes|yes|-|-|true = TILTED, false = LEVEL

Configuration

  • common config options available

Motion Sensor

type: "homie-homecontrol/v1/type=motionsensor"

Example usages: Represent a PIR motion sensor.

Properties

|id|type|settable (defualt)|retained|unit (default)|format|comment |-|-|-|-|-|-|-| |motion|boolean|false|yes|-|-|true = MOTION, false = NO MOTION |no-motion|integer|false|yes|s|-|Seconds since last motion was detected |lux|integer|false|yes|lx|-|Current light intensity in lux

Specifics

Properties no-motion and lux are optional. The no-motion property is designed to emit in time intervals (e.g. 30, 60, 120 seconds). Updating continiously every seconds would spam the message bus. Therefore as configuration option you can only specify an array of time intervals.

Configuration

  • common config options available
  • Properties no-motion and lux are optional and can be configured with boolean flags whether they should be present or not:
    • noMotion
    • lux
  • noMotionIntervals an array of time intervals after which an update is sent when no motions was detected
export interface MotionSensorhNodePropertyConfig extends BaseNodePropertyConfig {
    lux: boolean;
    noMotion: boolean;
    noMotionIntervals: number[];
}

export const DefaultNoMotionIntervals = [30, 60, 120, 180, 300];

TODO: Think about an implementation change? Due to the way no-motion is implemented (fixed intervals) a more fitting homie datatype would be enum. This would also provide information to other consumers of the property at which intervals the property will report.

Thermostat

type: "homie-homecontrol/v1/type=thermostat"

TODO: document this!

Mediaplayer

type: "homie-homecontrol/v1/type=mediaplayer"

TODO: document this!

Powermeter

type: "homie-homecontrol/v1/type=powermeter"

TODO: document this!

Dimmer

type: "homie-homecontrol/v1/type=dimmer"

TODO: document this!

Shutter

type: "homie-homecontrol/v1/type=shutter"

TODO: document this!

Colorlight

type: "homie-homecontrol/v1/type=colorlight"

TODO: document this!

Text

type: "homie-homecontrol/v1/type=text"

TODO: document this!

Battery

type: "homie-homecontrol/v1/type=battery"

TODO: document this!

Maintenance

type: "homie-homecontrol/v1/type=maintenance"

TODO: document this!

Common configration options

Each node has the following common configuration options:

settable:

Configures if all or specific properties should be settable. Can be either a boolean or an object of booleans with property IDs for which the settable option is specified.

Example:


// All properties should be settable
const config_all = {
    settable: true
}

// only toggle property should be settable
const config_specific = {
     settable: {
        state: false,
        toggle: true
     }
}

propertyOpts:

Provides proptery options for the homie-properties see node-homie.

Example:


// do not attempt to read previous property state from mqtt
const config = {
     propertyOpts: {
         readValueFromMqtt: false,
         readTimeout:0
     }
}