I have a multi-channel temperature recorder that outputs a data table as HTML text. I would like to extract some of the channel data into separate Items. I have tried REGEX but am not making any headway at all. The data stream looks like:
<HTML><HEAD><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><META HTTP-EQUIV="Pragma" CONTENT="no-cache"><TITLE>REAL DATA</TITLE></HEAD><BODY BGCOLOR="#FFFFFF"><TABLE border="0" width="100%" bgcolor="#00FFFF"><tr><td>CURRENT DATA DISP</td></tr></TABLE><br>Recording in progress.<br><br><CENTER><FORM method="GET" action="REALDATA.HTM"TARGET="SETTING"><div align="center"><CENTER><TABLE border="1" cellpadding="3" cellspacing="0"><tr><td colspan=3>'16-09-18 15:39:16</td><td colspan=3> </td></tr><tr><td>CHAN</td><td>DATA</td><td>COMMENT</td><td>CHAN</td><td>DATA</td><td>COMMENT</td></tr><tr><td>ch1</td><td> 24.03 C</td><td>Hot Water Tank </td><td>ch2</td><td> 21.91 C</td><td>Furnace Air Out </td></tr><tr><td>ch3</td><td> 23.16.....
I can get the table into an Item no problem but no luck on individual channels (ch1, ch2…). Can anyone suggest a suitable REGEX?
MUCH appreciated. Mike.
Please edit this post and put three back tics before and after your HTML text so we can see the HTML tags and other formatting which the forum interpreted as post formatting.
Your HTML goes here
Without out being able to see the tags and such we cannot help with the REGEX.
I gave up on the REGEX. I found it was much easier just to using simple string functions in rules…
Can you post your code? How do you input the html to openhab? how do you parse it?
I can tell you what I did but I have a very limited knowledge of Openhab
and while works just fine, I probably don’t know why! The html data is
read as a string by using the html binding. Because the string has a fixed
format I can use a rule with string functions to cut out substrings,
convert them to numbers and then send them back to an item:
rule "Update test2"
Item Hyoki2 received update
xs2 = Hyoki2.state.toString
d2 = new Double(buffer2)
postUpdate (ht2, d2)
There may well be easier ways to do this but this works for me.
How long is the html-string?
Can you shoe the Item-definition?
The string is quite long - see the first post for an actual copy.
The item is very simple:
Number ht2 “Liquid Line at Furnace [%.2f °C]” (data)