items

items

Source:

Items namespace. This namespace handles querying and updating openHAB Items.

Classes

ItemHistory
Item

Members

(static, constant) DYNAMIC_ITEM_TAG

Source:

Tag value to be attached to all dynamically created items.

Methods

(static) addItem(itemConfig) → {Item}

Source:

Creates a new item within OpenHab. This Item will persist to the provider regardless 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.

Parameters:
Name Type Description
itemConfig ItemConfig

the Item config describing the Item

Throws:
Returns:

an items.Item object

Type
Item

(static) removeItem(itemOrItemName) → {boolean}

Source:

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

Parameters:
Name Type Description
itemOrItemName String | HostItem

the Item or the name of the Item to remove

Returns:

true if the item was actually removed

Type
boolean

(static) replaceItem(itemConfig) → {Item}

Source:

Replaces (upserts) 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 it's 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.

Parameters:
Name Type Description
itemConfig ItemConfig

the Item config describing the Item

Throws:
Returns:

an items.Item object

Type
Item

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

Source:

Gets an openHAB Item.

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 exception)

Returns:

the item

Type
items.Item

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

Source:

Gets all openHAB Items.

Returns:

all items

Type
Array.<items.Item>

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

Source:

Gets all openHAB Items with a specific tag.

Parameters:
Name Type Attributes Description
tagNames String <repeatable>

an array of tags to match against

Returns:

the items with a tag that is included in the passed tags

Type
Array.<items.Item>

(static) safeItemName(s) → {string}

Source:

Helper function to ensure an item name is valid. All invalid characters are replaced with an underscore.

Parameters:
Name Type Description
s string

the name to make value

Returns:

a valid item name

Type
string