Page 1 of 2

Combine commands in one HTTP call

Posted: 30 Mar 2013 15:13
by pz1
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



You can combine two commands

Posted: 30 Mar 2013 15:13
by PoltoS
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.

Thanks. This is indeed not a

Posted: 30 Mar 2013 15:13
by pz1
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. )


You can easily convert 255/0

Posted: 30 Mar 2013 15:13
by PoltoS
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!

OK that conversion idea is

Posted: 30 Mar 2013 15:13
by pz1
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.

Hmm, Apparantly I did not get

Posted: 30 Mar 2013 15:13
by pz1
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?

A little bit progress

Posted: 30 Mar 2013 15:13
by pz1
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

This is certainly a problm of

Posted: 30 Mar 2013 15:13
by PoltoS
This is certainly a problm of URL encoding. This will work:
http://raspberry:8083/JS/Run/zway.devic ... :%22off%22

This does work indeed correct

Posted: 30 Mar 2013 15:13
by pz1
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.

The URL above does not create

Posted: 30 Mar 2013 15:13
by PoltoS
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.