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, (relay ON) ;, (relay OFF);

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

Then it’s OFF send to browser

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


Switch relay "Label"


rule "Activate Relay"
    Item relay changed
    if(relay.state == ON)  sendHttpGetRequest("")
    else sendHttpGetRequest("")


Switch item=relay

see wiki.
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.


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

Hi rikoshack,

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

if(right.state == ON) sendHttpGetRequest(“”)
else sendHttpGetRequest(“”)

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 "" 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!