46 lines
2.1 KiB
PHP
46 lines
2.1 KiB
PHP
<?php
|
|
$smartmeUserName = "MY_SMARTME_USERNAME";
|
|
$smartmePassword = "MY_SMARTME_PASSWORD";
|
|
$smartmeQuery = "https://api.smart-me.com/api/Devices/";
|
|
|
|
// Create a stream
|
|
$opts = array(
|
|
'http'=>array(
|
|
'method'=>"GET",
|
|
'header'=>"Accept-language: en\r\n" .
|
|
"Authorization: Basic " . base64_encode("$smartmeUserName:$smartmePassword")
|
|
)
|
|
);
|
|
$context = stream_context_create($opts);
|
|
|
|
// Open the file using the HTTP headers set above
|
|
$smartme_output = file_get_contents($smartmeQuery, false, $context);
|
|
$response = json_decode($smartme_output, true);
|
|
|
|
$powerstate = $response[0]['SwitchOn'];
|
|
echo "Last updated: " . date('Y-m-d H:i:s', strtotime($response[0]['ValueDate'])) . "<br><br>";
|
|
|
|
echo "Name: " . $response[0]['Name'] . "<br>";
|
|
echo "Zählerstand komplett: " . $response[0]['CounterReading'] . " " . $response[0]['CounterReadingUnit'] . "<br><br>";
|
|
|
|
//echo "SwitchOn: " . $response[0]['SwitchOn'] . "<br>";
|
|
|
|
echo "<h4 <!--style='margin-bottom: 10px;'-- >Aktuelle Daten</h4>";
|
|
echo "Leistung: " . $response[0]['ActivePower'] . " " . $response[0]['ActivePowerUnit'] . "<br>";
|
|
echo "Spannung: " . $response[0]['Voltage'] . " V <br>";
|
|
echo "Strom: " . $response[0]['Current'] . " A <br>";
|
|
echo "Leistungsfaktor: " . $response[0]['PowerFactor'] . "<br>";
|
|
//echo "Active Power Unit: " . $response[0]['ActivePowerUnit'] . "<br>";
|
|
//echo "Counter Reading Unit: " . $response[0]['CounterReadingUnit'] . "<br>";
|
|
//echo "Counter Reading Import: " . $response[0]['CounterReadingImport'] . "<br>";
|
|
echo "Temperatur: " . $response[0]['Temperature'] . " °C<br>";
|
|
|
|
echo "<hr>";
|
|
|
|
if ($powerstate == "1"){
|
|
echo "<div style='background: green; height: 60%; color: white;'><div style='font-size: xx-large;position: relative; float: left; top: 50%; left: 50%; transform: translate(-50%, -50%);'>Power ON</div></div>";
|
|
} else {
|
|
echo "<div style='background: red; height: 60%; color: white;'><div style='font-size: xx-large;position: relative; float: left; top: 50%; left: 50%; transform: translate(-50%, -50%);'>Power OFF</div></div>";
|
|
}
|
|
|
|
//var_dump($response[0]);?>
|