Parse text file for item values

Hi all, I’m attempting to retrieve values collected from my weather station to store in items. At the moment I’m doing this in an overly complicated way using a custom console application written in c#. I am wanting to move from Windows to RPi in the near future, so this will no longer be a viable option. I’m thinking there must be a fairly simple way to parse the text file, but my reading of the transformation add-ons is that none of them are quite right for the job. Following is an example of the text file:

[General]
Date=24/06/2019
Timestamp=2019-06-24T16:50:100:

[Temp]
Low=3.5
LTime=02:32
High=12.3
HTime=11:16

I would like to be able to retrieve, say High and store it in a max temp item for the day.

Appreciate any ideas/assistance!

Do you have control over the format your weather station is reporting? If yes, I’d suggest to use a JSON format, that one is parsable.

1 Like

No, unfortunately I’m not able to modify the output format.

in this case I’d try it with some (2?) regex statements.

ok thanks will give that a shot

Not sure what I’m doing. I’ve used val String newString = transform(“REGEX”, “High=(.*?)\n”, rawWeather), regex101 seems to be happy (although it returns multiple matches). Any regex experts able to assist?

In openHAB, the regex needs to match the full String, not just a line of the String.

You need something like .*High=(.*?)\n.*

Brilliant. That’s gotten me closer! So the only problem now is that High is used several times throughout the file and the current regex returns the last match. For example,

[General]
Date=24/06/2019
Timestamp=2019-06-24T16:50:100:

[Temp]
Low=3.5
LTime=02:32
High=12.3
HTime=11:16

[HeatIndex]
High=12.3
HTime=11:16

In the above example, the figure returned would be the heatindex high. Is it possible to stop at just the first match? Or better yet, specify which match # to keep. I’m researching regex but not figuring it out.

Thanks again for all the help!

If the order is consistent then specify a bit more around the string you care about.

.*LTime=.*\nHigh=(.*?)\n.*