Create JSON Item in OH2

Tags: #<Tag:0x00007fd312236ff8> #<Tag:0x00007fd312236e18> #<Tag:0x00007fd312236c88>

(paddy) #1

I’m using openhabian (Version 2.1) and I want to create an item with values of the local weather station. The URL is:

There I get following code:

“DESC_I”:“Temperatura dell´aria”,
“DESC_L”:“Temperatura dl’aria”,
I would like to create an item conaining the field “VALUE” (temperature). How do i create an item in OH2?

Thank you in advance!

(Mikael Gustafsson) #2


You will need the http-binding and JSON transformation. You can read about both the binding and the transformation on their respective pages in the online documentation. There’s also an almost direct example of the item definition needed here (under JSONPath Examples).


(paddy) #3

Thank you, I made a .items file and a sitemap with the item. Unfortunatley I don’t get any values, I will try further on.

(Scott Rushworth) #4

I do something similar using a rule for checking the Weather Underground API to get weather alerts and outside lux levels. It uses the JSONPATH transform to populate item values. Try something like this:


Number    Outside_Temperature    "Outside Temperature [%.1f °C]"    <temperature>    (gWeather)


rule "Alert: Check for temperature"
    Time cron "0 1/5 * * * ?"
    //Item Virtual_Switch_1 changed
    logDebug("Rules", "Alert: Check for temperature: Starting")
    val String rawMessage = executeCommandLine("/bin/sh@@-c@@/usr/bin/curl -s -X GET",60000)
    if (rawMessage.length > 0) {
        val String transformedMessage = transform("JSONPATH", "$.VALUE", rawMessage.substring(1,rawMessage.length-1))
        if (transformedMessage != null) {
            logDebug("Rules", "Alert: Check for temperature: transformedMessage=[{}]",transformedMessage)


Text item=Outside_Temperature

(paddy) #5

It seems to work! Thank you so much!

(paddy) #6

If I want to create some other items for example pressure, I only have to change the json-adress and the names of the items?

(Scott Rushworth) #7

Yes, you could. I’m not familiar with the weather service you are using, but they may have restrictions on the frequency of the API calls. You could just do one call to, parse it, and update your items.

If this is your station, you could also add it to Weather Underground (your location might be a factor) and use the new ESH Weather Underground binding, the older OH Weather binding, or use the approach outlined in this thread:

(paddy) #8

Thanksgiving you, to geht other values Like humidity or pressure I only have to Change the sensorcode to LF ord LD.RED and i getti the values. So in the script I only have to Change the code and the Name of the item and rule?


(Scott Rushworth) #9

As I said, you could do that. But rather than make several calls, you can make one and iterate over the results. Add Outside_Humidity and Outside_Pressure items and try something like this. Add more items and case statements to add other values.

rule "Alert: Check for weather"
    Time cron "0 1/5 * * * ?"
    var String rawMessage = executeCommandLine("/bin/sh@@-c@@/usr/bin/curl -s -X GET",60000)
    if (rawMessage != null && rawMessage.contains("SCODE")) {
        rawMessage = rawMessage.substring(1,rawMessage.length - 1).replace("},\n","},,")
        val String[] rawMessageArray = rawMessage.split(",,")
            val String transformedMessage = transform("JSONPATH", "$.VALUE", item + "}")
            switch (transform("JSONPATH", "$.TYPE", item + "}")) {
                case "LT" : Outside_Temperature.sendCommand(transformedMessage)
                case "LF" : Outside_Humidity.sendCommand(transformedMessage)
                case "LD.RED" : Outside_Pressure.sendCommand(transformedMessage)

(paddy) #10

Fantastic, it works! Thank you so much.