Use data from a file to create an item

All, I am able to get data from my solar inverter in the format of a html file. See below for an example of the file, everything between the ----


{“method”:“uploadsn”,“version”:“Solax_SI_CH_2nd_20160912_DE02”,“type”:“AL_SE”,“SN”:“123456”,“Data”:[0.0,0.0,0.0,0.0,-0.8,242.8,0,38,0.2,18132.5,-1108,0,0,49.04,-0.06,-3,28,9,0.0,5037.0,0.00,0.00,49.98,0.0,0.0,0,0.00,0,0,0,0.00,0,8,0,0,0.00,0,8],“Status”:“2”}

I am trying to use this data to be used by a thing for example the value of 38 is the percentage charge on the battery. I have tried this with a regex and although it matches in regex101 and others I cant seem to get it to match in OH, any ideas?

May we see your attempt?
Are you doing this in a rule, or a binding transformation?

Hi rossko57,

See below the regex I have used.

.+?(?=Data)Data.*242.8,0,(\d.)

That looks like JSON, why not use the JSONPATH transformation? $.Data[7] should return that 38 value I think.

openHAB regular expressions are a little different from normal. First, the expression must match the entire string. What is returned is the first matching group (i.e. the first set of parens).

So I would expect something like the following to work to extract that 38.

.*Data\":\[.*,.*,.*,.*,.*,.*,.*,(.*),.*
1 Like

Hi mate, thanks for the advise I will give it a go and see what I can find.

Am getting the following error in the logs now.

2021-01-20 03:26:28.532 [WARN ] [ofiles.JSonPathTransformationProfile] - Could not transform state ‘UNDEF’ with function ‘$.Data[7]’ and format ‘%s’

The binding had a problem fetching data since your edit of the Item/channel.
Did you just need to be patient until the next scheduled read, or something?

Getting it each time it does a read

Here is a full breakdown of the setup

OH Version = OH3
Hardware =Raspberry Pi

Thing = Inverter IP created using the HTTP Binding, have the full path to the page in the Base URL of http://192.168.100.22/api/realTimeData.htm with a Basic Authentication even thogu authentication is nor needed at all. (Could this be the issue)
It is then under context type text/html.

The channel config is
Channel Type = Number
State URL Extension = Blank
Command URL Extension = Blank
State Transformation = Blank
Command Transformation = Blank
Read/Write Mode = Read Only

Item Link details
Name = Solar_Battery_Percent
Label = Solar Battery Percent
Type = Number
Category = Solar
Semantic Class= Point
Semantic Property = None
Profile = JSONPATH
JSONPath Expression = $.Data[7]
State Formatter = Blank

I am able to query the Inverter from the Pi CLI and pull down the page using a wget and a curl

curl http://192.168.100.22/api/realTimeData.htm
{“method”:“uploadsn”,“version”:“Solax_SI_CH_2nd_20160912_DE02”,“type”:“AL_SE”,“SN”:“31FC556E”,“Data”:[6.2,7.2,378.8,372.6,11.2,245.3,2611,40,11.4,18200.8,227,2348,2682,53.43,39.03,2088,29,63,0.0,5057.4,0.00,0.00,49.97,0.0,0.0,0,0.00,0,0,0,0.00,0,8,0,0,0.00,0,8],“Status”:“2”}

As rossko57 indicates, UNDEF is a special state that the binding applies to Items when it cannot know the state of the Item, often because there was a communications error.

Please post the YAML from the code tab where available.

I don’t know the HTTP binding so I can’t say under what circumstances it will use UNDEF, but I suspect it is because it’s getting a 400 level error code when attempting to access the URL. There should be errors in the logs I would expect. If not put the binding into debug logging and see if it tells you what is going wrong.

For debugging purposes, you can add another channel and Item to your HTTP Thing to just show the raw string that you get. Might even see an authentication challenge!

Hi rikoshark,

Thanks for the reply. Not 100% how to go about getting the details you refer to. How do I get the YAML code your asking me. Also from a log file aspect I am only seeing the below in the logs.

2021-01-21 14:11:26.471 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing ‘http:url:0a2900a796’ changed from UNINITIALIZED (HANDLER_INITIALIZING_ERROR): The transformation pattern must consist of the type and the pattern separated by a colon to UNINITIALIZED
2021-01-21 14:11:26.528 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing ‘http:url:0a2900a796’ changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)

How do I put the binding into debug mode?

Your error message is complaining about the parameter form that you have given. I don’t know if you are still working with a profile or directly on the binding channel.

Great news it seems to be working now. Have no idea at all what changed as I didnt edit anything but suddenly started getting the correct values coming in. Thanks so much for your help guys could not have done it without you.

Almost everywhere MainUI you will see atab at the top called Code. Click on that.

Make sure to look in openhab.log for errors too.

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