Outback MATE3 JSON parsing help

215 views
Skip to first unread message

Nathan Stratton

unread,
Feb 9, 2015, 10:49:08 AM2/9/15
to ope...@googlegroups.com
If I request: http://10.71.129.2/Dev_status.cgi?&Port=0

I get back:

{"devstatus": {
"Sys_Time": 1423478757,
"Sys_Batt_V": 48.2,
"ports": [
{ "Port": 1, "Dev": "GS","Type": "60Hz","Inv_I_L1": 1,"Chg_I_L1": 0,"Buy_I_L1": 0,"Sell_I_L1": 0,"VAC1_in_L1": 15,"VAC2_in_L1": 0,"VAC_out_L1": 113,"Inv_I_L2": 6,"Chg_I_L2": 0,"Buy_I_L2": 0,"Sell_I_L2": 0,"VAC1_in_L2": 3,"VAC2_in_L2": 0,"VAC_out_L2": 112,"AC_Input": "Gen","Batt_V": 47.6,"AC_mode": "NO AC","INV_mode": "Inverting","Warn": ["none"],"Error": ["none"],"AUX": "disabled","RELAY": "disabled"},
{ "Port": 2, "Dev": "GS","Type": "60Hz","Inv_I_L1": 0,"Chg_I_L1": 0,"Buy_I_L1": 0,"Sell_I_L1": 0,"VAC1_in_L1": 16,"VAC2_in_L1": 0,"VAC_out_L1": 114,"Inv_I_L2": 0,"Chg_I_L2": 0,"Buy_I_L2": 0,"Sell_I_L2": 0,"VAC1_in_L2": 3,"VAC2_in_L2": 0,"VAC_out_L2": 112,"AC_Input": "Gen","Batt_V": 47.6,"AC_mode": "NO AC","INV_mode": "Inverting","Warn": ["none"],"Error": ["none"],"AUX": "disabled","RELAY": "disabled"},
{ "Port": 4, "Dev": "CC","Type": "FM","Out_I": 6.3,"In_I": 2,"Batt_V": 48.4,"In_V": 112.7,"Out_kWh": 0.6,"Out_AH": 13,"CC_mode": "Bulk  ","Error": ["none"],"Aux_mode": "Manual","AUX": "disabled"},
{ "Port": 5, "Dev": "CC","Type": "FM","Out_I": 8.3,"In_I": 4,"Batt_V": 48.4,"In_V": 104.8,"Out_kWh": 0.8,"Out_AH": 17,"CC_mode": "Bulk  ","Error": ["none"],"Aux_mode": "Manual","AUX": "disabled"},
{ "Port": 6, "Dev": "FNDC","Enabled": ["A","B"],"Shunt_A_I":  -19.9,"Shunt_A_AH": -691,"Shunt_A_kWh":  -34.460,"Shunt_B_I":  15.1,"Shunt_B_AH": 399,"Shunt_B_kWh":  21.070,"SOC": 78,"Min_SOC": 78,"Days_since_full": 37.8,"CHG_parms_met": false,"In_AH_today": 31,"Out_AH_today": 147,"In_kWh_today":  1.490,"Out_kWh_today":  7.090,"Net_CFC_AH": -315,"Net_CFC_kWh":  -14.660,"Batt_V": 48.2,"Batt_temp": "7 C","Aux_mode": "auto","AUX": "disabled"}
]}}

I have done some searching on JSON and openhab but have not bee able to find many examples. I am trying to do things like pull the state of charge of my batteries from Port 6, SOC, or pull Batt_V also from Port 6.

Anyone with some JSON experience willing to help me with this?

Mark

unread,
Feb 13, 2015, 3:02:30 PM2/13/15
to ope...@googlegroups.com
Nathan,
Given your specific JSON, this JSONPath expression will extract the SOC from Port 6 (with a filter-expression):

$.devstatus.ports[?(@.Port==6)][0].SOC

From that, the others should be easy to derive.  I tested it using the Sample openHAB Rule:

// Test JSONPath

 

rule
"Test JSONPath"

when Time cron "0/10 * * * * ?"

then

   
var String json = '{
                "Shunt_A_kWh": -34.46,
                "Shunt_B_I": 15.1,
                "Shunt_B_AH": 399,
                "Shunt_B_kWh": 21.07,
                "SOC": 78,
                "Min_SOC": 78,
                "Days_since_full": 37.8,
                "CHG_parms_met": false,
                "In_AH_today": 31,
                "Out_AH_today": 147,
                "In_kWh_today": 1.49,
                "Out_kWh_today": 7.09,
                "Net_CFC_AH": -315,
                "Net_CFC_kWh": -14.66,
                "Batt_V": 48.2,
                "Batt_temp": "7 C",
                "Aux_mode": "auto",
                "AUX": "disabled"
            }
        ]
    }
}'

   
var soc = transform("JSONPATH","$.devstatus.ports[?(@.Port==6)][0].SOC", json)
   println
(soc)
end



I used this as a reference for the JSONPath capabilities:

Nathan Stratton

unread,
Feb 13, 2015, 5:13:01 PM2/13/15
to ope...@googlegroups.com
On Fri, Feb 13, 2015 at 3:02 PM, Mark <mr.gu...@gmail.com> wrote:
Nathan,
Given your specific JSON, this JSONPath expression will extract the SOC from Port 6 (with a filter-expression):

$.devstatus.ports[?(@.Port==6)][0].SOC

Thanks, so I would put that in say outback_soc.js in configuration/transforms/ dir? What would my item line look like?
 
From that, the others should be easy to derive.  I tested it using the Sample openHAB Rule:

Yep, just need one working to get started.
 

--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
To view this discussion on the web visit https://groups.google.com/d/msgid/openhab/5e99b056-0be0-44cf-a15a-d8588b213878%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark

unread,
Feb 13, 2015, 5:24:10 PM2/13/15
to ope...@googlegroups.com
If you have a look at the HTTP Binding doc:
https://github.com/openhab/openhab/wiki/Http-Binding

There's an example that uses the REGEX(...) transform on the HTTP result. It'll be similar to that, except using JSONPATH(...)

Nathan Stratton

unread,
Feb 13, 2015, 5:35:33 PM2/13/15
to ope...@googlegroups.com
Thanks, that is what I was missing, works perfectly now. 

Mark

unread,
Feb 13, 2015, 6:03:18 PM2/13/15
to ope...@googlegroups.com
Nathan,
You may want to post your completed, working, JSONPATH Transformation example so others can benefit (or improve the Doc and post it to the openHAB Transformations Wiki page for bonus points)

Mark

unread,
Feb 14, 2015, 12:45:55 PM2/14/15
to ope...@googlegroups.com
Perfect! Thanks for updating the examples page Nathan...
Reply all
Reply to author
Forward
0 new messages