[OBSOLETE] URI Switch -- Device Handler for controlling items via HTTP calls

Troy - Sorry for delay – have been tied up with work over past week. Will test out this weekend and give feedback. thanks for taking your time to work on this – greatly appreciated.

OK. We now have partial success!!!

The good news first. With one simple modification of the code (I hardcoded a new header pair for login authentication), I am now able to communicate between the SmartThings hub and the UPB hub and am able to turn “on” a set of lights.

Bad news - I am not able to turn the lights “off”. Looking at the debug log, I believe I see where the code is failing, but am not sure what controls this behavior. Here is the relevant output from the “ON” command in the debug log:


Here is the same line from the “OFF” command:


What is different between the two lines is that the “OFF” command is missing the ampersand, which is used to break up the body key pairs.

Thoughts on how to fix?

Whoops! That was my bad. I left out the ampersand in the Off section. I committed the change into the github repo. Hope it works now!

That did the trick. I will test with some other lights in the system and get back with some feedback later. Thanks again for all your help on this.

Thanks for writing this! I’m having trouble making this work. I’m able to run the following curl command:

curl -X POST --header “Content-Type: text/plain” --header “Accept: application/json” -d “OFF” “

And I see the following in my openhab logs:

Item: Light_FF_Bath_Ceiling got command OFF

But when I try to use the URI Switch device handler I don’t see anything in the logs and the lights do not turn on/off. My device preferences are:

external_off_uri text
external_on_uri text
input_off_key_1 text
input_off_value_1 text OFF
input_on_key_1 text
input_on_value_1 text ON
internal_ip text
internal_method enum POST
internal_off_path text /rest/items/Light_FF_Bath_Ceiling
internal_on_path text /rest/items/Light_FF_Bath_Ceiling
internal_port text 8080

I see the following in my ST logs:

uuid 3:46:23 PM: debug Executing ON
uuid 3:46:23 PM: debug resultPOST /rest/items/Light_FF_Bath_Ceiling HTTP/1.1
Accept: /
User-Agent: Linux UPnP/1.0 SmartThings
Content-Type: application/x-www-form-urlencoded

It don’t think ST is reaching out to my openhab box at all. They are both on the same private network. What am I missing?

Thanks, Jim

Getting the following error when trying to install the SmartApp from code:

No signature of method: script14833970056911486873372.metadata() is applicable for argument types: (script14833970056911486873372$_run_closure2) values: [script14833970056911486873372$_run_closure2@77475fe2] Possible solutions: getMetadata(), getState(), setState(java.lang.Object), metaClass(groovy.lang.Closure)

Quick update, I was able to confirm that ST is actually connecting to my openhab box, so I must have incorrect settings for my input off/on keys and input off/on values.

This is a Device Handler, not a SmartApp. Try it again under device handlers and it should work.

Jim, thanks for the feedback! The issue is that it only sends payloads over if there is a key and a value set, you’ve only got a value set. I’ll have to rethink the logic on that and get an update pushed out.

Jim, just pushed new code to GitHub. Pull the new version and try it now.

lol my bad. Duh

Thanks! I was actually able to get it to work by changing the following:

//"Content-Type": "application/x-www-form-urlencoded"
                "Content-Type": "text/plain"
            //body: myGroovyMap
            body: "OFF"

I will pull the new version this afternoon and try it. This will allow me to control my Insteon devices with Google Home.

1 Like

The DH also needs a fix on external call. Its missing the sendevent to save the state

Can you give me the output in your log? I’ve added the code to keep state but can’t get mine working because it’s complaining about a cert. See if the push works for you.

I just added the call and now it works fine saving the state.

if (external_off_uri){
def cmd = “${settings.external_off_uri}”;
log.debug "Sending request cmd[${cmd}]"
httpGet(cmd) {resp ->
if (resp.data) {
log.info “${resp.data}”
sendEvent(name: “switch”, value: “off”)

You manually change the code or did you pull the latest version from github?

I changed locally

This I assume works only with the newer X10 stuff, not the old RF Director series. Is that correct?

This works with anything that you can curl. Essentially if you can control it by going to a webpage, you can control it with this.

Hi @tguerena.

Do you know if it’s possible to also monitor state of the device being controlled and set the on/off button state upon change.

My use case is, using a slightly modified version of your excellent DH, I’m controlling a ControlByWeb WebRelay. This device allows me to send various URL commands to turn on / off plus turn on for xx mins. Similar to a MIMOlite, you can also turn off via a signal input too. - it’s very well made and good set of options.

My challenge is. If it turn on the relay via the ST device button, all good, the button shows ON correctly in the app. But if I turn the device off via another method eg physical switch or via the timer URL when it goes off the button in St will still show ON.

I know I can issue another URL command to obtain status, the URL returns XML showing status via a 1 or 0.


I just have no clue not being a developer to incorporate that and update the button status.

Is this possible and are there any examples where I can hack about to incorporate into the DH?

Many thanks in advance.

1 Like