Have done Openhab 2 file in rules or items or script

Good day,
Unfortunately, I can not get any further, I have a file


how can i read this file from a rules or items can also be a script.
I want to calculate a value from the file at what.
Thanks for your help, sorry for my bad English.


What would you like to do with the contents of the file?

It’s easy enough to use a CAT command in a Exec Binding thing to push the contents of the file into an openHAB2 Item.

cat \var\lib\openhab2\log_results.txt

You could even try to use the Regex feature to filter it (this isn’t something I’ve mastered yet).

It’s possible to trigger the Thing on demand, or set a polling interval.

Much like how I used the Exec binding to pull the results of the APCaccess command into openHAB2.

(Read to the end, as Rich gives some excellent advice on how to handle the results)

1 Like

There is also the Log Reader binding which can follow the file, assuming it’s constantly changing, and assign lines that match a given regular expression to an Item.


You could also use node-red to read the content of the file, filter the value you need and pass it to OH via the openhab nodes or via MQTT

Thank you have made it.
In a rule.

rule "curl_datei_erstellen"
        Time cron "* 0/1 * 1/1 * ? *" //1 min.
        var results = executeCommandLine("curl -u 'user:password' -o 'datei_name.txt' -L 'url'", 60000)
        //logInfo("TEST_LOG_results", results)
        var String catm = executeCommandLine("cat /var/lib/openhab2/ datei_name.txt", 1000)
        //logInfo("TEST_LOG_cat", catm)
        var akku = transform("JSONPATH", "$..state_of_charge", catm)
        //logInfo("TEST_LOG_akku", akku)
        var watt = transform("JSONPATH", "$..system.power", catm)  
        //logInfo("TEST_LOG_watt", watt)  

Thanks for your tips.

FYI - You can do HTTP calls directly from rules or from items and not have to resort to curl/cat.

1 Like

Yes I do, but with this website I can not give in the URL string user and password, that’s why I do it that way.

What you are doing is called “basic authentication” and is covered by the HTTP binding. Docs for it are here.