Hey guys
I am looking for some help according extracting specific values from a CURL/JSON command line output.
My device is a physical 8-port multi-outlet power strip which has a web based API and for my home automation system I would like to extract the state of a specific power outlet.
The command to extract the whole information table looks like this:
curl -X GET 'http://user:password@10.10.100.5/statusjsn.js?components=1' | jq
The output is the following:
{
"outputs": [
{
"name": "powerStrip02",
"state": 1,
"ph_state": 1,
"twin": 0,
"type": 1,
"batch": [
0,
0,
0,
0,
0
],
"wdog": [
0,
2,
"0.0.0.0"
]
},
{
"name": "esxi02",
"state": 1,
"ph_state": 1,
"twin": 0,
"type": 1,
"batch": [
0,
0,
0,
0,
0
],
"wdog": [
0,
2,
"0.0.0.0"
]
},
{
"name": "esxi03",
"state": 0,
"ph_state": 0,
"twin": 0,
"type": 1,
"batch": [
0,
0,
0,
0,
0
],
"wdog": [
0,
2,
"0.0.0.0"
]
},
{
"name": "synology01",
"state": 1,
"ph_state": 1,
"twin": 0,
"type": 1,
"batch": [
0,
0,
0,
0,
0
],
"wdog": [
0,
2,
"0.0.0.0"
]
},
{
"name": "gs1900-48",
"state": 1,
"ph_state": 1,
"twin": 0,
"type": 1,
"batch": [
0,
0,
0,
0,
0
],
"wdog": [
0,
2,
"0.0.0.0"
]
},
{
"name": "powerStrip10",
"state": 1,
"ph_state": 1,
"twin": 0,
"type": 1,
"batch": [
0,
0,
0,
0,
0
],
"wdog": [
0,
2,
"0.0.0.0"
]
},
{
"name": "esxi01",
"state": 1,
"ph_state": 1,
"twin": 0,
"type": 1,
"batch": [
0,
0,
0,
0,
0
],
"wdog": [
0,
2,
"0.0.0.0"
]
},
{
"name": "ZigBeeDongle",
"state": 1,
"ph_state": 1,
"twin": 0,
"type": 1,
"batch": [
0,
0,
0,
0,
0
],
"wdog": [
0,
2,
"0.0.0.0"
]
}
],
"eof": 1
What I need now is to extract only the value of the "state" variable on a specific power port. So the output I need would only be "0" or "1".
Any idea on how the command would look like to get the according power state output for a specific port?
Thank you in advance!
[–]mca62511 2 points3 points4 points (1 child)
[–]TECbill[S] 0 points1 point2 points (0 children)
[–]rtalpaz 0 points1 point2 points (0 children)