Need help pulling string from a website to use in rules

  • Platform information: Raspberry Pi Nano
    • Hardware: Raspberry Pi Nano
    • OS: Rasbian image from openHABian
    • Java Runtime Environment:Zulu Embedded OpenJDK Java 8
    • openHAB version: 2
  • Issue of the topic: I want to retrieve the names of our Airbnb guest from an internal website.

When I use the view-source for the page, I see the text I’m looking for:

…<B>Greetings Simona and Tiziana ,<…

What I want is to get the names that are between the word “Greetings” and the coma. I think I just need to write a transform like I use for my Phillips Hue sensors:

(function(i) {
    var json = JSON.parse(i);
    return (json['config']['tholddark']);

The above code extracts the value “9604” from the Hue Clip API text:
“config”: {
“on”: true,
“battery”: 86,
“reachable”: true,
“alert”: “none”,
“tholddark”: 9604,
“tholdoffset”: 7000,
“ledindication”: false,
“usertest”: false,
“pending”: []

  • Please post configurations (if applicable):
    • Items configuration related to the issue

//sample item for Hue sensor
Number	HUE_HueSensorConfig_tholddark_MasterBedroom	"HUE_HueSensorConfig_tholddark_MasterBedroom[%d]"	<Batterylevel>	(gSkur) { http="<[HTTP:// KEYD/sensors/28:300000:JS(getHueSensorConfig_tholddark.js)]"}

// so my new item would look something liek htis
String	SFBayAirbnbGuestName	"Airbnb Guest Name"	<>	(gSkur) { http="<[HTTP://]"}

  • Sitemap configuration related to the issue n/a

  • Rules code related to the issue

  • Services configuration related to the issue
    hue Binding

  • If logs where generated please post these here using code fences:

You need to use the REGEX transform with something like .*Greetings (.*),.*.

.* matches an number of any character up to the word "Greetings " and the REGEX returns all the characters after "Greetings " and the first “,” it sees. The .* at the end matches the rest of the web page.

Ahh regex, my old enemy…

1 Like

Some people, when confronted with a problem, think “I know, I’ll use regular expressions.” Now they have two problems.

Jamie Zawinski

Note: this oft repeated quote is taken out of context but still contains a kernel of truth.

I did a little home work and found a solution based on this post:

Items file

String AirbnbGuest_Name "Airbnb guest names" 	(gSkur) { http="<[HTTP://]"}


(function(csv) { 
  var arr = csv.split("Greetings ");
  var arr2 = arr[1].split(",</B>");
  return arr2[0];