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
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.
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.
I used arduino ethernet module, that is working with http commands. Then
you send http command relay goes to open or close But I think it’s
better to use wifi arduino module that is working with your router with
internet.
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://”.
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.