JSONPATH transformation - help with parsing type

I am new to openhab & just starting out. I have tried using examples & other forum posts to address my problem with no success. I am using openhab 1.7 on Raspberry PI.
I am trying to get my current PV output power (amongst other items) - PAC from a Fronius Symo inverter, using JSONPATH to extract the value from a js object. I am using the following ITEM:
Number Current_Power “Current Power [%.1f Kw]” (Solar) {http="<[http:///solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData:10000:JSONPATH($…Body…PAC.Value.)]"}

But I am seeing the following errors in my openhab log file & there is no value updated on the web page.

2016-03-03 11:28:06.270 [DEBUG] [g.openhab.io.net.http.HttpUtil] - About to execute 'http:///solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData’
2016-03-03 11:28:07.096 [DEBUG] [g.openhab.io.net.http.HttpUtil] - {
“Head” : {
“RequestArguments” : {
“DataCollection” : “CommonInverterData”,
“DeviceClass” : “Inverter”,
“DeviceId” : “1”,
“Scope” : “Device”
},
“Status” : {
“Code” : 0,
“Reason” : “”,
“UserMessage” : “”
},
“Timestamp” : “2016-03-03T11:08:53+11:00”
},
“Body” : {
“Data” : {
“DAY_ENERGY” : {
“Value” : 10560,
“Unit” : “Wh”
},
“FAC” : {
“Value” : 49.98,
“Unit” : “Hz”
},
“IAC” : {
“Value” : 16.04,
“Unit” : “A”
},
“IDC” : {
“Value” : 15.09,
“Unit” : “A”
},
“PAC” : {
“Value” : 3921,
“Unit” : “W”
},
“TOTAL_ENERGY” : {
“Value” : 10471064,
“Unit” : “Wh”
},
“UAC” : {
“Value” : 244.2,
“Unit” : “V”
},
“UDC” : {
“Value” : 346.9,
“Unit” : “V”
},
“YEAR_ENERGY” : {
“Value” : 1500613,
“Unit” : “Wh”
},
“DeviceStatus” : {
“StatusCode” : 7,
“MgmtTimerRemainingTime” : -1,
“ErrorCode” : 0,
“LEDColor” : 2,
“LEDState” : 0,
“StateToReset” : false
}
}
}
}
2016-03-03 11:28:07.098 [DEBUG] [.JSonPathTransformationService] - about to transform ‘{
“Head” : {
“RequestArguments” : {
“DataCollection” : “CommonInverterData”,
“DeviceClass” : “Inverter”,
“DeviceId” : “1”,
“Scope” : “Device”
},
“Status” : {
“Code” : 0,
“Reason” : “”,
“UserMessage” : “”
},
“Timestamp” : “2016-03-03T11:08:53+11:00”
},
“Body” : {
“Data” : {
“DAY_ENERGY” : {
“Value” : 10560,
“Unit” : “Wh”
},
“FAC” : {
“Value” : 49.98,
“Unit” : “Hz”
},
“IAC” : {
“Value” : 16.04,
“Unit” : “A”
},
“IDC” : {
“Value” : 15.09,
“Unit” : “A”
},
“PAC” : {
“Value” : 3921,
“Unit” : “W”
},
“TOTAL_ENERGY” : {
“Value” : 10471064,
“Unit” : “Wh”
},
“UAC” : {
“Value” : 244.2,
“Unit” : “V”
},
“UDC” : {
“Value” : 346.9,
“Unit” : “V”
},
“YEAR_ENERGY” : {
“Value” : 1500613,
“Unit” : “Wh”
},
“DeviceStatus” : {
“StatusCode” : 7,
“MgmtTimerRemainingTime” : -1,
“ErrorCode” : 0,
“LEDColor” : 2,
“LEDState” : 0,
“StateToReset” : false
}
}
}
}’ by the function '$…Body…PAC.Value.'
2016-03-03 11:28:07.100 [DEBUG] [.JSonPathTransformationService] - transformation resulted in '[3921]'
2016-03-03 11:28:07.100 [DEBUG] [.o.b.http.internal.HttpBinding] - transformed response is '[3921]'
2016-03-03 11:28:07.101 [DEBUG] [.o.b.http.internal.HttpBinding] - Couldn’t create state of type ‘class org.openhab.core.library.items.NumberItem’ for value '[3921]'
2016-03-03 11:28:07.103 [DEBUG] [ore.internal.items.ItemUpdater] - Received update of a not accepted type (StringType) for item Current_Power
2016-03-03 11:28:08.476 [DEBUG] [.o.m.c.i.folder.FolderObserver] - Refreshing folder ‘sitemaps’

If I have my item Current_Power as a STRING it works ok, but I would like to have it as a decimal number so that I can do calculations etc with it?

Any help would be appreciated.
Thanks

Did you try JSONPATH($.Body.Data.PAC.Value) ? If it’s still returning an array of answers, can you append [0] to the expression to return the first entry in the array?

That fixed it straight away, did not need to use the index [0].
Many thanks

my item definition is now:
Number Current_Power “Current Power [%d]” (Solar) {http="<[http://10.0.0.32/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData:10000:JSONPATH($.Body.Data.PAC.Value)]"}

Once again many thanks for your great reply & promptness.

2 Likes

Thank you. It worked also for my Symo inverter :slight_smile:

Hi, i also have a problem in OH2.

My .items-File looks like this:

Number PV_CURRENT “Aktuelle Leistung [%0f W]” (PV) {http=“http://192.168.178.38/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System:500:JSONPATH($.Body.Data.PAC.Value)”}
Number PV_DAY_ENERGY “Tagessumme [%0f Wh]” (PV) { http=“http://192.168.178.38/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System:500:JSONPATH($.Body.Data.DAY_ENERGY.Value)” }
Number PV_YEAR_ENERGY “Jahressumme [%0f Wh]” (PV) { http=“http://192.168.178.38/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System:500:JSONPATH($.Body.Data.YEAR_ENERGY.Value)” }
Number PV_TOTAL_ENERGY “Gesamtsumme [%0f Wh]” (PV) { http=“http://192.168.178.38/solar_api/v1/GetInverterRealtimeData.cgi?Scope=System:500:JSONPATH($.Body.Data.TOTAL_ENERGY.Value.1)” }
Number Current_Power “Current Power [%d]” (Solar) {http="<[http://10.0.0.32/solar_api/v1/GetInverterRealtimeData.cgi?Scope=Device&DeviceID=1&DataCollection=CommonInverterData:1000:JSONPATH($.Body.Data.DAY_ENERGY.Value)]"}

My Sitemap:

Frame label=“Photovoltaik” {

Text item=PV_CURRENT
Text item=Current_Power
Text item=PV_DAY_ENERGY
Text item=PV_YEAR_ENERGY
Text item=PV_TOTAL_ENERGY

}

Sitemap works, but there are no Values.