php script to show status from uservariable

Moderator: leecollings

Post Reply
plutonium
Posts: 18
Joined: Tuesday 06 August 2013 19:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.7253
Location: Sweden
Contact:

php script to show status from uservariable

Post by plutonium »

Hi,

After I got this script up and running I wanted to display the info on my wordpress page. This is how I did.
status.jpg
status.jpg (7.32 KiB) Viewed 1094 times
By using this code below with PHP Code for posts plugin you manage display information from your uservariables.

Code: Select all

<?php
echo "<b>Machine status</b>";
echo "</br>";
$arr = array(6, 8, 10);
foreach ($arr as &$value) {

$get_data = "http://192.168.0.11/json.htm?type=command&param=getuservariable&idx=".$value;
$result = file_get_contents($get_data);
$decode = json_decode($result,true);
	
	if ($decode["result"][0]["Value"] == "1"){
		
	$icon = "green-icon.png";
	}
	else {
	$icon = "red-icon.png";
	}
	
switch ($decode['result'][0]['Name']) {
    case "washingmachine_status":
        $unit = "Washing machine";
        break;
    case "dryer_status":
        $unit = "Dryer";
        break;
    case "dishwasher_status":
        $unit = "Dishwasher";
        break;
}
	echo "</br>     " . $unit . "</br><img src=\"/wp-content/uploads/2015/12/" . $icon . "\">" . $decode['result'][0]['LastUpdate'] . "<br>";
}
?>
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest