[solved] HTTP Binding: Problems with sending a Z-Wave command

Hello openHAB users

I’m quite new with using OH and I’m lost with using the HTTP binding. I do have a small Z-Wave network with 7 nodes. All connected to a Razberry board placed on a RasperryPi. Now I would like to add some commands on my second Raspberry where openHAB is running (without using the Z-Wave binding). Now my problem:

If I’m using the command directly in the web browser:

http://192.168.71.141:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_2-0-37/command/on

then I can turn on my Fibaro wall plug. But if I’m using the same command in OH then nothing happens:

.items
Switch	zwdPlug1 "Dose 1"	(Plugs) { http=">[ON:POST:http://192.168.71.141:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_2-0-37/command/on] >[OFF:POST:http://192.168.71.141:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_2-0-37/command/off" }
Switch	zwdPlug2 "Dose 2"	(Plugs) { http=">[ON:POST:http://192.168.71.141:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_5-0-37/command/on] >[OFF:POST:http://192.168.71.141:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_5-0-37/command/off" }

Inside the log file 2015_09_09.request.log I do see the following entries:

192.168.71.22 -  -  [09/Sep/2015:16:22:47 +0000] "GET /CMD?zwdPlug1=TOGGLE&__async=true&__source=waHome HTTP/1.1" 200 13 
192.168.71.22 -  -  [09/Sep/2015:16:22:41 +0000] "GET /openhab.app?sitemap=default&poll=true&__async=true&__source=waHome HTTP/1.1" 200 3964 
192.168.71.22 -  -  [09/Sep/2015:16:22:57 +0000] "GET /CMD?zwdPlug1=TOGGLE&__async=true&__source=waHome HTTP/1.1" 200 13 

That looks right, doesn’t it? Return state 200 is good!?

Does anyone has an idea what I’m doing wrong or what I forgot?

Cheers
-Prom

The major difference I see is when you use the URL in your web browser it is doing a GET but in your OH Items it is doing a POST which are two different things.

I don’t have much experience with the HTTP Binding but try changing your http=">[ON:POST: to http=">[ON:GET:

The wiki page for the binding implies that it might support HTTP commands other than POST.

If that isn’t it I don’t know what the problem is.

Good luck!

Rich

Hi Rich
Thank you for your tip but unfortunately that didn’t help. It is also not working!

I was reading in the HTTP-Binding Wiki that using “curl” might be an option. So I tried on the console:

pi@raspberrypi ~ $ curl http://192.168.71.141:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_5-0-37/command/on
{"data":null,"code":200,"message":"200 OK","error":null}
pi@raspberrypi ~ $ curl http://192.168.71.141:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_5-0-37/command/off
{"data":null,"code":200,"message":"200 OK","error":null}

And it worked! Blessed with this success I tried out the Exec-Binding:

.items
Switch 	zwdPlug2 <Plugs> { exec=">[ON:/opt/openhab/configurations/scripts/turnPlugsOn.sh] >[OFF:/opt/openhab/configurations/scripts/turnPlugsOff.sh]" }

And now it works! But I still would like to know what I’m doing wrong with the HTTP-Binding! I thought, that is the reason why having this kind of binding at all!?! Or is it quite common to use “curl” commands to the different devices?

Cheers
-Prom

PS.
Maybe that is peanuts for most of the people here but this is my shell-script that I’m using:

 turnPlugsOn.sh

 #!/bin/bash
 curl -s http://192.168.71.141:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_2-0-37/command/on
 curl -s http://192.168.71.141:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_5-0-37/command/on

Like I said, I don’t have much experience with the HTTP binding. Perhaps the binding doesn’t support GET and only supports POST.

A lot of web based APIs use a REST type interface which supports HTTP POST and HTTP PUT commands for interaction with them. This appears to be what the HTTP Binding was created for. However, for APIs that are just based on the HTTP GET command, it would appear the HTTP Binding is not suitable and you have to use CURL. At least for now.

You can also send GET commands using the sendHttpGetRequest(String url) in a rule as yet another way to activate your devices.

Rich

I see that the closing ] is missing in the binding strings before the double quote mark at the end of each line. Also Richard’s point about using the correct GET vs. POST method is important.

1 Like

Damn, how embarrassing! Yep, that solved my issue!
Sorry for such a stupid problem!
Cheers
-Prom

Hi,
I guess its off topic but can anyone guid me how to use the http command to turn on or off the fibro switch like http://192.168.71.141:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_2-0-37/command/on.
I have Aeon z wave stick connected to linux based laptop.