Looking for tutorial on how to create items/things that talk to a http device

I have a RP3B with Openhab2 installed on it.
Using the paper gui I added the Wemo and Nest bindings. I then added the auto discovered wemo and nest things/items. That all worked (except that Nest shows ONLY celsius, can’t figure out how to get it to show fahrenheit.) Also added HomeKit support and figured out how to use the REST browser to add tags to allow it to show in IOS. So far, so good.
Now I’d like to add a home-made device that is a toggle switch to raise/lower the garage door. The device is reached with two http commands - one to toggle (i.e. momentary contact) and one to view the current status.
What files should I be modifying/adding on disk in /opt/openhab/conf in order to do this?
I tried creating an items file (items/GDOpener.items) containing

Switch GDOpener "Garage Door Opener" { http=">[OFF:GET:http://10.0.0.5/g.php?TOGGLE] >[ON:GET:http://10.0.0.5/g.php?TOGGLE]" }

and item showed up in the gui - I can’t do anything with it. Nothing else shows up in GUI.
I added a sitemap (sitemaps/GDOpener.sitemap)

sitemap GDOpener label="Garage Door Opener" {
  Frame item=GDOpener icon=garagedoor {
    Switch item=GDOpener label="GDOpenerOpen" mappings=[OFF="GDOpenerOpen"] visibility=[GDOpener==OFF]
    Switch item=GDOpener label="GDOpenerClose" mappings=[ON="GDOpenerClose"] visibility=[GDOpener==ON]
  }
}

and nothing showed up in the gui dashboard.
(so far, not even trying to display the current state of the device)
Any thoughts?

If going thru an API use.
etc/openhab2/services/http.cfg

Example http.cfg file

http:pihole.url=http://my.hole/admin/api.php?summaryRaw
http:pihole.updateInterval=1800000 

What happens when you use http://10.0.0.5/g.php?TOGGLE in a web browser?

So, basically, the TOGGLE url will open, close, or pause movement, on my garage door.
I also have a script on that host that will show the current state (from magnetic reed sensors)
That same script also shows the state of my front door.

I’d love to incorporate both the functional url and the display url into a single “widget” on the openhab2 paper dashboard AND make it all work in IOS via HomeKit.

I have no idea what to do with the http.cfg example - can you elaborate?

THANKS!

Not needed if you have a script that’s being used to get the info. Is the script running on the same RPI? If so, take a look at the EXEC binding.

To add a link on the dashboard see this topic.

Switch relays are not on same RPI. So, I am using http to get at them (and, besides, I want to learn how to do that!)
I can’t figure out how the text files and the internal database interact with each other, which takes precedence.
It seems to me that since the paper ui can’t do http stuff directly, there should be a very simple formula for adding these (read and write) to openhab2 that can be documented.
And, oh, I mistyped before - when I said “add link on dashboard” I meant add widget to paper ui dashboard - like one for a wemo switch or nest thermostat.

Ok, so you will need the http.cfg try creating and adding this:

You need to fill in the “yourinfo” part.

http:yourinfo.url=http://10.0.0.5/g.php?TOGGLE
http:yourinfo.updateInterval=60000 

Hi guys, I don’t want to storm your pary, here, but…
@yossie, what is the hardware of your homemade garage controller?

I suspect arduino/ESP8266.
In which case you should really look into using MQTT as a messaging service instead of HTTP
It will be far more efficient and much easier to use.

1 Like

My garage door opener and door sensor is a RP1 (!!) with a 8-relay board connected to it. Some tiny php read/writes to /sys/gpio pins to sense and operate the garage door.

I still can’t figure out how to get this to work in OH2 - every place I look on web, and here, I find hints and ideas but never a complete tutorial on how to connect a REST/HTTP data source to a widget on the paper ui dashboard.

Right now, this is what I have in my files:

services/http.cfg:

GDOpener.url=http://10.0.0.5/g.php?TOGGLE
GDOpener.updateInterval=60000 
Doors.url=http://10.0.0.5/s.php?GET
Doors.updateInterval=60000 

items/RP.items:

Switch GarageDoorOpener "Garage Door Opener" <GDopener> { http=">[ON:GET:http://10.0.0.5/g.php?TOGGLE] >[OFF:GET:http://10.0.0.5/g.php?TOGGLE]" }
String Doors "Doors" <Doors> {http="<[http://10.0.0.5/s.php?GET]"}

sitemaps/RP.sitemap:

sitemap RP label="RP" {
        Frame label="RP" {
                Text item=Doors
                Switch item=GDOpener
        }
}

After I put these three files in, I do see two items (Garage Door Opener and Doors) - but no things to match, and nothing on the Paper UI dashboard.

Use BasicUI to control and PaperUI to configure. You don’t necessarily need a “thing” just an item.

In the http.cfg file it should start with the url not the item name. In the first example

http:pihole.url=http://my.hole/admin/api.php?summaryRaw
http:pihole.updateInterval=1800000 

Im running pihole on a second RPI and connected to the pihole url via http:pihole.url=http://then the address here. I have no idea what should put here for a url but I assume you have that info, as it’s your system.

As @vzorglub mentioned above, it would be better to use MQTT over HTTP for this. Both RPI’s work well together using this protocol.

See https://www.openhab.org/docs/concepts/units-of-measurement.html#units-of-measurement. You probably just need to add |°F to the label for the Item and where you use the Item’s state in Rules.

First some basics. You have installed the HTTP Binding?

Why did you choose to use a manual installation instead of using apt-get or yum?

This can be collapsed to http=">[*:GET:http://10.0.0.5/g.php?TOGGLE].

What GUI and where in that GUI? PaperUI? If so then realize the two important things.

  1. HTTP is a 1.x version binding, the only thing you can do in PaperUI with 1.x bindings is install them and see that Items defined in .items files exist. They won’t appear in the “Control” tab and you can’t modify or do anything with them in PaperUI.

  2. PaperUI is intended for administration only and it can only really administer 2.x version binding’s stuff and stuff created in PaperUI. It cannot manage 1.x version bindings and it cannot manage stuff defined in text files manually.

Remove this from your sitemap. You already defined the label on your Item. Until you get this to work, get rid of the mappings and visibility to simplify the setup until you get it to work.

If I assume PaperUI, then see above.

I don’t think that is appropriate for this use case. The URL should only be hit when the user takes some action. Using http.cfg like this will cause the garage door to go up and down 1800000 milliseconds regardless of interactions with the Switch Item.

I don’t know anything about HomeKit so can’t answer anything about that. I think it should work through Hue Emulation.

But the first part, as I mentioned above, will not work. HTTP binding is a 1.x binding. Only Items that are linked to Channels (a 2.x version binding concept) appear in the Control tab of PaperUI. You must create a sitemap or build a HABPanel. If you want everything displayed in a single widget, you will need to settle on HABPanel and probably have to build the custom widget yourself.

I’m going to agree with H102 and Vincent, MQTT is a much better choice for this. I have the exact same setup as you for my garage doors, only I’m running on an RPi 3. I wrote and published https://github.com/rkoshak/sensorReporter as a result. For something like this you only need to configure a GPIO actuator and a couple of GPIO sensors and the MQTT connection and you are done.

The big reason you want to use MQTT for the sensors at least, you want immediate notification of a change in the sensor with the minimum amount of wasted computer effort. This means you want to push the sensor readings, not pull them. The HTTP binding can only poll the sensors every x seconds for a change.

MQTT isn’t the only way to do this. sensorReporter will also support pushing the sensor readings to the OH REST API instead of using MQTT if you set up the HTTP Connection instead.

So I’ll continue.

See the HTTP binding README. You are basically already there with your Item definition and sitemap. But the key is to realize that you won’t be able to interact with these Items in PaperUI.

These are based on OH 2.x version bindings so PaperUI is able to show them. It cannot do the same for HTTP.

That’s because it cannot be done.

Get rid of the first one. The second one is fine but you probably want to use a polling period of 1000 (assuming your device takes less than a second to respond). You don’t want to have to wait a minute before you know if the door is open or not. See the discussion about polling versus push above.

For the opener Item see my version above. You can use * instead of creating a separate binding config for each command type.

For the sensors, see https://www.openhab.org/addons/bindings/http1/#example-of-how-to-configure-an-http-cache-item for how to properly configure the Item to work with the config in http.cfg.

There are no Things and PaperUI will not show these Items.

Just to be clear, it’s not that Things are optional in this case. The HTTP binding is a 1.x version binding. It doesn’t have Things at all.