[ST Edge] Web Requestor: a driver to issue local POST and GET HTTP requests

@bickyb

@Alwas has a good point: if you were trying to fit the URL into an automation routine configuration, then that field is more limited. The pre-defined field in the web requestor device settings is longer. But like I said, if that still isn’t long enough, then try my HTTP Devices driver.

1 Like

Hi there, just wanted to thank you so very much for this. I am now using your HTTP device Creator V1 and its the best thing ever! .

i have to manally create and edit each switch (have 128 of them) but it is working great! i just post the Get command for on and off into the settings for each device, rename it move the room , set the icon and i am back in business!!

it doesnt update the switch status if the physical switch is pressed but i can live with that!

thanks again!! amazing stuff!!

2 Likes

Holy this is a super long thread even got a badge for all the reading I did, which is as least three quarters of it.

Ideally what I would like to achieve, and I am not sure if it’s even possible, is to have a tile that shows if my computer is on or off and being able to use this same tile to turn my computer on and off. Just like a lock, light bulb, etc.

This is what I have managed so far:

  1. I am using “TAustin’s [Edge] Wake-on-LAN” to Turn ON a Windows Computer

  2. I am using "TAustin’s [ST Edge] Web Requestor " to Turn OFF a Windows Computer
    (I am running a simple webserver to accept the GET command)

    • I used “ygerlovin’s [ST Edge] Virtual Things Edge Driver” to create a Momentary button.
      (“TAustin’s [ST Edge] vEdge Creator” is great too but I impatiently couldn’t find a momentary button/switch that didn’t make more than one tile in my Homebridge setup.)

    • I created an Automation routine to send the Get URL which is activated by the Momentary button.

This is all working great including voice commands via Alexa and Siri

  1. The next step in my mind was to monitor whether the computer is on or off. Unfortunately Windows Computer doesn’t play well with “TAustin’s [ST Edge] LAN Device Monitor”. So I thought since I had the webserver running anyway it seemed I should be able to use “TAustin’s [ST Edge] Web Requestor” to poll for HTTP Response Code 200 for ON and HTTP Response Code **Timeout for off.

But I can’t figure it out how to make this part work, if I create a routine with the IF section under Web Requestor there is the selection for HTTP Response Code while in the THEN section there is the selection for the GET URL request setting. Wouldn’t you need to first send the GET URL and then get a response code?

After part 3 is working I still need to figure out how to put it all together :)~

Any help/advice with what I am trying to achieve would be appreciated.

Yes. You’d really need a sequence of automation routines/rules:

1st Issue the webrequestor preconfigured request
-pause for a second-
2nd Test the response code field for 200; if not 200, assume PC is offline; if 200 assume online

Thank you so much for your work on this! I think I’m running into an issue with a header for authorization=bearer … Where after bearer is a 408 character token (for talking to a local Enphase envoy solar gateway). Any chance of a future version with at least an extra field that can concatenate with the headers field for the first web request in an instance?

Hi- Do you have any flexibility of providing the token either as a parameter in the URL, or as a JSON element as part of the body?

Kind of crazy to have an HTTP header value so long!

Yeah, it seems Enphase is really going the extra mile to make it unnecessarily complicated. In looking at this more, I’m not sure that even with the long header that it will be feasible.

Basically, you have to retrieve a JWT from their cloud api (the 408 character one) but it expires in a year, so that can be hard coded, but you have to GET a local endpoint url with the Authorization=Bearer JWT and also retrieve a sessionID from that request and then send both the JWT and the sessionID to the specific local endpoint, and it also appears to require HTTPS with certificate verification turned off. (Another limitation that smartthings can’t overcome at this point, right?)

So, with all that, I think the certificate verification is the deal breaker and maybe my suggestion isn’t needed…

Looks like I would need a local “relay” running on another device to take the request and do the ssl and pass back the response. I’ll keep playing around and brainstorming. So far I didn’t find any examples where the JWT could be passed in the body or url form encoded…

You might need a custom driver to handle this situation.

Yeah, that would be great if someone would develop one. Maybe someday I will be able to learn enough to cobble one together, but it’s probably a low priority for most, just based on a small installed base of people who have both SmartThings and an Enphase solar array (there are a pretty limited number of github repositories which are updated to interact with the Enphase v4 API, even).

In the meantime, I think I might be able to cobble something in python that will take a web requestor api query and and pass it along to the Enphase with the correct headers and ignore the HTTPS certificate, and retrieve the json response and send that back as the response to the web requestor request. Thanks again for helping me understand what I need to do.

DRIVER UPDATE NOTICE FOR HTTP DEVICES DRIVER
Version: 2023-03-06T19:03:54.090312374
Channel: SmartThings. Add a little smartness to your things.
README file: HTTPDevices/README.md at main · toddaustin07/HTTPDevices · GitHub


This update includes the following changes:

  • Switch device URL can now be configured with variable substitution using ${switch}; use the ‘Single HTTP Request’ fields in device Settings; separate on- and off-state URLs can also still be used instead
  • Added a switch to Dimmer device: switch state can be included in the URL string or request body with variable substitution: ${switch} (similar to ${level}). Note that switch and dimmer states are linked to behave like a typical light dimmer/switch. @Gavacac
  • Addition of Temperature & Humidity device: temperature and humidity values can be included in the URL string or request body with variable substitution: ${temperature}, ${humidity}

The new Temperature & Humidity device option may not appear right away in the creator device list. It may take a few hours to show up even after your hub is updated, and/or a restart of the SmartThings app.

2 Likes

Hi there, this is a GREAT driver. I been using it for a couple of moths now. And the Request/post function work great.
The only strange thing I notice is when am trying to edit (add action) some of my existing routines, in automations, the "HTTP device’ is not showing in the mobile App. But if I create a new routine the device shows, as expected.
I use the “reset app data” option in the settings. But the result is the same.

BTW. Im using the last app v1.6.97.13 in iOs 16.3.1

Any ideas what should I do? This is a normal? or if this is a iOs issue?
Thanks u all.

Thanks for the updates on HTTP Devices Driver. I’ve deployed it for my use cases and they all worked well!

1 Like

Ok I found a solution for this ST iOs App “error”.
It’s seems if you have an existing Routine with a scene, this prevents that some edge devices (at least the http request and mqtt devices) are shown in the app to be added.

But if you delete the scene execution, you can add the edge devices, then you can re-add the scene execution.

I hope this helps someone.

After many hours and a number of days, installing software, & learning a bit of JSON I finally I got part 3 working.
I created one Rule via Postman and 2 Routines
This is the Rule:

{
	"name": "Toggle switch on Web Req 200",
	"actions": [{
		"if": {
			"equals": {
				"left": { "string":"200"
                },
                "right": {
                    "device": {
                      "devices": [
                        "3b487bfc-f30c-4791-944c-c29804b18d96"
                        ],
                        "component": "main",
						"capability": "partyvoice23922.httpcode",
                        "attribute": "httpcode"
                    }
                    }
						},
			"then": [{
				"command": {
					"devices": [
						"7d34fca2-3784-454d-b9c1-b151bc587f6d"
					],
					"commands": [{
						"component": "main",
						"capability": "switch",
						"command": "on"
                    }]
                }
			}],
			"else": [{
				"command": {
					"devices": [
						"7d34fca2-3784-454d-b9c1-b151bc587f6d"
					],
					"commands": [{
						"component": "main",
						"capability": "switch",
						"command": "off"
					}]
				}
			}]
		}
	}]
}

Routine#1 If toggle switch is ON then GET URL: http://x.x.x.x:xxxx/test
Routine#2 If toggle switch is OFF then turn ON and turn OFF after 5 minutes

Not sure if this will help anyone as it seems rudimentary, and messy but it is working.

In the end it took 1 simple webserver, 3 Drivers, 4 Switches, 1 Rule, and 2 Routines to accomplish all this.

2 Likes

I’m just starting on using rules and although I can handle javascript etc JSON is not easy to visualise for a non-programmer. I also use this one, and another which I find helpful for duplicating /cutting ‘branches’ with it’s tree view.

1 Like

@TAustin this is awesome. Has anyone successfully made this work to control Fully Kiosk API for TTS? I can issue a this url (below) on my local network just fine, but when trying the “Web Reg Multi Master” I cant get it to play the sound. I have tried using different “web request” fields, all seem to take the URL configuration fine, but none will plat the sound. can anyone help?

http://192.168.1.:2323/?cmd=textToSpeech&text=Welcome+Home&password=[passhere]

Is the forwarding server/companion needed even if the endpoints I am hitting are all on my local network? Seems unnecessary, but, also seems like you have been through this!

It was a syntax issue on my end. the correct syntax is to use

“GET:http://192.168.x.x:2323/?cmd=textToSpeech&text=Front+Door&password=password

Works great except that I cant seem to get it to fire from an automation… Anyone know what I am missing now?

Did you configure your request in device Settings in one of the slots? Or are you trying to create an on-the-fly request?

Apologies in advance. I know next to nothing about using http with Smartthings. I’ve noticed a few mentions of Node-Red here and my goal is to send device status updates to node-red.

Has anyone used Web Requestor to update nodes in Node-Red? If so, I would very much appreciate a pointer on how it is done.

Thanks