HTTP Binding ON OFF command?

Hello I wanted to ask.

I’m new on OpenHAB. Can any body help?

I need I think a HTTP binding to control the relay.

Relay works then I type on browser
http://192.168.1.14:30000/31, (relay ON) ;
http://192.168.1.14:30000/32, (relay OFF);

How can I wrote to openHAB commands then I Switch the light Switch and it goes ON the OpenHAB sends a command 192.168.1.14:30000/31 to browser?

Then it’s OFF send to browser 192.168.1.14:30000/32.

I think the easiest way to do this is through a rule:

Items:

Switch relay "Label"

Rules:

rule "Activate Relay"
when
    Item relay changed
then
    if(relay.state == ON)  sendHttpGetRequest("http://192.168.1.14:30000/31")
    else sendHttpGetRequest("http://192.168.1.14:30000/32")
end

Sitemap:

Switch item=relay

see wiki. https://github.com/openhab/openhab/wiki/Http-Binding
define a switch in items and use the syntax documented above.

Thank you a lot but I get this message in terminal where can be a problem?

“Error during the execution of rule ‘Activate Relay’: host parameter is null”

Well that doesn’t make a whole lot of sense. According to the wiki you just need to supply a String URL and we are in that rule. Is your running rule just like the example above or are you doing some other stuff to construct the URL?

If you are supplying the URL inline like above I’ve no recommendations. If you are constructing the URL String, try logging it out before the httpGetRequest to make sure the String is actually being constructed correctly.

Rich

Worked! Thank you a lot, I missed “http://” in front of IP.

Hi Jurgis,

I am planning to do exactly as you have for my garage door opener using ESP8266 connected to a relay module. What did you use with your relay? Do you have the codes you used to share? Thanks for your post. I think I’m getting closer to my end goal after seeing it.

Hi, Rommel

I used arduino ethernet module, that is working with http commands. Then
you send http command relay goes to open or close :slight_smile: But I think it’s
better to use wifi arduino module that is working with your router with
internet.

Hi rikoshack,

I have tried your step above, but cant controll my ip cam. I tried to send :
Rules:

if(right.state == ON) sendHttpGetRequest(“http://192.168.0.100:81/moveptz.xml?user=admin&password=admin&dir=right”)
else sendHttpGetRequest(“192.168.0.100:81/moveptz.xml?user=admin&password=admin&dir=stop”)
end

Do you have any sugestion how send correct command?

Thank you in advance

Do those commands work from the command line using curl? If not try curl -d. If curl -d works you need to use sendHttpPostRequest instead of sendHttpGetRequest.

If neither works there is something wrong with the URL.

One thing I do note is in your “else” you are missing the “http://” part of the URL.

Hi, thank you for your fast respond. Im on windows machine and curl not installed. Yes i forgot to put “http://” on sample above. But on my rules it does have “http://”.

But if i type it directly " http://192.168.0.100:81/moveptz.xml?dir=right" on browser it works. I have changed code on my rules to sendHttpPutRequest still no respond.

Not PUT, POST, as in sendHttpPostRequest.

You can install curl on a Windows machine and highly recommend it for debugging this sort of problem.

Putting it into the browser implies that GET is the right HTTP command, though web browsers are way better able to handle weird cases than the OH http actions.

Hello all, I am running openHAB2.4 and I have been trying to figure out how to turn a light on by sending a request over HTTP (http://openhabianpi:8080/light=ON) I’ve been scouring the internet for two days and reading everything I can find trying to figure out how to do it. I have HTTP bindings installed but I cannot figure out how to do it! I think you have to somehow write a rule that listens for a HTTP request. Can anyone tell me if I’m correct and point me in the right direction on how to do that? Thank you for any help in advanced!

Install the REST API Documentation from the Misc tab in PaperUI. Open the docs and it will show all the REST API endpoints. To send a command to an Item in OH I think you need to use an HTTP PUT. The docs are interactive so you can make calls from it and it will tell you the equivalent curl command. From there you can translate to whatever you have that is generating the HTTP request.

The HTTP binding is not required. That is to make OH issue HTTP requests to other services.

That was very helpful! It worked and it made the difference between THINGS and ITEMS clear. Thank you for the help!