Vera trigger from IFTTT (Maker), like Google Assistant/Home

I was able to setup a basic script that got the Vera working with IFTTT. I wanted to share what I have done so far, in hopes of collaborating some solutions to some of the problems. There are some security issues with using the Maker plugin, specifically around opening up the ports to control the Vera. While it can be done without any translation scripts, that left the Vera open completely, so secure devices, especially door locks, were a problem. The solution below still leaves less secure devices open (for now), until an authentication solution can be devised. A PHP script is being used as a wrapper to implement some of the security, and to automate some of the tasks. In my case, runs on a NAS/Home server, which already hosts other sites anyways. For me, this is a hold-over solution until Google releases the SDK, which will hopefully allow full (and direct local) integration with the Vera.

Basic problems to solve, which I think are doable:
1. Security - Should it require HTTPS and pass a password in the message? Any other ideas for authentication that works with Maker?
2. Move devices, like fans, appliances, thermostats, etc
3. Scene control
4. Control by room names
5. Maybe a rPi image that is almost plug-and-play
6. Find some way to eliminate PHP and host directly on Vera

The below configuration allows you to use Google Home to say something like “Set the kitchen lights to 100” or “Turn the kitchen lights on”. The name of the light is taken directly from Vera (allowing a “:” separated pre-pended label, because I label my devices).

Example IFTTT Maker configuration for Google Home:

Say a phrase with both a number and a text ingredient

What do you want to say?
Set the $ light to #

What's another way to say it? (optional)
Set the $ lights to #

What do you want the Assistant to say in response?
Setting the $ light to #

Maker response
Make a web request

URL
http://<ip_address_of_php>/data_request.php?action=dimmer&name= {{TextField}}&value={{NumberField}}

PHP Script to handle the dimmers (only dimmers implemented so far, as an example)
NOTE: Code is quick and dirty, just a proof-of-concept at this point, but it does function.

<?PHP

$VERA_HOST = 'http://<local_vera_ip_address>:3480';

// Method: POST, PUT, GET etc
// Data: array("param" => "value") ==> index.php?param=value
function CallAPI($method, $url, $data = false)
{
    $curl = curl_init();

    switch ($method)
    {
        case "POST":
            curl_setopt($curl, CURLOPT_POST, 1);

            if ($data)
                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
            break;
        case "PUT":
            curl_setopt($curl, CURLOPT_PUT, 1);
            break;
        default:
            if ($data)
                $url = sprintf("%s?%s", $url, http_build_query($data));
    }

    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $result = curl_exec($curl);

    curl_close($curl);

    return $result;
}

// Determine the list of devices for name->id translation
$parm = [
	'id' => 'sdata',
	'output_format' => 'json'
];
$json = CallAPI( 'GET', $VERA_HOST . '/data_request', $parm); 
$vera_sdata = json_decode($json);
//print_r($vera_sdata);

$devices = $vera_sdata->devices;
$scenes = $vera_sdata->scenes;
$rooms = $vera_sdata->rooms;
$categories = $vera_sdata->categories;

// Fixup google funky name stuff that sometimes gets thrown in for unknown reasons
$_GET['name'] = trim(str_replace('the', '', $_GET['name']));

echo "Looking for " . $_GET['action'] . " device " . $_GET['name'] . " to set at " . $_GET['value'] . "\n<br>";
error_log(  "Looking for " . $_GET['action'] . " device " . $_GET['name'] . " to set at " . $_GET['value'] );

// Simple script for dimmers (category=2, TODO: Should we look up category number from JSON response??)
if( strtolower($_GET['action']) == "dimmer" )
{
	foreach( $devices as $device )
	{
		//echo "Device type " . $device->category . " " . $device->name . " has id " . $device->id . "\n<br>";
		if( $device->category == 2 && 
			(
			  strtolower(trim($device->name)) == strtolower($_GET['name']) || 
			  strtolower(trim(substr(strstr($device->name,":"),1))) == strtolower($_GET['name'])
			) )
		{
			echo "Setting " . $_GET['action'] . " device " . $device->name . " to " . $_GET['value'] . "\n<br>";

			$parm = [
        			'id' => 'action',
        			'output_format' => 'json',
				'DeviceNum' => $device->id,
				'serviceId' => 'urn:upnp-org:serviceId:Dimming1',
				'action' => 'SetLoadLevelTarget',
				'newLoadlevelTarget' => $_GET['value']
			];
			$json = CallAPI( 'GET', $VERA_HOST . '/data_request', $parm);
			print_r( $json );
		}
	}
}

?>

Let me know your thoughts, or if anyone is interested in collaborating on the solution.

If you’re just trying to control Vera from Google Home I find HA Bridge does this in a dumb down way where I can figure it out in a short time. Not perfect but I’m able to control lights with no problem. The dock locks and sensors seems to be an issue still because it treats Vera as a Philip Hue device.