Request thing information from url and seperate data by semicolon


i’m using openhab for years now and i’m very happy with it. Have a new gadget in my home network which offers state information at an http endpoint. The returned information is a long string, separated by semicolon.

What is the best approach to request the http endpoint every 60 seconds or so and split the returned information in several things or one thing with different channels? There are only two different data types returned (strings and numbers).

Couldn’t really find a solution so far.



This is precisely what the http binding is for.

If you go through the docs there you will see you can set up one thing that polls an url and then allows you to define channels that parse the return value. In your case, it sounds like you’ll want to make sure you also have either the regex transform installed or use a script transform to parse the return value.

Nice, that looks good. I’ve created one Thing for the URL to be pulled. Then i’ve added two channels for two values i want to extract from the response.
The first one runs fine and returns the correct value.

The second does not return anyhting. The javascript transformation i’m using in the second (not working) channel / it’s item looks like this:

(function(i) {
    var logger = Java.type("org.slf4j.LoggerFactory").getLogger("RASENSCHAF");
    var logger.warn("RASENSCHAF");
    var logger.warn("Wert: " + i + " | Type: " + typeof i);
    var array = i.split(';');
    return parseInt(array[1]);

This is the value which is returned from the endpoint (http get request):


This is a semicolon separated string with 4 fields.
If i check the logs, i see the log output as warnings. The line stating "Wert: " does not show the expected value of i (input), it shows “UNDEF” and Type “string”.

Any Idea, what i did wrong?

Javascript doesn’t have an UNDEF constant; the js version is undefined. The fact that UNDEF appears in your script indicates that the transform is working correctly, but for some reason it is being passed the string "UNDEF" by the channel.

You’ll have to troubleshoot the channel definition itself to see what’s going on. To start with, just remove the transform and link the channel to a string item. See if that string item actually gets the semicolon separated string that you are expecting.

1 Like

okay thanks for the explanation. I’ve double checked, that both channels are configured the same. There is no difference in configuration at the UI-level as i can see.

I’ve set the Profile at the item for the not working channel to “Standard” and the item has the value UNDEF right after saving the item definition.

This sounds like the channel isn’t recieving the value at all.

Now i’ve unlinked the item and removed the channel completely. After that i’ve recreated the channel and created a new item with a slightly different Name.

Now it works as it is supposed to.

Is OpenHab caching something somewhere?

I don’t know enough about the inner workings of the http binding to be able to say with any certainty.