File sensor? I'm migrating from Home Assistant to OH2. Need a bit of help!

Having just loaded Openhab2 a couple of days ago. I’m very impressed with its configuration capabilities!
The migrate from Home Assistant has started… Hopefully.

So quick one. Is there an equivalent of Home assistant’s File Sensor in Openhab2?
I have a solar controller that prints to file.
A sample of the line printed to file:

{'FW': '0308', 'SOC': '916', 'Relay': 'OFF', 'PID': '0x203', 'H10': '20', 'BMV': '700', 'TTG': '14400', 'H12': '0', 'H18': '18462', 'I': '0', 'H11': '0', 'Alarm': 'OFF', 'CE': '-64359', 'H17': '15716', 'P': '0', 'AR': '0', 'V': '12575', 'H8': '14369', 'H9': '59586', 'H2': '-65586', 'H3': '0', 'H1': '-181292', 'H6': '-12624519', 'H7': '11885', 'H4': '0', 'H5': '0'}

In home assistant the file sensor would use regex to extract info… IE ‘SOC’ (State of Charge) and print it to a sensor output.

Sample of the HA code:

  - platform: file
    name: BMV - SOC
    file_path: /config/vedirect-bmv/bmv700Parsed.txt
    value_template: >
      {{ (value | regex_findall_index("\'SOC\': \'(\d+)\'") | int) / 10 }}
    unit_of_measurement: '%'

Can this be achieved in OH2?

You could likely do something with Jython scripting. @rlkoshak may have some ideas.

There’s an FTP Upload binding -

Content of a “capture” can be processed in a rule.
That’s more of a substitute file handler, than eavesdropping on an existing setup though. Depends what you want.

I believe you could use the exec binding to run a script or cat the file and then parse the output as a transform.

In watching videos on home assistant it seems they do plenty of the back ground work for you on things that openHAB require some you to code.

Looks like I’ll have to brush up on my coding skills :laughing:

Ive basically got a python script that initiates a serial connection to the Victron Solar controller, then prints the info to file. Then I’ve a second script that parses the last line from that file and prints it to a parsed file.
Home Assistant reads it every 30 sec then extracts the section I need via regex.

So, I suppose the way I’ll have to go forward is to create a script that does the extraction from the file, then publishes to MQQT…

This may take a long long long time!

I’ve got HA and OH2 running on the same machine while I get OH ready…

what about the serial binding? https://www.openhab.org/addons/bindings/serial1/

1 Like

Will take a look at that too!

Example of openHAB rule reading from a file

but as said, why not bypass the external scripts and jus read from serial

1 Like

I’d like to read from serial. Much cleaner way to do it. There’s a lot of learning between me and that tho! And from my understanding print doesn’t come in CSV format either. That’s why we used regex in HA.

Think I can manage the print to MQTT in the meantime…

Jython scripting is Python 2 compatible. @5iver and hos team have made it quite easy to use with openHAB.

Wow… I have a team! Where are they hiding? Tell 'em to stay out of my code!

You can use your scripts natively in Jython, but you may need to do some conversion to Python 2.7. You could also run your scripts using executeCommandLine. If you are just starting up with OH, I suggest not using the rules DSL and going straight to the new rule engine, scripted automation, Jython , and the helper libraries. If you provide your script, I will make up a rule for you. Everything you are asking for can absolutely be done in OH… in several different ways.

2 Likes

You are doing the work of a whole team? You really do need to get out more. :smiley:

1 Like

It was an example, you see, not a drop-in tailored solution. For the purposes of fetching data from serial, it doesn’t matter if it comes in CSV or JSON or XML or some unspecified proprietary format, all of that gets dealt with easily after you have the data.

It’d be best at this stage to reveal what you are trying to do, rather than how you are trying to do it.
Your target device is unknown, but a hint in your script that it is a BMV-700, a meter?
This has a serial port, running proprietary protocol “VE-Direct”?
Is your openHAB host going to connect to that? Or there is some other gateway inbetween that openHAB must deal with instead?

I understand trying to exploit existing scripts, but this is looking really unwieldy … you’ve a script that prints to a file, another script that interprets into another file, now you’re looking to transmit as MQTT to a broker, have openHAB subscribe to the broker, and finally reinterpret dat to OH Items.

1 Like

Unlike the home Assistant forum, we help YOU configure and understand your system.

The volunteers do not and cannot supply complete solutions for you. The system is so flexible that there are many ways to accomplish something. since you alone can troubleshoot any issue, you need some understanding of its operation.

1 Like

Victron BMV-700 indeed is a meter!
It reads conditions of a 12V battery system and solar array.
Then:

I then (in HA with a file sensor component) read the file and create a sensor reading in HA GUI to display for use in automation’s etc.

Ive just managed (with help from someone smarter than I) to convert the parsed file to JSON then publish to the MQTT server.
Its pretty useful that way and I’ve now just added an MQTT thing for each reading from the meter.

Thanks for all the homework guys. Think this will be a steep learing curve for me, but I really do like the interface on this, customizable, no reboot every time you make a sensor change, plenty of paperwork online.

Will definitely look into going direct to serial once I’ve got the bulk of the OH system configured.

The next one for me is ingratiating a Hall pulse flow meter and counter to tally water use (in OpenHab2)!

1 Like

I understand the culture shock. It was about this time last year I gave up on Home Assistant.

2 Likes

Dunno about that one, but openHAB has bindings for Modbus/TCP and SunSpec. They might or might not be useful for your intended application.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.