Wemo API with PHP and WemoServer

I have totally abandoned Wemo Connect and built my own Smartapp using virtual on/off buttons switches to control my wemo devices from ST. Works fine except that I must have a means to update these virtual switches if a wemo is controlled by means other than ST. Enter WemoServer…

The developer, MikeP, has recently added new functionality to his product that when one or more devices state changes it triggers (GET, PUT or POST) rule. This rule (can) contains the name, UDN and state of the device which one includes within the URL field of the rule. For instance, one can define a rule that when any device state is changed that WemoServer will call http://myServerIP:Port/myWemoParser.php?name=&name;&udn=&udn;&state=&state;” The php file then determines what url to create to change the state of the associated On/Off Button in ST.
i.e. $stURL=“http://graph.api.smartthings.com/api/smartapps/installations/nnnn/switches/nnnn/on?access_token=nnn”;

Having already authorized the appropriate devices within ST and having the means to create the appropriate ST url my problem is actually sending the command from my php program to ST. I know that this PHP program is creating the correct URL as I can copy it, paste it into a browser address bar and have it turn on/off/toggle the appropriate device.

Sorry for the lengthy post but I am lost at this point. I would have thought that if I can simply paste the PHP created URL into a browser and have it behave as intended I could do the same within php using something like header( “Location:” . $url); but even though the page is re-directed, that does not change the device state.

Help!!! :cold_sweat:

1 Like

Progess… sort of. :smirk:

Seems there is nothing wrong with the way I redirect the current PHP page. If I paste the URL http://myServerIP:Port/myWemoParser.php?name=&name;&udn=&udn;&state=&state;” into the browser address bar thereby bypassing WemoServer rule, the redirect occurs and the state of the ST switch changes as intended. When this same file is loaded via WemoServer rule however, the redirect does occur (according to the wemoserver log) but the state of the switch never changes.

Did you manage to make any progress on this? The default WeMo connect used by SmartThings is abysmal.

I have everything working near 100%. Over the past few months only problems have been that on occasions the Apache Server stops responding (solved by restarting the Apache server each day at midnight via Windows task) and, on very rare occasions, WemoServer needs to be restarted. Can’t recall when I last needed to restart the latter.

The problem I described above was solved via PHP using Curl.exe for Windows. In php it looks like

$url=“https://graph.api.smartthings.com/api/smartapps/installations/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx/”. $devType . “/” . $devID . “/” . $state .
$output = shell_exec('C:\curl\cURL\bin\curl ’ . $url);

Not pretty but it works.

1 Like