Raspberry Pi 4 Model B Rev 1.1 / 4GB
I am looking at using the HTTP Binding to be able to receive data from another device on the network and have read through the HTTP Binding docs and various posts but I’m not getting it. Is there a simple example of how Openhab would receive data from an HTTP Request that I could parse in a script (likely python) ? I have myopenhab.org configured as well.
Basically I am assuming I want something like:
Then an event for the HTTP request would trigger and it could parse the URL to retrieve the “data” element etc.
I can see in my log:
2021-05-21 08:49:30.619 [WARN ] [p.internal.http.HttpResponseListener] - Requesting 'https://myopenhab.org/testing' (method='GET', content='null') failed: 404 Not Found
So I know Openhab is seeing the request … but I’m obviously not understanding a lot here …
Is there a simple example someone can point me to?
You have the purpose of the binding backwards. The HTTP binding requests data from other devices, it doesn’t handle requests from other devices. openHAB is initiating the HTTP call.
Put another way, the HTTP binding doesn’t create a new web server with new URLs that other devices can use send HTTP requests to.
If your other device wants to request data from openHAB, it must use openHAB’s REST API. Under Developer Tools there is an interactive set of documents that will show you everything you need to know to get an Item’s state in openHAB from another device.
Ok thanks Rich … yes I have been playing around with the REST API and can get and set existing items in openhab (using curl) but obviously I’ve been going down the wrong path thinking the HTTP binding would help.
So … back to my example, if I change it to say:
How does that become a trigger so that my script can parse the URL?
As a simpler example, I can set a switch to ON or OFF using a curl like:
curl -X POST "http://openhabian.local:8080/rest/items/OhmTime" -H "accept: */*" -H "Content-Type: text/plain" -u oh.smartthings.someAPIToken: -d "OFF"
But in my case I want to send the Item a string and let it get parsed by the script.
Sorry for the basic questions but clearly I am confused
Ok … so its obvious … I just look for the Item to change just like always … answered my own question after falling into a rabbit hole thanks for setting me straight.