I am working HTTP binding to control(on/off) light from http link. I have added switch item in openhab and able to control light successfully. But if I put same link (127.0.0.1/cgi-bin/test.cgi?on) in browser, I am getting some success message like "Status OFF\ON". I want the same status to displayed on Openhab web page. How can I do this?
If you want to show on your sitemap the results from calling the URL you will need to use two Items and a rule to process the call to the URL.
Create a Switch Item to trigger the call. Don’t bind this Item to anything.
Create a String Item to store the result from the URL call.
Create a rule that triggers when the Switch Item is triggered. This rule will call the URL using the sendHttpGetRequest(url) action and store the string that comes back in the String Item.
Put both items on your sitemap.
If you want to just get some sort of feedback that your request was successful (or more importantly failed), instead of storing the result of the sendHttpGet action call in a String Item, check it within your rule and generate an alert with the status. If you are using my.openhab you can use the sendNotification action. Otherwise use your alerting mechanism of choice (e.g. Notify My Android, email, Twitter, etc).
Switch MyLight "My Light"
String MyLightResult "Last call to My Light returned [%s]"
Rules:
rule "Trigger light"
when
Item MyLight received command
then
val result = sendHttpGetRequest("url")
MyLightResult.postUpdate(result)
end
Sitemap:
Switch item=MyLight
Text item=MyLightResult
You may have to do some parsing and manipulation of result to extract just the string you want. If the call to postUpdate doesn’t work, change it to postUpdate(result.toString)