How to send http request?

If I open page, then my lamp is ON. - toggle to OFF.
How to set up OpenHAB for this?
Thank you in advance

1 Like

Look at the HTTP Binding

I had the same problem when I started with openHAB, I ended up doing it like this.


Switch networkLamp "Lamp"


Switch item=networkLamp


rule "Network Lamp ON"
	Item networkLamp received update ON

rule "Network Lamp OFF"
	Item networkLamp received update OFF
1 Like

It is better to use the HTTP binding directly, e.g.

Switch networkLamp {http=">[ON:POST:]" >[OFF:POST:]"}

1 Like

If you want to have it in the rules then this might make it tidier:

rule "Network Lamp"
        Item networkLamp received command
        switch(receivedCommand) {
            case ON : sendHttpGetRequest("")
            case OFF : sendHttpGetRequest("")

Do you have any example on how to do that, when there are mapping involved too? I got a switch to control the pan and tilt on a webcam, and skipping the rules could make that a lot simpler to look at.

My sitemap is defined like this

Switch item=GarageCamPosition  label="Target" mappings=[0="Car", 1="Door"]

and the item like this

String GarageCamPosition "Camera position [%s]" <webcam> (all)

I do not see how this is related to the http binding.
I would stick with a rule in your case.

@martin_klimke, @rlkoshak, @Mikey Okay… At this point I think I’m just missing something blatantly obvious…

This is my items:

Switch Popcorn “Popcorn” { http=">[ON:POST:[4].instances[0].commandClasses[0x20].Set(255)] >[OFF:POST:[4].instances[0].commandClasses[0x20].Set(0)] }

My SiteMap:
sitemap home label=“The Smart Bachelor Pad”
Frame label=“Kitchen” {
Colorpicker item=TrackLights label="Kitchen Track Lights"
Colorpicker item=StripLights label="Kitchen Strip Lights"
Colorpicker item=lKitchen label="All Kitchen Lights"
Switch item=Popcorn label=“Popcorn Machine”
Frame label=“Living Room” {
Colorpicker item=Sconce label="Living Room Wall Lights"
Colorpicker item=lrLights label="All Living Room Lights"
Switch item=Fireplace label=“Fireplace” mappings=[PowerToggle=“On/Off”]
Frame label=“Main Controls” {
Switch item=BuildingDoors
Text item=DoorBell
Colorpicker item=gLights
Switch item=Sonos_Favorite mappings=[“Classic Rock’s Greatest Hits”=“Classic Rock”,“Wobblin’ Dubstep”=“Dubstep”,“Hazy Indie Summer”=“Indie”]

My log:
01:02:03.120 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'http.items’
01:02:03.153 [WARN ] [.internal.HttpGenericBindingProvider] - bindingConfig is NULL (item=Popcorn (Type=SwitchItem, State=Uninitialized)) -> process bindingConfig aborted!

What am I doing wrong!!??

You may have to escape or use URL encoding for the square brackets and parens that are part of the URL.

I’m still learning, but could you elaborate on how to escape them? Do I prefix it with “%” ?

So some quick google searching:

I made some adjustments to the items file:
[ = %5B
] = %5D
( = %28
) = %29

Switch Popcorn “Popcorn” { http=">[ON:POST:[4].instances[0].commandClasses[0x20].Set(255)] >[OFF:POST:[4].instances[0].commandClasses[0x20].Set(0)] }

I still get the same result tho :frowning:

To escape them put a \ in front of them.


I’ve made the following adjustments by prefixing it with “”. No change :frowning:

**Please note I have surrounded the \ with “” because when I originally posted it, the “” did not appear.

In my items file, I have prefixed every bracket and paran with \ no “” surrounding it.

Switch Popcorn “Popcorn Machine” { http=">[ON:POST:""[4""].instances""[0""].commandClasses""[0x20""].Set""(255"")] >[OFF:POST:""[4""].instances""[0""].commandClasses""[0x20""].Set""(0"")] }


17:49:55.597 [WARN ] [.internal.HttpGenericBindingProvider] - bindingConfig is NULL (item=Popcorn (Type=SwitchItem, State=Uninitialized)) -> process bindingConfig aborted!
17:50:33.816 [WARN ] [home.core.internal.items.ItemUpdater] - InstantiationException on org.eclipse.smarthome.core.library.types.StringType

That’s the point. By using the ‘’ you are telling the openHAB software not to interpret those characters as special and pass them through unchanged. You should not see the ‘’.

Right, that makes sense. In that case I did edit the items fie accordingly, unfortunately, the result is the same :frowning: .

Try to make it work with curl from the command line. There might be something wrong with the URL over all, a small typo or something.

1 Like

It looks like the trailing quote mark is missing. Is that not needed?

{ http=">[ON:POST: URL] >[OFF:POST: URL ]"}

1 Like

Good eye. Indeed the closing quote is required.

HA! Based on other things you’ve help me with my eye is only good when it’s not my config.

@rlkoshak @sc1982

Okay So I’m getting closer. I got it to work using curl!

curl ‘[7].instances[0].commandClasses[0x20].Set(0)’ -u admin


curl -g ’ curl ‘[7].instances[0].commandClasses[0x20].Set(0)’ -u admin

Now… I face the next hurdle… Looks like I can only send this command if I include the -u parameter. Is there a way I can pass two additional parameters in OH in the items file in order to send the request?