items

Namespace

items

Description:
  • Items namespace. This namespace handles querying and updating openHAB Items.

Source:

Classes

Item
ItemPersistence
ItemSemantics
PersistedItem
PersistedState
TimeSeries

Namespaces

metadata

Members

(static, constant) DYNAMIC_ITEM_TAG

Description:
  • Tag value to be attached to all dynamically created Items.

Source:

Tag value to be attached to all dynamically created Items.

Methods

(static) NAME() → {Item|null}

Description:
Source:
Example
// retrieve item by name directly on the items namespace
console.log(items.KitchenLight.state) // returns 'ON'
// equivalent to
console.log(items.getItem('KitchenLight').state) // returns 'ON'
Returns:

items.Item Item or null if Item is missing

Type
Item | null

(static) addItem(itemConfig) → {Item}

Description:
  • Creates a new Item within OpenHab. This Item will persist to the registry, and therefore is independent of the lifecycle of the script creating it.

    Note that all Items created this way have an additional tag attached, for simpler retrieval later. This tag is created with the value DYNAMIC_ITEM_TAG.

Source:
Parameters:
Name Type Description
itemConfig ItemConfig

the Item config describing the Item

Throws:
Returns:

Items.Item

Type
Item

(static) existsItem(name) → {boolean}

Description:
  • Whether an Item with the given name exists.

Source:
Parameters:
Name Type Description
name string

the name of the Item

Returns:

whether the Item exists

Type
boolean

(static) getItem(name, nullIfMissingopt) → {Item}

Description:
  • Gets an openHAB Item.

Source:
Parameters:
Name Type Attributes Default Description
name string

the name of the Item

nullIfMissing boolean <optional>
false

whether to return null if the Item cannot be found (default is to throw an ItemNotFoundException)

Returns:

items.Item Item or null if nullIfMissing is true and Item is missing

Type
Item

(static) getItems() → {Array:.<Item:>}

Description:
  • Gets all openHAB Items.

Source:
Returns:

items.Item[]: all Items

Type
Array:.<Item:>

(static) getItemsByTag(…tagNames) → {Array:.<Item:>}

Description:
  • Gets all openHAB Items with a specific tag.

Source:
Parameters:
Name Type Attributes Description
tagNames Array:.<string:> <repeatable>

an array of tags to match against

Returns:

items.Item[]: the Items with a tag that is included in the passed tags

Type
Array:.<Item:>

(static) removeItem(itemOrItemName) → {Item|null}

Description:
  • Removes an Item from openHAB. The Item is removed immediately and cannot be recovered.

Source:
Parameters:
Name Type Description
itemOrItemName string | Item

the Item or the name of the Item to remove

Returns:

the Item that has been removed or null if it has not been removed

Type
Item | null

(static) replaceItem(itemConfig) → {Item|null}

Description:
  • Replaces (or adds) an Item. If an Item exists with the same name, it will be removed and a new Item with the supplied parameters will be created in its place. If an Item does not exist with this name, a new Item will be created with the supplied parameters.

    This function can be useful in scripts which create a static set of Items which may need updating either periodically, during startup or even during development of the script. Using fixed Item names will ensure that the Items remain up-to-date, but won't fail with issues related to duplicate Items.

Source:
Parameters:
Name Type Description
itemConfig ItemConfig

the Item config describing the Item

Throws:
Returns:

the old Item or null if it did not exist

Type
Item | null

(static) safeItemName(s) → {string}

Description:
  • Helper function to ensure an Item name is valid. All invalid characters are replaced with an underscore.

Source:
Parameters:
Name Type Description
s string

the name to make value

Returns:

a valid Item name

Type
string