Class BusEvent

java.lang.Object
org.openhab.core.model.script.actions.BusEvent

public class BusEvent extends Object
The static methods of this class are made available as functions in the scripts. This gives direct write access to the openHAB event bus from within scripts. Items should not be updated directly (setting the state property), but updates should be sent to the bus, so that all interested bundles are notified.
Author:
Kai Kreuzer - Initial contribution, Stefan Bußweiler - Migration to new ESH event concept
  • Constructor Details

    • BusEvent

      public BusEvent()
  • Method Details

    • sendCommand

      public static Object sendCommand(Item item, String commandString)
      Sends a command for a specified item to the event bus.
      Parameters:
      item - the item to send the command to
      commandString - the command to send
    • sendCommand

      public static Object sendCommand(Item item, Number number)
      Sends a number as a command for a specified item to the event bus.
      Parameters:
      item - the item to send the command to
      number - the number to send as a command
    • sendCommand

      public static Object sendCommand(String itemName, String commandString)
      Sends a command for a specified item to the event bus.
      Parameters:
      itemName - the name of the item to send the command to
      commandString - the command to send
    • sendCommand

      public static Object sendCommand(Item item, Command command)
      Sends a command for a specified item to the event bus.
      Parameters:
      item - the item to send the command to
      command - the command to send
    • postUpdate

      public static Object postUpdate(Item item, Number state)
      Posts a status update for a specified item to the event bus.
      Parameters:
      item - the item to send the status update for
      state - the new state of the item as a number
    • postUpdate

      public static Object postUpdate(Item item, String stateAsString)
      Posts a status update for a specified item to the event bus.
      Parameters:
      item - the item to send the status update for
      stateAsString - the new state of the item
    • postUpdate

      public static Object postUpdate(String itemName, String stateString)
      Posts a status update for a specified item to the event bus.
      Parameters:
      itemName - the name of the item to send the status update for
      stateString - the new state of the item
    • sendTimeSeries

      public static Object sendTimeSeries(@Nullable Item item, @Nullable TimeSeries timeSeries)
      Sends a time series to the event bus
      Parameters:
      item - the item to send the time series for
      timeSeries - a TimeSeries containing policy and values
    • sendTimeSeries

      public static Object sendTimeSeries(@Nullable String itemName, @Nullable Map<ZonedDateTime,State> values, String policy)
      Sends a time series to the event bus
      Parameters:
      itemName - the name of the item to send the status update for
      values - a Map containing the timeseries, composed of pairs of ZonedDateTime and State
      policy - either ADD or REPLACE
    • postUpdate

      public static Object postUpdate(Item item, State state)
      Posts a status update for a specified item to the event bus. t
      Parameters:
      item - the item to send the status update for
      state - the new state of the item
    • storeStates

      public static Map<Item,State> storeStates(Item... items)
      Stores the current states for a list of items in a map. A group item is not itself put into the map, but instead all its members.
      Parameters:
      items - the items for which the state should be stored
      Returns:
      the map of items with their states
    • restoreStates

      public static Object restoreStates(Map<Item,State> statesMap)
      Restores item states from a map. If the saved state can be interpreted as a command, a command is sent for the item (and the physical device can send a status update if occurred). If it is no valid command, the item state is directly updated to the saved value.
      Parameters:
      statesMap - a map with (Item, State) entries
      Returns:
      null