Domoticz Switch if turned on:
If Plex is playing = pause
if Plex is paused = play
if Plex is stopped = press select
This gives me 3 control functions using just a single button on my Wallmote.
Call the php script from a Lua device script:
lua script
Code: Select all
commandArray = {}
if (devicechanged['Wallmote Plex'] == 'On') then
os.execute("php -f /root/scripts/plex/control.php &")
end
return commandArray
Code: Select all
<?php
// Configuration
$plexserver = "192.168.0.4";
$plexclient = "192.168.0.38";
//Disable PHP error reporting
error_reporting(0);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_URL => "https://$plexserver:32400/status/sessions",
));
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json'));
$resp = curl_exec($curl);
curl_close($curl);
$arr = json_decode($resp);
// Navigate the JSON to get the data
foreach($arr as $key=>$value){
foreach($value as $key=>$value){
foreach($value as $key=>$value){
$playerip = ($arr->MediaContainer->Video[$key]->Player->address);
$playerstatus = ($arr->MediaContainer->Video[$key]->Player->state);
};
};
};
// If Target Player IP present
if ($playerip == "$plexclient") {
// Check if its Playing
if ($playerstatus == 'playing') {
echo "Pausing player: $plexclient\n";
$command = "playback/pause";
} elseif ($playerstatus == 'paused') {
echo "Playing player: $plexclient\n";
$command = "playback/play";
};
} else {
echo "Pressing select on player: $plexclient\n";
$command = "navigation/select";
};
// Send command to the player
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_URL => "https://$plexserver:32400/system/players/$plexclient/$command",
));
curl_exec($curl);
curl_close($curl);
?>
1) The php curl command is set to allow unsigned SSL certificates.