[SOLVED] Parse file and make items

Angelos has it exactly right. Run that command once from the command line and /etc/openhab2/html/realtime.txt will point to /home/pi/CumulusMX/realtime.txt until /etc/openhab2/html/realtime.txt is removed.

It’s kind of like a shortcut. It comes in really handy for situations like these. Though be aware that regardless what the permissions are on the link, the openhab users must have permission to read the original file as well.

If you are running in Docker this won’t work without some additional work.

2 Likes

Hello, I want to pick up that topic again and ask for support. I have a more or less similar usecase, i.e. I want to parse a .txt file that contains weather data. I want to “extract” single values only (e.g. for Temperature, Pressure etc.) and map these values to items. I tried the approach described above in this thread and it worked so far, but I still have the following limitations and questions.

  1. In my openhab.log the following is shown when I run the rule:
2020-04-06 21:02:01.528 [INFO ] [ipse.smarthome.model.script.RAW DATA] - 12345 0.0 0.0 90 12.5 42 1022.9 0.00 0.00 146.30 0.00 0.00 23.9 46 - 4 - - 0 0.00 - - - - - - - - - 21 01 01 Bayreuth,_Stolzingstrasse-21:01 0 - 06 04 - - - - - - - 23.5 10.3 20.2 2.0 4 - 0 0.0 0.0 0.1 1.0 1.1 1.6 1.4 2.0 2.1 2.2 0.9 0.2 0.1 0.0 0.0 0.0 0.0 0.1 0.3 0.9 6.8 -0.1 5040 06/04/2020 18.8 -1.1 23.8 22.9 - 0.0 0.0 0.1 1.0 1.1 1.6 1.4 2.0 2.1 2.2 17.2 19.3 20.0 19.8 19.1 18.3 16.9 15.3 13.8 12.0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 20.2 2.0 12.5 3.3 0 _ _ 90.0 _ 0 - - - - - - - 0 26.8 22.6 - 1022.9 1019.7 0.0 20:00 16:09 - - 3.3 -4.6 0.0 2020 _ -1 0 -1 90 90 90 180 135 225 68 135 113 23 - - 0.0 - 49.966667 -11.59 - 66.0 31.0 - 09:39 !!C10.37Of!!

2020-04-06 21:02:01.532 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Get weater station data': The name 'Pressure' cannot be resolved to an item or type; line 13, column 5, length 8

What does the above Error-Message mean? Maybe that I have to create an item “Pressure” first? If yes, how do I have to define it in that specific case?

  1. As said I want to extract specific fields/values of the .txt file only. How do I “jump” to the right position in the file? Is that done by the command Pressure.postUpdate(weatherArray.get(10)) in the above example, i.e. does the value “10” in brackets represent the 10th field in the array somehow? If that is not the right track, how can I solve it?

Thanks a lot for your help.

Well, yes. If the Item does not exist yet, then your rule cannot post updates to it.
You create the Item however you usually create Items, either using a file like xxx.items or using PaperUI.
You’ll need to decide what type of Item you would like.

weatherArray.get(10)
selects the 11th result (counting starts at zero) from the array produced by the split earlier.

Thanks a lot for your swift reply. I’m a bit confused how to correctly define the item in that specific case. The first part is clear for me, but how to define the rest? I think I have to add something in curly brackets, but what and how?

Number Pressure "Luftdruck [%.2f hPa]" <pressure> { ??? ="[???]" }

Only if you want to link your file-defined Item to some binding.
As you seem to want to control it from a rule, I don’t think you do.

OK, will try it. One question, only for the sake of completeness. If I wanted to link my file-defined Item to some binding, how the expression in curly brackets would have to look like?

If using Scripted Automation, you can create the Items pragmatically too. Though in Jens’ specific use case I wouldn’t recommend doing that. I only mention it for completeness.