Combine commands in one HTTP call

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

Combine commands in one HTTP call

Post by pz1 » 30 Mar 2013 15:13

I intend to use Razberry as a smart Z-Wave dongle from within Openremote (OR). OR has implemented the HTTP protocol that can deal with XMLPath, JSONPath,RegEx on returned values. It works fine with Razberry for binary switching using separate on/off buttons. But a toggle switch does not work, because that needs the switch Status.
Getting switch status involves 2 steps. 1) Get the status, and 2) Read the data element. OR has two problems. a) It can not sent two http calls in one command, and b) It needs the values "on" and "off" instead of the values 0 and 255 that the ZWayAPI returns.
I have been unable to cope with this within standard facilities of OR. It would be conceivable to develop a protocol for Razberry in OR. But that does involve programming in Java, and I am not a programmer.

So I started to wonder if it would be possible to construct a combined status call in Razberry. I guess that would require some JS programming returning either "on" or "off" possibly in some container. Again here my skills fall short.

I have seen a few users here who are quite good at these things. Could one of you provide an example solution for the combined commands:
http://raspberry:8083/ZWaveAPI/Run/devi ... [0x20].Get()
result:null
http://raspberry:8083/ZWaveAPI/Run/devi ... el.valueOf()
result: either 255 or 0

Or is this just a bad idea?

Thanks,
Pieter


Since 29-12-2016 I am no longer a moderator for this forum

User avatar
PoltoS
Posts: 4637
Joined: 26 Jan 2011 19:36

You can combine two commands

Post by PoltoS » 30 Mar 2013 15:13

You can combine two commands in one with semicolon as delimiter. JS will use the evaluated value of the last as the return of this set. So,

http://raspberry:8083/JS/Run/zway.devic ... evel.value
(I've mangled the requests a bit).

But keep in mind, that the level.value will contain the previous value, not last one, since the process is asyncronous - the Get command will be queued and no one knows when will it be executed! So, this is not the best design.

pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Thanks. This is indeed not a

Post by pz1 » 30 Mar 2013 15:13

Thanks. This is indeed not a good approach, and it wouldn't work with the OpenRemote HTTP protocol either.
What I actually was suggesting is to create a piece of JS on the raspberry which first did a Get() and next on getting the "null" response would read the data element. (which then would have the correct value I assume?) The same JS finally converts the 0 or 255 in the desired outputs (on/off in my case) before returning the result.
I am aware this is more complex than my trivial example here. I guess similar things would have to be done with other retreived values. It would make integration with OpenRemote, and possibly other platforms that support http protocols a lot easier.

Or in other words: Can I have an API call where I request the status of a device and get the answer in terms I specify as a parameter (e.g. on/off, 0/1, etc. )

Since 29-12-2016 I am no longer a moderator for this forum

User avatar
PoltoS
Posts: 4637
Joined: 26 Jan 2011 19:36

You can easily convert 255/0

Post by PoltoS » 30 Mar 2013 15:13

You can easily convert 255/0 to on/off [with (zway.devices[2].Basic.data.level.value ? "on" : "off")], but still the problem of async is here. You can not make a Get and read the value immediately - it would certainly be not executed yet!

Making a blocking request is a very bad idea!

pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

OK that conversion idea is

Post by pz1 » 30 Mar 2013 15:13

OK that conversion idea is progress. I hadn't picked that up from the docs. Thanks.
I'll see what the OR people have on offer.
Since 29-12-2016 I am no longer a moderator for this forum

pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Hmm, Apparantly I did not get

Post by pz1 » 30 Mar 2013 15:13

Hmm, Apparantly I did not get it. Within Chrome I manually called
http://raspberry:8083/JS/Run/zway.devices[2].Basic.Get()
followed by
http://raspberry:8083/JS/Run/zway.devic ... evel.value ? "on" : "off"
The first call returned null as expected. The second call only returned 0 whatever the status actually was. I did try the url both with and without spaces.
Without the question mark and the remainder it correctly returned 0 or 255.
What do I miss?
The online documentation seems to have gone, so I cannot check. Only 4 pages are available now.
I found an older version of the document on my PC. I also could not find that substitution syntax there. Again what do I miss? What other documentation is needed to learn about these 'hidden' functionalities?
Since 29-12-2016 I am no longer a moderator for this forum

pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

A little bit progress

Post by pz1 » 30 Mar 2013 15:13

Taking a different approach I have made a little bit of progress on this issue:
http://www.openremote.org/display/forum ... h+Razberry
From OpenRemote I can now succesfully queue a switch on/off followed by a Get.status.
Unfortunately the read data.value does not make it to the Razberry queue yet
Since 29-12-2016 I am no longer a moderator for this forum

User avatar
PoltoS
Posts: 4637
Joined: 26 Jan 2011 19:36

This is certainly a problm of

Post by PoltoS » 30 Mar 2013 15:13

This is certainly a problm of URL encoding. This will work:
http://raspberry:8083/JS/Run/zway.devic ... :%22off%22

pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

This does work indeed correct

Post by pz1 » 30 Mar 2013 15:13

This does work indeed correct in Chrome. Unfortunately as I have written in a mail to both Christian and you, if I send this URL from OpenRemote, I do not see it listed in the command queue. The Switch on/off and Get.status as send from OR do show up in that queue.
Since 29-12-2016 I am no longer a moderator for this forum

User avatar
PoltoS
Posts: 4637
Joined: 26 Jan 2011 19:36

The URL above does not create

Post by PoltoS » 30 Mar 2013 15:13

The URL above does not create a packet, but directly reads the value from Z-Way local data tree. The tree is updated by Get/Report mechanism by Z-Way itself.

By the way, note that each Set() usually executes a Get() too, so no nede to specify it explicitely in the URL.

Post Reply