Clone this wiki locally
The HTTP protocol can be used to execute HTTP get commands to either retrieve information from an URL or if you have a device that can be controlled via HTTP you can use this protocol to talk to your device.
OpenRemote Online Designer
Let's create a command which calls the Weather Underground API and extracts the temperature of a given location. We will use the command with a sensor to print the temperature on our user interface. If you want to use this weather service you can sign up for a limited free account here.
Create new Device
In "Building Modeler", create new device (New>New Device)
Still in "Building Modeler", select the device that was created in step 1 and click on New>New Command Specify a name and select "HTTP" as protocol.
Protocol specific settings:
- URL - The URL which will be called
- HTTP Method - Specifies the HTTP request method GET is the safest and mostly used form, but specific applications may define their own preferred method.
- Content-Type - Specifies type of media. Can be left blank, unless explicitly specified for a specific application as e.g. the XBMC application.
- Workload - Can be String (eg. JSON data) which is send with the POST and PUT methods (Example also on XBMC page).
- Username - If the URL is password protected, you can provide a username.
- Password - Here comes the password of that user.
- XPath expression - If the returned page is a XML document, you can use Xpath to extract information from that XML. See our short introduction to Xpath usage.
- Regular expression - If the result is not XML, you might be able to use a regular expression to extract the information you need.
- Polling interval - If you link this command to a sensor, the polling interval is used to update the sensor periodically.
- JSONPath Expression - which can be used to extract data from a JSON response, examples can be found here. Stefan Goessner's mini tutorial on JSONPath.
The Wunderground Weather API URL looks like this:
http://api.wunderground.com/api/YOUR_KEY/conditions/q/de/BIELEFELD.xml Replace YOURKEY with the number you received from Wunderground. The Xpath expression for temperature in C is //response/current_observation/temp_c Use polling of 10 minutes to not exceed the limits of free usage of Wunderground
Since we are not going to add any other command, click on "Submit".
The command will return a value and we want that value to be printed in out UI. For this we need a sensor that is linked to our command. I will use a custom sensor wich will just return the result as a string.
Done! Now we have the device, the command and the sensor.
Use commands in UI Designer
Now we switch to the UI Designer and create our user interface. The panel will contain 2 labels. One has a static text and the other one is linked to our sensor.
It's currently 5 degrees in Bielefeld :)