Skip to content

Instantly share code, notes, and snippets.

@Westlad
Created January 15, 2017 20:44
Show Gist options
  • Select an option

  • Save Westlad/f0ab0e017154fc85f1ed741ca314b1a7 to your computer and use it in GitHub Desktop.

Select an option

Save Westlad/f0ab0e017154fc85f1ed741ca314b1a7 to your computer and use it in GitHub Desktop.
A simple script to receive a JSON object with "on and "off" directives and call a python script to turn a heater on or off.
<?php
$EchoJArray = json_decode(file_get_contents('php://input'));
$RequestType = $EchoJArray->request; // I don't use this yet
// ******************** Get state ********************;
$action = $EchoJArray->power;
if(empty($action)) {
$action = "off";
}
// ******************** Execute ********************;
$cmd = "/home/pi/alexa/heater.py";
switch ($action) {
case 'on':
$output=shell_exec("$cmd -n");
break;
case 'off':
$output = shell_exec("$cmd -f");
break;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment