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

@hotzware/openhab-tools

v3.0.0

Published

Tools for the openHAB JavaScript Automation Add-On.

Downloads

96

Readme

openHAB JS Automation Tools

This library provides some utilites for the openHAB JS Scripting Add-On.

Please note that it depends on the openHAB JavaScript Library, which is included in the JS Scripting Add-On by default. Therefore, it is only listed in the devDependencies of this package.

js-semistandard-style npm version

Installation

  • Requires the openHAB JavaScript binding which comes with a version of the openHAB library.
  • Go to the javascript user scripts directory: cd $OPENHAB_CONF/automation/js
  • Run npm install @hotzware/openhab-tools (you may need to install npm)

Compatibility

This library depends on openhab >= 4.6.0 (which is included since openHAB 4.1.0 Milestone 2) and openhab_rules_tools >= 2.0.1.

openhab_rules_tools will automatically get installed by npm, openhab is already included with the add-on. Just make sure you have a compatible version installed (use console.log(utils.OPENHAB_JS_VERSION) to check the currently used version).

API

To have a look at all capabilities of this library, have a look at the JSDoc().

The README will only take care of the most important stuff, and explain the more complicated ones.

itemutils

  • dimItem: Dims an Item step-by-step to a target state.
  • getGroupUtils: See Group Utilities

Group Utilities

The Group Utilities provide a number of functions on groups, e.g. arithmetic operations like min/max and count operations.

Examples
const { itemutils } = require('@hotzware/openhab-tools');
// The name of the member with the maximum state.
itemutils.getGroupUtils(group).membersMax.name;
// The sum of states.
itemutils.getGroupUtils(group).membersSum;
// Count how many members are on.
itemutils.getGroupUtils(group).membersCount(item => item.state === 'ON');

See JSDoc: GroupUtils for full API documentation.

rulesx

  • createAlarmClock: See Alarm Clock.
  • createAlarmClockItems: Creates the required Items for an alarm clock and optionally also generates Sitemap code.
  • createSceneEngine: See Scene Engine.

Alarm Clock

Creates an alarm clock with time and days configurable over Items, therefore compatible with Sitemaps.

Under the hood, two rules are created. The first rule, the so-called manager rule, watches for configuration changes and updates the cron trigger of the second rule, the alarm clock itself. It also disables and enables the alarm clock rule based on the switchItem.

Required Items

Configuration Items must follow a specific naming scheme, switchItem can be anything.

| Itemname-Suffix | Purpose | |---------------------|------------------------------------| | switchItem | Enable/disable alarm | | switchItem_H | Hour | | switchItem_M | Minute | | switchItem_MON | Monday | | switchItem_TUE | Tuesday | | switchItem_WED | Wednesday | | switchItem_THU | Thursday | | switchItem_FRI | Friday | | switchItem_SAT | Saturday | | switchItem_SUN | Sunday | | switchItem_Time | Displays the alarm time as String. |

Alarm Rule
rulesx.createAlarmClock(switchItem, data => { console.log('Successfully tested alarm clock.'); });

See JSDoc: getAlarmClock() for full API documentation.

Scene Engine

Call scene by sending a command to the sceneItem.

When a member of the scene changes it's state, the rule will check whether a defined scene is matching the current states and which scene.

It creates a full rule with triggers and actions out of your scene definition.

The sceneItem

Must be a Number item. You can assign a scene to every positive integer value, except to 0.

0 is the value the Item is et to when no match with a scene is found on members' change.

Scene definition

Scene definition works with an array of objects.

const sceneDefinition = {
  controller: 'scene call item name',
  scenes: [ // For each numeric state of the controller Item one object.
    { // Object for the value 1 of the controller Item.
      value: 1,
      targets: [ // Target states of items in the scene. Parameters explained later.
        { item: 'Florian_Licht', value: 'ON', required: true, conditionFn: function() { return parseFloat(items.getItem('Helligkeit').state) >= 10000; } },
        { item: 'Florian_LED_Stripes', value: 'OFF', required: false }
      ] 
    },
    { // Object for the value 15 of the controller Item.
      value: 15,
      targets: [ // Target states of items in the scene. Parameters explained later.
        { item: 'Florian_LED_Stripes', value: 'ON', required: true }
      ]
    }
  ]
};
Create the Scene Engine
rulesx.createSceneEngine(sceneDefinition);

See JSDoc: createSceneEngine() for full API documentation.

thingsx

  • createReEnableThingWithItemRule: Creates a rule that re-enabled a Thing on command ON to a given Item.
  • createThingStatusRule: Creates a rule that posts Thing statuses to String Items.
  • reEnableThing: Re-enables a Thing by first disabling and then enabling it again.
  • MlscRestClient: Class providing state fetching from and command sending to music_led_strip_control.