Another use for the web Requester would be to control Puppeteer scripts.
I have used Puppeteer before now to control my Optima projector which only provides an HTML portal for controlling the device.
A more general use case for puppeteer would be to screen scrape websites for information that would provide context to our automations and therefore make them smarter.
I am making a new version of the Web Requestor driver available that contains a field to display any returned data from a web request. See my previous post regarding the interesting things you can display based on the returned data type - JSON, XML, HTML, etc.
For example, if you can set up simple web server on a local machine you can experiment with creating different html files and check out the nice formatting that is possible in a simple text field in the mobile app. You just have to keep the width and height of your page to something that fits nicely on the mobile screen.
Reminder that I also have a forwarding bridge program available if you want to reach internet addresses outside your local LAN, so if interested in that, DM me (I haven’t made it generally available yet)
This new driver is being made available separately from the original driver, but on the same shared channel. This will avoid any potential loss of all the saved web requests you have in the current driver. This driver will be listed in the channel web link as ‘Web Requestor v1.2’, and when installed on your hub and you do an Add device / Scan Nearby, you’ll get a new, separate device created.
I won’t be disabling the original driver version so feel free to keep on using it as long as you need, however all future enhancements will be built on the 1.2 version.
What I’d really, really, really like is for the Web Requestor driver to allow creation of multiple Web Requestor devices in the style of vEdge Creator. The limitation as things stand is that I have a single device that can send requests to multiple predefined URLs or a custom URL and it can trigger automations with the return value, but I don’t actually know what the request was.
Say for example that a GET to a TV on http://192.168.0.100:9000/ returns ‘Running’ that might be enough to identify the response as coming from a TV. However if I have two of the same brand of TV a GET to http://192.168.0.101:9000/ may also return ‘Running’ so if I see ‘Running’ I certainly don’t know which TV it was. If the TV is switched off the connection is refused but I don’t know that came from an attempt to connect to the TV. So really I need a Web Requestor device for each TV.
@TAustin, thanks a lot for the great work you did. I feel a bit more positive about Edge, since I am not an expert developer and need to convert some smartapps and DTH.
Is it possible (Simple way) to pass multiple parameters in a post command, here is my Curl POST command
There’s probably a few different ways to address this:
multiple devices as you suggested
adding some kind of prefix indicator (e.g. ‘9>’ to the response field to indicate which saved request it was from (1-50)
have a separate field that would be set to the number of the web request, or perhaps even the request string itself
#2 has the limitation where it wouldn’t help you if you sent a custom URL; #3 would definitely need to be the request string itself if it were to be useful for custom URLs
Just trying to think if there any other alternate ways to solve the problem, but providing a version of web requestor that could instantiate multiple devices wouldn’t be difficult.
Hi - you can define the string to be whatever you want. Sometimes spaces have to be substituted with %20 depending on the receiver, but that would be the only concern.
I’d thought about the other options, and there are probably also options at the end user level in automations and the like, but it rather felt like it was working against the architecture.
I am also wondering if ST have plans in this area. Web requests are so ubiquitous that it would seem odd if the Rules API didn’t end up with this capability, whether natively or indirecting through some other entity.
Great driver! Im using the web requestor to run my sonoff switches locally. I can execute on and off commands with a virtual edge device. I was wondering if you can react to only a part of the http request. Unfortunately when you request a status it returns not only the state but how long the device has been online. Since the http request response is always changing it’s imposible to react to it in a routine. Is there a way to react only to the first part of the http request (in other words react only to everything before the coma)? {“power”:“off”, “uptime”:“3 days and 23:51:59”} Hope this makes sense! Thanks in advance for the help!!!
Hi - I understand the challenge. Unfortunately there’s no function in either Automations or Rules to test for a substring in a device attribute. You can only test for equivalence to the entire string.
Just thinking out loud, but maybe one way to provide at least a bit more flexibility is to create capability fields that would separate out, say the first 3 fields in a json response. It would have to be limited to a fixed number of them (like 3) because it couldn’t be dynamic. I wouldn’t display them in the device details, but they’d be available for automations/rules.
I’ll give this some more thought, and maybe others might have better ideas. I’d want to make sure this would be a generally useful feature, so anyone else that would find this useful, please let me know.
EDIT: I’d want to do the same for XML responses. Maybe instead of having to do some number of them (e.g. 3), the most prevalent use case may be just grabbing and making available the first value found of any returned key/value pair in either JSON or XML. It’s not completely straightforward since json and xml content can vary tremendously, making consistent parsing a challenge.
SECOND EDIT: I’m thinking now it may be best to have a device preferences setting where you provide the key of a value you want to extract into a special field. But what if you have multiple different web requests each with their unique key value to be extracted? Well I think I’d have that covered with a new version of the driver I’m working on that lets you create multiple web requestor devices. With that, you’ll be able to configure web requests in their own unique device for easier use in automations (@orangebucket 's suggestion).
There may be a way to get creative in a Rule. It rather depends on what Rules are supposed to do with different types of data and what they actually do in practice.
For example, what do ‘greaterThan’ or ‘lessThan’ do when presented with strings, as seems to be permitted?
Take the string {"power":"on".
Is it the case that it evaluates as lexographically greater than any string beginning {"power":"off"?
Is it also true that it is lexographically less than any longer string starting with{"power":"on"?
Hey Todd, I completely switched over to the new driver but it seems to have stopped working a couple of days ago. I did notice that today when I clicked on the driver, it prompted me to install an update which was ~3MB.
When I select a web request to execute, it just spins. In my automation history, I see messages along the lines of “some devices are disconnected” which I am guessing is referring to the driver.
I will keep digging but was not sure if you or anyone else may be having the same issue.
I think this would work for local motion detection based on blue iris connected cameras. The current method uses BI Fusion smartapp. It works by setting a URL alert within blue iris and being seen as a motion sensor in ST. I’m not quite smart enough to figure it out at this moment, but this seems like another piece to transition more to local!
I had a similar situation with my Shelly Motion Sensor. You can configure it with a URL that it would send an HTTP GET request to whenever there is motion detected. However here’s the thing: these addresses usually also require a port number. But an Edge driver can’t request a specific port number on the hub. Even if you found out the port number the driver was using, it can and will change whenever the driver or hub is restarted. My solution is to use a intermediate server I have running on a separate, always-on machine (I’m using Raspberry Pi but could be any Linux/Windows/Mac machine). The device (in your case the blue iris camera) is configured to send its notification to the server at its fixed address. The Edge driver registers with that server, which tells the server: whenever you see a message from the given IP address, forward it to me at my current port. Works very nicely, and solves the general limitation of no fixed ports for Edge drivers.
I’m cleaning up my forwarding server and will be posting it as a shared project for anyone who wants to implement a similar scenario.
BTW, the server also overcomes another limitation of Edge drivers: they cannot directly communicate with any address outside your local LAN (like an internet address or the SmartThings API, for example). So my server also allows an Edge driver to send it an HTTP request which it will then forward to ANY address and return the response to the Edge driver. Works with Web Requestor!
At the request of @orangebucket, I have a new Web Requestor driver available that is designed to be more useful in acting on a web request response.
In the original version of Web Requestor, nothing was done with the response data other than to display it on the device details screen. It was possible to inspect the response data string from a Rule, but Rules has no way to look for a substring.
This new driver makes it easier to act on the response data with the following new features:
The HTTP response code + any errors are now returned in its own field. Automations/rules can test for ‘200’, for example, or for any other non HTTP-code error text which will begin with ‘**’
You can now have the driver extract a specific value from a JSON or XML response, based on a configured key name. If found, this extracted value will be placed in a new extracted key value field, which can be use in automations/rules. The key is specified in the device Settings (one per device).
Multiple web requestor devices can now be created to facilitate building automations/rules around an individual device’s web request(s). A button now appears in each device’s details screen to create a new device. Each device will continue to include up to 50 pre-configured web requests, in addition to the new option to specify a key for JSON and XML value extraction.
Because of the changes outlined above, this driver is being made available as a new driver, as opposed to an update of the previous. I’m trying to make sure I don’t disrupt existing devices or otherwise cause anyone to have to redo everything. What you can do, is run this new driver in parallel, and move your existing web requestor device to this new driver when you are ready. Your existing web requests will continue to work as they do today, but accessing the new features will be done under the new driver devices. Once you’ve moved everything over to the new driver, you can delete the old one.
To get the new driver, use my shared driver channel invite and select the “Web Requestor Multi v1.0” As always, give it some time to get loaded to your hub and then you can do an Add device / Scan nearby to get the initial device created.
Yes, and jolly useful it is too. With a single requestor device you could send request 1 and request 2 in quick succession and when a response came back you wouldn’t know which request it was for unless the content was diagnostic. With multiple requestor devices that issue is greatly reduced.
It is also nice to just be able to test the response code as sometimes that is all that matters. If you are just interested in whether a device is switched on pretty much anything other than a timeout means it is.