Get data via Apiary API

Discussions about RaZberry - Z-Wave board for Raspberry computer
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Get data via Apiary API

Post by pz1 »

I try to get some data from [module] OpenWeather. Ultimately I do want to use that data in a rule. For the moment I just want to get it to OpenRemote. I guess the Apiary API is the way to go. However I do get a problem understanding the documentation. I would expect to get the temperature with:

Code: Select all

http://raspberry:8083/ZAutomation/api/v1/devices/OpenWeather_72/data/metrics/level
OpenWeather_72 is the internal id of the OpenWeather widget. But is says: not found
{"data":null,"code":404,"message":"404 Not Found","error":"Device OpenWeather_72/data/metrics/level doesn't exist"}
A call with only rhe widget id yields the following JSON blurp:

Code: Select all

{
	"data" : {
		"creatorId" : 72,
		"deviceType" : "sensorMultilevel",
		"id" : "OpenWeather_72",
		"location" : null,
		"metrics" : {
			"scaleTitle" : "°C",
			"title" : "Leens",
			"probeTitle" : "Temperature",
			"level" : 0.7,
			"icon" : "http://openweathermap.org/img/w/01d.png"
		},
		"permanently_hidden" : false,
		"tags" : [],
		"updateTime" : 1423210517
	},
	"code" : 200,
	"message" : "200 OK",
	"error" : null
}
With an online JSONPath tester using
data.metrics.level
results in:
'0' => "0.7"
Whatever separators I use in the full http string; no success. What am I doing wrong?

Update 13:51 On OpenRemote I can get the correct value using:

Code: Select all

URL:      http://raspberry:8083/ZAutomation/api/v1/devices/OpenWeather_72 
Method:          GET
Content-type: application/json
Polling:           5m
JSONPath:      $.data.metrics.level
Can't I reach this deep with Apiary API?
Since 29-12-2016 I am no longer a moderator for this forum
zorro
Posts: 1
Joined: 08 Feb 2015 12:23

Re: Get data via Apiary API

Post by zorro »

Perhaps json-csv.com has a tool to help you. They are good at extracting data from JSON feeds.
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Get data via Apiary API

Post by pz1 »

zorro wrote:Perhaps json-csv.com has a tool to help you. They are good at extracting data from JSON feeds.
Thanks for taking the effort.
I do not need/want other tools. I just want to know from the developers why I apparantly can't JSONPath to the full depth of the tree
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Get data via Apiary API

Post by pofs »

That's probably how the internal request router is written. Can't say much more here, as I'm not really involved with the JS part of the project.

Try asking PoltoS :)
dolpheen
Posts: 119
Joined: 10 Feb 2015 00:38

Re: Get data via Apiary API

Post by dolpheen »

Looks like the '/ZAutomation/api' request is managed by webserver.js (on github)
There are only 3 patterns for request:
/devices
/devices/:dev_id
/devices/:v_dev_id/command/:command_id
So you can only get all devices, device with device_id or make command on device.
For you request (devices/OpenWeather_72/data/metrics/level) there is no parser so it returns 404 error
Razberry B+ 2.0.1-rc25 on ZW500 + 15 devices / Razberry B 2.0.1-rc25 on ZW300 for test
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Get data via Apiary API

Post by pz1 »

dolpheen wrote:So you can only get all devices, device with device_id or make command on device.
That is what I understood from the Apiary API documentation. But why specify "Device attributes" for the api if you can't select them directly? To me it looks as if the API has not yet been implemented to its full extent.
dolpheen
Posts: 119
Joined: 10 Feb 2015 00:38

Re: Get data via Apiary API

Post by dolpheen »

pz1 wrote:To me it looks as if the API has not yet been implemented to its full extent.
For me 'ZAutomation/api' is pretty RESTful and there is no problem to parse JSON on client side. Of course it has ways for improvments, nothing is perfect :)
If am right OpenRemote provide some specification(correct me if I am wrong) for REST API (defined schemes for URL, returened values, etc), that is what zway 'OpenremoteHandler' API module is for. But it handles only physical devices, so, I think you can ask for improvement, create issue or pull request on github.
Razberry B+ 2.0.1-rc25 on ZW500 + 15 devices / Razberry B 2.0.1-rc25 on ZW300 for test
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Get data via Apiary API

Post by pz1 »

dolpheen wrote:For me 'ZAutomation/api' is pretty RESTful and there is no problem to parse JSON on client side. Of course it has ways for improvments, nothing is perfect :)
I am not complaining. I am aware this is very much work in progress.
If am right OpenRemote provide some specification(correct me if I am wrong) for REST API (defined schemes for URL, returened values, etc), that is what zway 'OpenremoteHandler' API module is for.
Actually I am the original developer of RaZ-OR, which grew into OpenRemoteHelpers, so I do understand how it works :)
But it handles only physical devices, so I think you can ask for improvement.
As suggested by Pofs I already send a note to Sergeui for explanation
dolpheen
Posts: 119
Joined: 10 Feb 2015 00:38

Re: Get data via Apiary API

Post by dolpheen »

pz1 wrote: Actually I am the original developer of RaZ-OR, which grew into OpenRemoteHelpers, so I do understand how it works :)
:D Good job!
Then I see it's should be pretty easy for your to update the OpenRemoteHelper to parse vDev request to get values from it and propose the modification for community.
Razberry B+ 2.0.1-rc25 on ZW500 + 15 devices / Razberry B 2.0.1-rc25 on ZW300 for test
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: Get data via Apiary API

Post by pz1 »

dolpheen wrote:Then I see it's should be pretty easy for your to update the OpenRemoteHelper to parse vDev request to get values from it and propose the modification for community.
Since last year the OpenRemoteHelper already has a "stub" for metrics provided by Yurkin Vitaliy. That can get the attributes.

Code: Select all

http://raspberry:8083/OpenRemote/metrics/ZWayVDev_zway_15-3-49-1/
13.18
Internally it does something like:

Code: Select all

http://raspi:8083/JS/Run/controller.devices.get("ZWayVDev_zway_15-3-49-1").get("metrics:level")
13.18
Some variants on that can easily be provided.
note: See http://docs.zwayhomeautomation.apiary.io/#devices for a list of device attributes

My original question was not getting things to work (I know that), but to understand how the Apiary API is supposed to work in the end. That is the question for the Zwave>Me team.
Since 29-12-2016 I am no longer a moderator for this forum
Post Reply