Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Within this article, it is assumed that an MQTT broker is providing the current weather information via MQTT topic. However, instead of providing weather values like wind speed or current outside temperature as native data, it provides a JSON object as string value. If the MQTT topic is configured correctly (for more information about MQTT see the following article), the JSON object will be shown within the Item Tree as follows:

The full example of this JSON object looks as follows:

Code Block
languagejs
{
  "current":
  {
    "outside_temperature" : 21.5,
    "wind_speed" : 10
  }
}

To extra data from this JSON string, the logic module can be used. To get the outside temperature, the following parsing definition has to be added:

Image Added

  • Item suffix: Outside
    This means that the item ID of the virtual item that will be created by the Logic module will have the suffix Outside. This suffix will be appended to the original item ID followed by a dot. In our example the item ID will be NETx\XIO\Mqtt\MyBroker\weather\current.Outside
  • Base path or Item ID: empty
    If multiple items shall be recalculated, a base path for start searching for items can be specified here. If only 1 single item is selected, this parameter is ignored.
  • Selector: NETx\XIO\Mqtt\MyBroker\weather\current
    Here the source item is specified. If multiple items shall be recalculated, the selector for pattern matching must be specified. 
  • Data type: float
    Here the data type of the created virtual item is defined. In our case we will take a real since the temperature can be a decimal.
  • In processing type: JSON
    Here the type of the incoming data must be specified. In our example, JSON has to be chosen.
  • In processing resource: $.current.outside_temperature
    Depending on the incoming data type, the processing function has to be defined. For JSON, a valid JPATH expression has to be specified here – for XML, an XPATH expression has to be used. In our example, we are using the JPATH $.current.outside_temperature. $ selects the root element, .current selects the child named current and .outside_temperature the child for .current named outside_temperature. More information about JPATH can be found here.

After having saved the definition, the following item will appear within the item tree:

Image Added

The pre- and post-processing can also be combined with calculation functions. To show the value in Fahrenheit, you can use the following definition:

Image Added

The result of this definition is a virtual item that shows the extracted temperature in degrees Celsius. 

Image Added