See [openhab-js : items](https://openhab.github.io/openhab-js/items.html) for full API documentation.
- items : `object`
- - .NAME ⇒ `Item`
- - .existsItem(name) ⇒ `boolean`
- - .getItem(name, nullIfMissing) ⇒ `Item`
- - .getItems() ⇒ `Array[Item]`
- - .getItemsByTag(...tagNames) ⇒ `Array[Item]`
- - .addItem([itemConfig](#itemconfig))
- - .removeItem(itemOrItemName) ⇒ `boolean`
- - .replaceItem([itemConfig](#itemconfig))
- - .safeItemName(s) ⇒ `string`
+ - .NAME ⇒ `Item`
+ - .existsItem(name) ⇒ `boolean`
+ - .getItem(name, nullIfMissing) ⇒ `Item`
+ - .getItems() ⇒ `Array[Item]`
+ - .getItemsByTag(...tagNames) ⇒ `Array[Item]`
+ - .addItem([itemConfig](#itemconfig))
+ - .removeItem(itemOrItemName) ⇒ `boolean`
+ - .replaceItem([itemConfig](#itemconfig))
+ - .safeItemName(s) ⇒ `string`
```javascript
var item = items.KitchenLight;
Calling `getItem(...)` or `...` returns an `Item` object with the following properties:
- Item : `object`
- - .rawItem ⇒ `HostItem`
- - .persistence ⇒ [`ItemPersistence`](#itempersistence)
- - .semantics ⇒ [`ItemSemantics`](https://openhab.github.io/openhab-js/items.ItemSemantics.html)
- - .type ⇒ `string`
- - .name ⇒ `string`
- - .label ⇒ `string`
- - .state ⇒ `string`
- - .numericState ⇒ `number|null`: State as number, if state can be represented as number, or `null` if that's not the case
- - .quantityState ⇒ [`Quantity|null`](#quantity): Item state as Quantity or `null` if state is not Quantity-compatible or without unit
- - .rawState ⇒ `HostState`
- - .members ⇒ `Array[Item]`
- - .descendents ⇒ `Array[Item]`
- - .isUninitialized ⇒ `boolean`
- - .groupNames ⇒ `Array[string]`
- - .tags ⇒ `Array[string]`
- - .getMetadata(namespace) ⇒ `object|null`
- - .replaceMetadata(namespace, value, configuration) ⇒ `object`
- - .removeMetadata(namespace) ⇒ `object|null`
- - .sendCommand(value): `value` can be a string, a [`time.ZonedDateTime`](#time) or a [`Quantity`](#quantity)
- - .sendCommandIfDifferent(value) ⇒ `boolean`: `value` can be a string, a [`time.ZonedDateTime`](#time) or a [`Quantity`](#quantity)
- - .postUpdate(value): `value` can be a string, a [`time.ZonedDateTime`](#time) or a [`Quantity`](#quantity)
- - .addGroups(...groupNamesOrItems)
- - .removeGroups(...groupNamesOrItems)
- - .addTags(...tagNames)
- - .removeTags(...tagNames)
+ - .rawItem ⇒ `HostItem`
+ - .persistence ⇒ [`ItemPersistence`](#itempersistence)
+ - .semantics ⇒ [`ItemSemantics`](https://openhab.github.io/openhab-js/items.ItemSemantics.html)
+ - .type ⇒ `string`
+ - .name ⇒ `string`
+ - .label ⇒ `string`
+ - .state ⇒ `string`
+ - .numericState ⇒ `number|null`: State as number, if state can be represented as number, or `null` if that's not the case
+ - .quantityState ⇒ [`Quantity|null`](#quantity): Item state as Quantity or `null` if state is not Quantity-compatible or without unit
+ - .rawState ⇒ `HostState`
+ - .members ⇒ `Array[Item]`
+ - .descendents ⇒ `Array[Item]`
+ - .isUninitialized ⇒ `boolean`
+ - .groupNames ⇒ `Array[string]`
+ - .tags ⇒ `Array[string]`
+ - .getMetadata(namespace) ⇒ `object|null`
+ - .replaceMetadata(namespace, value, configuration) ⇒ `object`
+ - .removeMetadata(namespace) ⇒ `object|null`
+ - .sendCommand(value): `value` can be a string, a [`time.ZonedDateTime`](#time) or a [`Quantity`](#quantity)
+ - .sendCommandIfDifferent(value) ⇒ `boolean`: `value` can be a string, a [`time.ZonedDateTime`](#time) or a [`Quantity`](#quantity)
+ - .postUpdate(value): `value` can be a string, a [`time.ZonedDateTime`](#time) or a [`Quantity`](#quantity)
+ - .addGroups(...groupNamesOrItems)
+ - .removeGroups(...groupNamesOrItems)
+ - .addTags(...tagNames)
+ - .removeTags(...tagNames)
```javascript
// Equivalent to items.KitchenLight
Calling `addItem(itemConfig)` or `replaceItem(itemConfig)` requires the `itemConfig` object with the following properties:
- itemConfig : `object`
- - .type ⇒ `string`
- - .name ⇒ `string`
- - .label ⇒ `string`
- - .category (icon) ⇒ `string`
- - .groups ⇒ `Array[string]`
- - .tags ⇒ `Array[string]`
- - .channels ⇒ `string | Object { channeluid: { config } }`
- - .metadata ⇒ `Object { namespace: value } | Object { namespace: { value: value , config: { config } } }`
- - .giBaseType ⇒ `string`
- - .groupFunction ⇒ `string`
+ - .type ⇒ `string`
+ - .name ⇒ `string`
+ - .label ⇒ `string`
+ - .category (icon) ⇒ `string`
+ - .groups ⇒ `Array[string]`
+ - .tags ⇒ `Array[string]`
+ - .channels ⇒ `string | Object { channeluid: { config } }`
+ - .metadata ⇒ `Object { namespace: value } | Object { namespace: { value: value , config: { config } } }`
+ - .giBaseType ⇒ `string`
+ - .groupFunction ⇒ `string`
Note: `.type` and `.name` are required.
Basic UI and the mobile apps need `metadata.stateDescription.config.pattern` to render the state of an Item.
Calling `Item.persistence` returns an `ItemPersistence` object with the following functions:
- ItemPersistence :`object`
- - .averageSince(timestamp, serviceId) ⇒ `PersistedState | null`
- - .averageUntil(timestamp, serviceId) ⇒ `PersistedState | null`
- - .averageBetween(begin, end, serviceId) ⇒ `PersistedState | null`
- - .changedSince(timestamp, serviceId) ⇒ `boolean`
- - .changedUntil(timestamp, serviceId) ⇒ `boolean`
- - .changedBetween(begin, end, serviceId) ⇒ `boolean`
- - .countSince(timestamp, serviceId) ⇒ `number`
- - .countUntil(timestamp, serviceId) ⇒ `number`
- - .countBetween(begin, end, serviceId) ⇒ `number`
- - .countStateChangesSince(timestamp, serviceId) ⇒ `number`
- - .countStateChangesUntil(timestamp, serviceId) ⇒ `number`
- - .countStateChangesBetween(begin, end, serviceId) ⇒ `number`
- - .deltaSince(timestamp, serviceId) ⇒ `PersistedState | null`
- - .deltaUntil(timestamp, serviceId) ⇒ `PersistedState | null`
- - .deltaBetween(begin, end, serviceId) ⇒ `PersistedState | null`
- - .deviationSince(timestamp, serviceId) ⇒ `PersistedState | null`
- - .deviationUntil(timestamp, serviceId) ⇒ `PersistedState | null`
- - .deviationBetween(begin, end, serviceId) ⇒ `PersistedState | null`
- - .evolutionRateSince(timestamp, serviceId) ⇒ `number | null`
- - .evolutionRateUntil(timestamp, serviceId) ⇒ `number | null`
- - .evolutionRateBetween(begin, end, serviceId) ⇒ `number | null`
- - .getAllStatesSince(timestamp, serviceId) ⇒ `Array[PersistedItem]`
- - .getAllStatesUntil(timestamp, serviceId) ⇒ `Array[PersistedItem]`
- - .getAllStatesBetween(begin, end, serviceId) ⇒ `Array[PersistedItem]`
- - .lastUpdate(serviceId) ⇒ `ZonedDateTime | null`
- - .nextUpdate(serviceId) ⇒ `ZonedDateTime | null`
- - .maximumSince(timestamp, serviceId) ⇒ `PersistedItem | null`
- - .maximumUntil(timestamp, serviceId) ⇒ `PersistedItem | null`
- - .maximumBetween(begin, end, serviceId) ⇒ `PersistedItem | null`
- - .minimumSince(timestamp, serviceId) ⇒ `PersistedItem | null`
- - .minimumUntil(timestamp, serviceId) ⇒ `PersistedItem | null`
- - .minimumBetween(begin, end, serviceId) ⇒ `PersistedItem | null`
- - .persist(serviceId): Tells the persistence service to store the current Item state, which is then done asynchronously.
- **Warning:** This has the side effect, that if the Item state changes shortly after `.persist` has been called, the new Item state will be persisted. See [JSDoc](https://openhab.github.io/openhab-js/items.ItemPersistence.html#persist) for a possible work-around.
- - .persist(timestamp, state, serviceId): Tells the persistence service to store the given state at the given timestamp, which is then done asynchronously.
- - .persist(timeSeries, serviceId): Tells the persistence service to store the given [`TimeSeries`](#timeseries), which is then done asynchronously.
- - .persistedState(timestamp, serviceId) ⇒ `PersistedItem | null`
- - .previousState(skipEqual, serviceId) ⇒ `PersistedItem | null`
- - .nextState(skipEqual, serviceId) ⇒ `PersistedItem | null`
- - .sumSince(timestamp, serviceId) ⇒ `PersistedState | null`
- - .sumUntil(timestamp, serviceId) ⇒ `PersistedState | null`
- - .sumBetween(begin, end, serviceId) ⇒ `PersistedState | null`
- - .updatedSince(timestamp, serviceId) ⇒ `boolean`
- - .updatedUntil(timestamp, serviceId) ⇒ `boolean`
- - .updatedBetween(begin, end, serviceId) ⇒ `boolean`
- - .varianceSince(timestamp, serviceId) ⇒ `PersistedState | null`
- - .varianceUntil(timestamp, serviceId) ⇒ `PersistedState | null`
- - .varianceBetween(begin, end, serviceId) ⇒ `PersistedState | null`
+ - .averageSince(timestamp, serviceId) ⇒ `PersistedState | null`
+ - .averageUntil(timestamp, serviceId) ⇒ `PersistedState | null`
+ - .averageBetween(begin, end, serviceId) ⇒ `PersistedState | null`
+ - .changedSince(timestamp, serviceId) ⇒ `boolean`
+ - .changedUntil(timestamp, serviceId) ⇒ `boolean`
+ - .changedBetween(begin, end, serviceId) ⇒ `boolean`
+ - .countSince(timestamp, serviceId) ⇒ `number`
+ - .countUntil(timestamp, serviceId) ⇒ `number`
+ - .countBetween(begin, end, serviceId) ⇒ `number`
+ - .countStateChangesSince(timestamp, serviceId) ⇒ `number`
+ - .countStateChangesUntil(timestamp, serviceId) ⇒ `number`
+ - .countStateChangesBetween(begin, end, serviceId) ⇒ `number`
+ - .deltaSince(timestamp, serviceId) ⇒ `PersistedState | null`
+ - .deltaUntil(timestamp, serviceId) ⇒ `PersistedState | null`
+ - .deltaBetween(begin, end, serviceId) ⇒ `PersistedState | null`
+ - .deviationSince(timestamp, serviceId) ⇒ `PersistedState | null`
+ - .deviationUntil(timestamp, serviceId) ⇒ `PersistedState | null`
+ - .deviationBetween(begin, end, serviceId) ⇒ `PersistedState | null`
+ - .evolutionRateSince(timestamp, serviceId) ⇒ `number | null`
+ - .evolutionRateUntil(timestamp, serviceId) ⇒ `number | null`
+ - .evolutionRateBetween(begin, end, serviceId) ⇒ `number | null`
+ - .getAllStatesSince(timestamp, serviceId) ⇒ `Array[PersistedItem]`
+ - .getAllStatesUntil(timestamp, serviceId) ⇒ `Array[PersistedItem]`
+ - .getAllStatesBetween(begin, end, serviceId) ⇒ `Array[PersistedItem]`
+ - .lastUpdate(serviceId) ⇒ `ZonedDateTime | null`
+ - .nextUpdate(serviceId) ⇒ `ZonedDateTime | null`
+ - .lastChange(serviceId) ⇒ `ZonedDateTime | null`
+ - .nextChange(serviceId) ⇒ `ZonedDateTime | null`
+ - .maximumSince(timestamp, serviceId) ⇒ `PersistedItem | null`
+ - .maximumUntil(timestamp, serviceId) ⇒ `PersistedItem | null`
+ - .maximumBetween(begin, end, serviceId) ⇒ `PersistedItem | null`
+ - .minimumSince(timestamp, serviceId) ⇒ `PersistedItem | null`
+ - .minimumUntil(timestamp, serviceId) ⇒ `PersistedItem | null`
+ - .minimumBetween(begin, end, serviceId) ⇒ `PersistedItem | null`
+ - .persist(serviceId): Tells the persistence service to store the current Item state, which is then done asynchronously.
+ **Warning:** This has the side effect, that if the Item state changes shortly after `.persist` has been called, the new Item state will be persisted. See [JSDoc](https://openhab.github.io/openhab-js/items.ItemPersistence.html#persist) for a possible work-around.
+ - .persist(timestamp, state, serviceId): Tells the persistence service to store the given state at the given timestamp, which is then done asynchronously.
+ - .persist(timeSeries, serviceId): Tells the persistence service to store the given [`TimeSeries`](#timeseries), which is then done asynchronously.
+ - .persistedState(timestamp, serviceId) ⇒ `PersistedItem | null`
+ - .previousState(skipEqual, serviceId) ⇒ `PersistedItem | null`
+ - .nextState(skipEqual, serviceId) ⇒ `PersistedItem | null`
+ - .sumSince(timestamp, serviceId) ⇒ `PersistedState | null`
+ - .sumUntil(timestamp, serviceId) ⇒ `PersistedState | null`
+ - .sumBetween(begin, end, serviceId) ⇒ `PersistedState | null`
+ - .updatedSince(timestamp, serviceId) ⇒ `boolean`
+ - .updatedUntil(timestamp, serviceId) ⇒ `boolean`
+ - .updatedBetween(begin, end, serviceId) ⇒ `boolean`
+ - .varianceSince(timestamp, serviceId) ⇒ `PersistedState | null`
+ - .varianceUntil(timestamp, serviceId) ⇒ `PersistedState | null`
+ - .varianceBetween(begin, end, serviceId) ⇒ `PersistedState | null`
Note: `serviceId` is optional, if omitted, the default persistence service will be used.
See [openhab-js : things](https://openhab.github.io/openhab-js/things.html) for full API documentation.
- things : <code>object</code>
- - .getThing(uid) ⇒ <code>Thing|null</code>
- - .getThings() ⇒ <code>Array[Thing]</code>
+ - .getThing(uid) ⇒ <code>Thing|null</code>
+ - .getThings() ⇒ <code>Array[Thing]</code>
#### `getThing(uid, nullIfMissing)`
Calling `getThing(uid)` returns a `Thing` object with the following properties:
- Thing : <code>object</code>
- - .bridgeUID ⇒ <code>String</code>
- - .label ⇒ <code>String</code>
- - .location ⇒ <code>String</code>
- - .status ⇒ <code>String</code>
- - .statusInfo ⇒ <code>String</code>
- - .thingTypeUID ⇒ <code>String</code>
- - .uid ⇒ <code>String</code>
- - .isEnabled ⇒ <code>Boolean</code>
- - .setLabel(label)
- - .setLocation(location)
- - .setProperty(name, value)
- - .setEnabled(enabled)
+ - .bridgeUID ⇒ <code>String</code>
+ - .label ⇒ <code>String</code>
+ - .location ⇒ <code>String</code>
+ - .status ⇒ <code>String</code>
+ - .statusInfo ⇒ <code>String</code>
+ - .thingTypeUID ⇒ <code>String</code>
+ - .uid ⇒ <code>String</code>
+ - .isEnabled ⇒ <code>Boolean</code>
+ - .setLabel(label)
+ - .setLocation(location)
+ - .setProperty(name, value)
+ - .setEnabled(enabled)
```javascript
var thing = things.getThing('astro:moon:home');
See [openhab-js : cache](https://openhab.github.io/openhab-js/cache.html) for full API documentation.
- cache : <code>object</code>
- - .private
- - .get(key, defaultSupplier) ⇒ <code>Object | null</code>
- - .put(key, value) ⇒ <code>Previous Object | null</code>
- - .remove(key) ⇒ <code>Previous Object | null</code>
- - .exists(key) ⇒ <code>boolean</code>
- - .shared
- - .get(key, defaultSupplier) ⇒ <code>Object | null</code>
- - .put(key, value) ⇒ <code>Previous Object | null</code>
- - .remove(key) ⇒ <code>Previous Object | null</code>
- - .exists(key) ⇒ <code>boolean</code>
+ - .private
+ - .get(key, defaultSupplier) ⇒ <code>Object | null</code>
+ - .put(key, value) ⇒ <code>Previous Object | null</code>
+ - .remove(key) ⇒ <code>Previous Object | null</code>
+ - .exists(key) ⇒ <code>boolean</code>
+ - .shared
+ - .get(key, defaultSupplier) ⇒ <code>Object | null</code>
+ - .put(key, value) ⇒ <code>Previous Object | null</code>
+ - .remove(key) ⇒ <code>Previous Object | null</code>
+ - .exists(key) ⇒ <code>boolean</code>
The `defaultSupplier` provided function will return a default value if a specified key is not already associated with a value.
- `when()`
- `or()`
- - `.channel(channelName)` Specifies a channel event as a source for the rule to fire.
- - `.triggered(event)` Trigger on a specific event name
- - `.cron(cronExpression)` Specifies a cron schedule for the rule to fire.
- - `.timeOfDay(time)` Specifies a time of day in `HH:mm` for the rule to fire.
- - `.item(itemName)` Specifies an Item as the source of changes to trigger a rule.
- - `.for(duration)`
- - `.from(state)`
- - `.fromOn()`
- - `.fromOff()`
- - `.to(state)`
- - `.toOn()`
- - `.toOff()`
- - `.receivedCommand()`
- - `.receivedUpdate()`
- - `.changed()`
- - `.memberOf(groupName)` Specifies a group Item as the source of changes to trigger the rule.
- - `.for(duration)`
- - `.from(state)`
- - `.fromOn()`
- - `.fromOff()`
- - `.to(state)`
- - `.toOn()`
- - `.toOff()`
- - `.receivedCommand()`
- - `.receivedUpdate()`
- - `.changed()`
- - `.system()` Specifies a system event as a source for the rule to fire.
- - `.ruleEngineStarted()`
- - `.rulesLoaded()`
- - `.startupComplete()`
- - `.thingsInitialized()`
- - `.userInterfacesStarted()`
- - `.startLevel(level)`
- - `.thing(thingName)` Specifies a Thing event as a source for the rule to fire.
- - `changed()`
- - `updated()`
- - `from(state)`
- - `to(state)`
- - `.dateTime(itemName)` Specifies a DateTime Item whose (optional) date and time schedule the rule to fire.
- - `.timeOnly()` Only the time of the Item should be compared, the date should be ignored.
+ - `.channel(channelName)` Specifies a channel event as a source for the rule to fire.
+ - `.triggered(event)` Trigger on a specific event name
+ - `.cron(cronExpression)` Specifies a cron schedule for the rule to fire.
+ - `.timeOfDay(time)` Specifies a time of day in `HH:mm` for the rule to fire.
+ - `.item(itemName)` Specifies an Item as the source of changes to trigger a rule.
+ - `.for(duration)`
+ - `.from(state)`
+ - `.fromOn()`
+ - `.fromOff()`
+ - `.to(state)`
+ - `.toOn()`
+ - `.toOff()`
+ - `.receivedCommand()`
+ - `.receivedUpdate()`
+ - `.changed()`
+ - `.memberOf(groupName)` Specifies a group Item as the source of changes to trigger the rule.
+ - `.for(duration)`
+ - `.from(state)`
+ - `.fromOn()`
+ - `.fromOff()`
+ - `.to(state)`
+ - `.toOn()`
+ - `.toOff()`
+ - `.receivedCommand()`
+ - `.receivedUpdate()`
+ - `.changed()`
+ - `.system()` Specifies a system event as a source for the rule to fire.
+ - `.ruleEngineStarted()`
+ - `.rulesLoaded()`
+ - `.startupComplete()`
+ - `.thingsInitialized()`
+ - `.userInterfacesStarted()`
+ - `.startLevel(level)`
+ - `.thing(thingName)` Specifies a Thing event as a source for the rule to fire.
+ - `changed()`
+ - `updated()`
+ - `from(state)`
+ - `to(state)`
+ - `.dateTime(itemName)` Specifies a DateTime Item whose (optional) date and time schedule the rule to fire.
+ - `.timeOnly()` Only the time of the Item should be compared, the date should be ignored.
Additionally, all the above triggers have the following functions:
#### Rule Builder Conditions
- `if(optionalFunction)`
- - `.stateOfItem(itemName)`
- - `is(state)`
- - `in(state...)`
+ - `.stateOfItem(itemName)`
+ - `is(state)`
+ - `in(state...)`
#### Rule Builder Operations
- `then(optionalFunction)`
- - `.build(name, description, tags, id)`
- - `.copyAndSendState()`
- - `.copyState()`
- - `.inGroup(groupName)`
- - `.postIt()`
- - `.postUpdate(state)`
- - `.send(command)`
- - `.sendIt()`
- - `.sendOff()`
- - `.sendOn()`
- - `.sendToggle()`
+ - `.build(name, description, tags, id)`
+ - `.copyAndSendState()`
+ - `.copyState()`
+ - `.inGroup(groupName)`
+ - `.postIt()`
+ - `.postUpdate(state)`
+ - `.send(command)`
+ - `.sendIt()`
+ - `.sendOff()`
+ - `.sendOn()`
+ - `.sendToggle()`
#### Rule Builder Examples