Global

Methods

_validateVersionNum(version) → {boolean}

Validates that the passed in version number is of the format X.Y.Z where X, Y, and Z are numbers.
Parameters:
Name Type Description
version string a version string to validate
Source:
Returns:
true if valid, false otherwise
Type
boolean

avgList(list) → {float}

Averages the states of the passed in list of Items. Items with a non-numeric state are completely ignored and not considered part of the calculation.
Parameters:
Name Type Description
list Array.<item>
Source:
Returns:
average of the Item's with numberic states.
Type
float

betweenTimes(start, end, test) → {boolean}

DEPRECATED DEPRECATED DEPRECATED Use openhab-js time.betweenTimes instead. Tests to see if now falls between a start time or end time (ignoring the date) with logic to handle cases where the time period spans midnight.
Parameters:
Name Type Description
start time.ZonedDateTime | java.time.ZonedDateTime | String | number | bigint | DateTimeType | DecimalType | PercentType | QuantityType date time or duration whose time portion indicates the start of the time period
end time.ZonedDateTime | java.time.ZonedDateTime | String | number | bigint | DateTimeType | DecimalType | PercentType | QuantityType date time or duration whose time portion indicates the end of the time period
test time.ZonedDateTime | java.time.ZonedDateTime | String | number | bigint | DateTimeType | DecimalType | PercentType | QuantityType date time or duration whose time portion indicates time to check whether it falls between, uses now if not supplied
Source:
Returns:
true if now is between the times (ignoring dates) of the passed in start and end
Type
boolean

checkGrpAndMetadata(namespace, grp, validateFunc, usage) → {boolean}

Utility function mostly used by rule templates to check the metadata and Group membership of the Items that drive a rule like Debounce or Time Based State Machine. An Item metadata namespace and Group is passed along with a function and usage text. The function validates that all Items that have the given namespace are members of grp, no members of grp lack the namespace metadata, and the validateFunc is called to validate the metadata on each individual Item. validateFunc should throw an exception with the reason why the Item failed validation when it fails. The usage text will be logged if one or more Items fail validations.
Parameters:
Name Type Description
namespace string the Item metadata namespace to check
grp string name of the Group Item all the Items with namespace should belong to
validateFunc function function called to validate the metadata is valid
usage string text to log out when an Item fails validation
Source:
Returns:
true if validation passes, false if there's a problem
Type
boolean

compareVersions(v1, v2) → {number}

Compare version numbers of the format X.Y.Z.
Parameters:
Name Type Description
v1 string the first version number
v2 string the second version number
Source:
Throws:
error if v1 or v2 are not parsable
Returns:
0 if the versions are equal, -1 if v1 is lower and 1 if v1 is higher
Type
number

countList(list) → {num}

Parameters:
Name Type Description
list Array.<item>
Source:
Returns:
the count of the Items that match the filterFunc
Type
num

createRuleWithMetadata(namespace, checkConfig, event, ruleName, func, description, tags, uid, systemStarted) → {HostRule}

Creates a rule that is triggered when any Item with valid metadata in the passed in namespace using the passed in trigger type. In addition to the passed in tags, a DYNAMIC_RULE_TAG will also be applied.
Parameters:
Name Type Description
namespace string Item metadata namespace used to identify those Items to trigger
checkConfig function function that returns true if the metadata on the Item is valid
event triggers.ItemStateChangeTrigger | triggers.ItemStateUpdateTrigger | triggers.ItemChangeTrigger the Item trigger type to create for each Item
ruleName string name of the rule generated
func function function to call when the rule is triggered
description string optional description for the rule
tags Array.<string> optional tags to apply to the rule
uid string optional UID to identify the rule
systemStarted int optional when true a runlevel 40 trigger will be added to the rule.
Source:
Returns:
the created rule, or null if there was a problem
Type
HostRule

createRuleWithTags(tag, event, ruleName, func, description, tags, uid, systemStarted) → {HostRule}

Creates a rule that is triggered when any Item with a given tag trigger type. In addition to the passed in tags, a DYNAMIC_RULE_TAG will also be applied.
Parameters:
Name Type Description
tag string Item tag used to identify those Items to trigger
event triggers.ItemStateChangeTrigger | triggers.ItemStateUpdateTrigger | triggers.ItemChangeTrigger the Item trigger type to create for each Item
ruleName string name of the rule generated
func function function to call when the rule is triggered
description string optional description for the rule
tags Array.<string> optional tags to apply to the rule
uid string optional UID to identify the rule
systemStarted int optional when true a runlevel 40 trigger will be added to the rule.
Source:
Returns:
the created rule, or null if there was a problem
Type
HostRule

createTimer(when, func, nameopt, keyopt)

Utility function to create a named timer. The name can be set with the name parameter or is autogenerated from the ruleUID (for UI) or filename and the timer's key (if available).
Parameters:
Name Type Attributes Description
when * any representation of time or duration, see time.toZDT
func function function to call when the timer expires
name string <optional>
name for the timer
key string <optional>
key of the timer to append to the generated name
Source:
Returns:
openHAB Java Timer

descendentsToMappedList(groupName, mapFunc, filterFunc) → {Array}

Same as membersToMappingList except it works on descendents of the Group.
Parameters:
Name Type Description
groupName string
mapFunc function
filterFunc function
Source:
Returns:
Type
Array

descendentsToString(groupName, separator, mapFunc, filterFunc) → {string}

Same as membersToString except it operates on the Group's descendents.
Parameters:
Name Type Description
groupName string
separator string
mapFunc function
filterFunc function
Source:
Returns:
Type
string

durationToDateTime(duration) → {time.ZonedDateTime}

DEPRECATED DEPRECATED DEPRECATED Use openhab-js time.toZDT(duration) Adds the duration to now. If the duration is a String, call parseDuration first.
Parameters:
Name Type Description
duration time.Duration | String
Source:
Returns:
the duration added to now, null if not a usable duration
Type
time.ZonedDateTime

generateTriggers(list, trigger, systemStarted) → {Array.<triggers>}

Generates an Array of Item triggers for each Item in the list.
Parameters:
Name Type Description
list Array.<Item> list of Items to generate triggers for
trigger triggers.ItemChangedTrigger | triggers.ItemStateUpdateTrigger | triggers.ItemStateUpdateTrigger type of trigger to generate for each Item in the list
systemStarted int optional, when provided adds a system runlevel trigger. Valid values are 40, 50, 60, 70, 80, 90, or 100.
Source:
Returns:
the generated rule triggers
Type
Array.<triggers>

getBackingMap(keyopt, cacheObjopt) → {java.util.Map}

Retrieves or creates a backing Java ConcurrentHashMap in the specified cache. If no cache is specified, cache.private is used. If no key is specified, a local Map is created but not stored in any cache (for backward compatibility).
Parameters:
Name Type Attributes Description
key string <optional>
key to store/retrieve the map in the cache
cacheObj object <optional>
the cache object to use (e.g., cache.shared or cache.private), defaults to cache.private if key is provided
Source:
Returns:
Java Map
Type
java.util.Map

getCountdownTimer(when, func, countItem, nameopt, keyopt, cacheObjopt)

A countdown timer updates an Item with the number of seconds left in the timer once a second.
Parameters:
Name Type Attributes Description
when * time.toZDT compatible time or duration
func function function to call at when
countItem string name of the Item to update with the seconds remaining
name string <optional>
countdown name displayed in openHAB
key string <optional>
key for the backing map in the cache
cacheObj object <optional>
cache object to use
Source:
Returns:
a new CountdownTimer

getDeferred(keyopt, cacheObjopt)

Deferred is a way to schedule a simple command sometime in the future.
Parameters:
Name Type Attributes Description
key string <optional>
key for the backing map in the cache
cacheObj object <optional>
cache object to use
Source:
Returns:
a new instance of Deferred

getGatekeeper(name, keyopt, cacheObjopt)

The Gatekeeper will ensure that a certain amount of time passes between commands.
Parameters:
Name Type Attributes Description
name String optional and used in error messages
key string <optional>
key for the backing map in the cache
cacheObj object <optional>
cache object to use
Source:
Returns:
a new Gatekeeper instance

getLoopingTimer(keyopt, cacheObjopt)

Parameters:
Name Type Attributes Description
key string <optional>
key for the backing map in the cache
cacheObj object <optional>
cache object to use
Source:
Returns:
a timer that resheduels itself until the passed in looping function return null

getRateLimit(keyopt, cacheObjopt)

The RateLimit class keeps track of when the last `run` was called and throws away subsequent calls to run that occur before the passed in `when`.
Parameters:
Name Type Attributes Description
key string <optional>
key for the backing map in the cache
cacheObj object <optional>
cache object to use
Source:

getTimerMgr()

The TimerMgr handles the book keeping to manage a bunch of timers identified with a unique key.
Source:

is12Hr(dtStr) → {boolean}

Tests the string to see if it matches a 12 hour clock time
Parameters:
Name Type Description
dtStr String potential hh:MM aa string
Source:
Returns:
true if it matches hh:mm aa
Type
boolean

is24Hr(dtStr) → {boolean}

Tests the string to see if it matches a 24 hour clock time
Parameters:
Name Type Description
dtStr String potential HH:MM String
Source:
Returns:
true if it matches HH:MM
Type
boolean

isISO8601(dtStr) → {boolean}

Tests the passed in string to see if it conforms to the ISO8601 standard
Parameters:
Name Type Description
dtStr String potential ISO8601 string
Source:
Returns:
true if ISO8601 format
Type
boolean

isNumber(i) → {boolean}

Tests to see if i is an Item with a numeric state.
Parameters:
Name Type Description
i *
Source:
Returns:
true if i's rawState has a floatValue function
Type
boolean

maxList(list) → {num}

Parameters:
Name Type Description
list Array.<item>
Source:
Returns:
Maxiumum value of the Items with numeric states.
Type
num

membersToMappedList(groupName, mapFunc, filterFunc) → {Array}

Utility that will return the passed in Group's members mapped with the passed in mapping function. An example mapping funciton would be: i => i.name which will return an array of the member's names. Supports an optional filterFunc to filter the members before generating the mapped list. A filter looks something like i => !i.isUninitialized
Parameters:
Name Type Description
groupName string
mapFunc function function called to map the Item
filterFunc function optional filtering function
Source:
Returns:
the filtered Items with the mapping function applies
Type
Array

membersToString(groupName, separator, mapFunc, filterFunc) → {string}

Calls membersToMappedList and joins the result into a separator separated string.
Parameters:
Name Type Description
groupName string
separator string string to separate the list in the resultant string
mapFunc function
filterFunc function
Source:
Returns:
the mapped values concetanted to a single string
Type
string

minList(list) → {num}

Parameters:
Name Type Description
list Array.<item>
Source:
Returns:
Minimum value of the Items with numeric states.
Type
num

parseDuration(durationStr) → {time.Duration}

DEPRECATED DEPRECATED DEPRECATED Use openhab-js time.Duration.parse() instead, note it uses ISO8601 duration formats Parses a duration string returning a js-joda Duration representing the duration. Supports the followiung units: - d days - h hours - m minutes - s seconds - s milliseconds The unit is preceeded by an integer (decimals are not supported). Examples: - 5d 2h 7s - 5m - 1h23m
Parameters:
Name Type Description
durationStr String string representation of the duration
Source:
Returns:
null if the string is not parsable
Type
time.Duration

recreateRule(uid, ruleName, ruleDescription, trigs, func, tsopt)

If a rule with the given UID exists, it's deleted. Then a new rule is created with the given properties. A DYNAMIC_RULE_TAG will be applied to the rule.
Parameters:
Name Type Attributes Default Description
uid string unique identifier for the given rule
ruleName string name for the rule as it will appear in MainUI
ruleDescription string explanation of the purpose of the rule
trigs Array.<object> triggers which willcause the rule to run
func function called when the rule triggers
ts Array.<string> <optional>
[] optional list of tags to apply to the rule
Source:

reduceDecendentStates(groupName, reduceFunc, filterFunc)

Same as reduceMemberStates except it does it for all descendents.
Parameters:
Name Type Description
groupName string
reduceFunc function
filterFunc function
Source:
Returns:
A single reduced value calculated from all members of the group

reduceMemberStates(groupName, reduceFunc, filterFunc)

Optionally, filters the members of the group, maps the Items to rawState, and applies the reduce function. The function should take two values, a total and a value. It would look something like this for a sum. (total, value) => total += value
Parameters:
Name Type Description
groupName string
reduceFunc function
filterFunc function
Source:
Returns:
A single reduced value calculated from all members of the group

removeRule(uid)

DEPRECATED Deletes the rule if it exists. Does not work in UI rules.
Parameters:
Name Type Description
uid String UID for the rule to remove
Source:

ruleExists(uid) → {Boolean}

Checks to see if the rule exists Only works for rules defined in the same file so it's utility is suspect
Parameters:
Name Type Description
uid String UID for the rule to look for
Source:
Returns:
true when the rule exists
Type
Boolean

runRule(nameOrUid, argsDict, cond) → {boolean}

DEPRECATED Calls another rule based on UID or rule name. TODO remove when added to openhab-js
Parameters:
Name Type Default Description
nameOrUid string Rule UID or name to run
argsDict dict optional dict of data to pass to the called rule
cond boolean false optional flag, when true the called rule's conditions will be evaluated
Source:
Returns:
true when the rule is found and successfully called
Type
boolean

sumList(list) → {float}

Sums the states of the passed in list of Items. Items with a non-numeric state are ignored.
Parameters:
Name Type Description
list Array.<item>
Source:
Returns:
sum of the Items with numeric states.
Type
float

toDateTime(when) → {time.ZonedDateTime}

DEPRECATED DEPRECATED DEPRECATED openhab-js now ships with toZDT() which implements this. Converts a number of date time formats and duration formats to a time.ZonedDateTime. Durations represeted by a Duration, duration string (see parseDuration), and raw numbers are added to now. Raw numbers are assumed to represent milliseconds. PercentType and QuantityTypes are assumed to represent seconds. Date times are converted to a time.ZonedDateTime. Time strings (e.g. "13:12" or "4:56 pm") return a ZonedDateTime with at that time with today's date.
Parameters:
Name Type Description
when time.ZonedDateTime | java.time.ZonedDateTime | String | number | bigint | DateTimeType | DecimalType | PercentType | QuantityType date time or duration to convert
Source:
Returns:
null if it cannot be converted
Type
time.ZonedDateTime

toToday(when)

DEPRECATED DEPRECATED DEPRECATED Use openhab-js toToday. Moves the date time to today's date. If pass a duration, converts it to a ZonedDateTime and then moves it to today's date.
Parameters:
Name Type Description
when time.ZonedDateTime | java.time.ZonedDateTime | String | number | bigint | DateTimeType | DecimalType | PercentType | QuantityType date time or duration to move to today's date
Source:
Returns:
time.ZonedDateTime with today's date

toTomorrow(when)

Moves the date time to tomorrow's date. If pass a duration, converts it to a ZonedDateTime and then moves it to tomorrow's date.
Parameters:
Name Type Description
when time.ZonedDateTime | java.time.ZonedDateTime | String | number | bigint | DateTimeType | DecimalType | PercentType | QuantityType date time or duration to move to today's date
Source:
Returns:
time.ZonedDateTime with tomorrow's date

toYesterday(when)

Moves the date time to yesterday's date. If pass a duration, converts it to a ZonedDateTime and then moves it to yesterday's date.
Parameters:
Name Type Description
when time.ZonedDateTime | java.time.ZonedDateTime | String | number | bigint | DateTimeType | DecimalType | PercentType | QuantityType date time or duration to move to today's date
Source:
Returns:
time.ZonedDateTime with yesterday's date

validateLibraries()

Checks to see if the minimum versions of openhab-js and openhab_rules_tools are met.
Source:
Throws:
  • error if one or more of the version numbers are malformed
  • error if one or more of the versions are too old