Create txt File

(T. H.) #1

Dear forum members,

I wanted to ask if there is a solution, how to write in the .rules file via a command a String in a txt file.

Sorry for the bad English!


(Rich Koshak) #2

You can implement it using Java IO in your Rule but you probably should not be doing this.

What are you trying to accomplish? There is almost certainly a better way (e.g. persistence).

(Kevin) #3

Perhaps you can execute an Bash Script in the .rules … and the Bash Script write the TXT File …

Let us know what you want write in the TXT … perhaps there is a better Solution …

(Kevin) #4

Perhaps this helps … I think you are a Native German Speaker :wink:

(T. H.) #5

I have an RFID reader that sends the TAG ID to the OpenHab 2 server via MQTT.
I would like to record in a txt file, who and at what time has read his TAG.

(Hakan Tandogan) #6

I would use persistence for this, that way, you have the events in a database and use SQL queries to read it from your consumer.

( ) #7

Or you could store the value in an item (I guess that’s what you are already doing) and use the openHAB REST Api to retrieve it whenever you want to. The detour through a file is possible but just not as clean as possible other solutions.

If you are interested in a better solution, it might help to tell us what’s your intended next step with the created file.

(T. H.) #8

Could you please give me an example? So the individual steps I have to do. I’m still a beginner and I need a few bases.

(Hakan Tandogan) #9

o.k., from my setup, for InfluxDB based persistence, but you can adapt this to JDBC based persistence very easily:

in items/sensebox-terasse.items:

Group gInflux
Number  Terasse_Sensebox_Luminance        "Terasse Light Level [%.1f lx]"      <light>         (Weather, gInflux)

the important part is the “(gInflux)” group membership in the item.

Then, in persistence/influxdb.persist:

Items {
        gInflux* : strategy = everyChange, everyHour
        gInfluxDaily* : strategy = everyChange, everyDay

Here, the important part is the “*” after the group name. I missed it in my first configurations, and it took me ages to find the simple syntax error.

Then, in services/influxdb.cfg,

password=nope-i-won't-tell-you :slight_smile: 

See also the threads: