Voila une icône "conso électrique" pour ceux que cela peut intéresser, pour le menu de FB33$.
Après avoir cherché une bonne application simple pour réaliser des icônes, j'ai trouvé "PixelFormer".
[edit 02/06/2018] ci-dessous l'icone vierge afin de servir de base pour d'autres icônes
Pour le code du graphique il vient de Benj29 (posté le 28 janv. 2018, 14:16 ici:
).
Le code charge des données historisées dans la BD de Jeedom sur une période scpécifiée (chercher le mot clé "period" dans le code PHP ci-dessous) et les affiche.
) pour tester facilement en live différents paramètres de style et je les implémente dans le design de la manière suivante:
où cmdId=X le numéro de l'info que tu veux afficher.
Le fichier chart.php est à mettre à l'endroit qui convient (ici à la racine de html de ton jeedom. Tu peux utiliser le plugin outils de développement ou un SFTP via Bitvise par exemple pour placer ton fichier.
Code : Tout sélectionner
<?php
class jsonrpcClient {
/* * ********Attributs******************* */
private $errorCode = 9999;
private $errorMessage = 'No error';
private $error = 'No error';
private $result;
private $rawResult;
private $apikey = 'XXXXX';
private $options = array();
private $apiAddr;
private $cb_function = '';
private $cb_class = '';
private $certificate_path = '';
private $noSslCheck = false;
/* * ********Static******************* */
/**
*
* @param type $_apiAddr
* @param type $_apikey
* @param type $_options
*/
public function __construct($_apiAddr, $_apikey, $_options = array()) {
$this->apiAddr = $_apiAddr.'/core/api/jeeApi.php';
$this->apikey = $_apikey;
$this->options = $_options;
}
/**
*
* @param type $_method
* @param array $_params
* @param int $_timeout
* @param type $_file
* @param int $_maxRetry
* @return boolean
*/
public function sendRequest($_method, $_params = null, $_timeout = 15, $_file = null, $_maxRetry = 2) {
$_params['apikey'] = $this->apikey;
$_params = array_merge($_params, $this->options);
$request = array(
'request' => json_encode(array(
'jsonrpc' => '2.0',
'id' => mt_rand(1, 9999),
'method' => $_method,
'params' => $_params,
)));
$this->rawResult = preg_replace('/[^[:print:]]/', '', trim($this->send($request, $_timeout, $_file, $_maxRetry)));
if ($this->rawResult === false) {
return false;
}
if (!((is_string($this->rawResult) && (is_object(json_decode($this->rawResult)) || is_array(json_decode($this->rawResult)))))) {
if ($this->error == 'No error' || $this->error == '') {
$this->error = '9999<br/>Reponse is not json : ' . $this->rawResult;
}
$this->errorMessage = $this->rawResult;
return false;
}
$result = json_decode(trim($this->rawResult), true);
if (isset($result['result'])) {
$this->result = $result['result'];
if ($this->getCb_class() != '') {
$callback_class = $this->getCb_class();
$callback_function = $this->getCb_function();
if (method_exists($callback_class, $callback_function)) {
$callback_class::$callback_function($this->result);
}
} elseif ($this->getCb_function() != '') {
$callback_function = $this->getCb_function();
if (function_exists($callback_function)) {
$callback_function($this->result);
}
}
return true;
} else {
if (isset($result['error']['code'])) {
$this->error = 'Code : ' . $result['error']['code'];
$this->errorCode = $result['error']['code'];
}
if (isset($result['error']['message'])) {
$this->error .= '<br/>Message : ' . $result['error']['message'];
$this->errorMessage = $result['error']['message'];
}
return false;
}
}
private function send($_request, $_timeout = 15, $_file = null, $_maxRetry = 2) {
if ($_file !== null) {
if (version_compare(phpversion(), '5.5.0', '>=')) {
foreach ($_file as $key => $value) {
$_request[$key] = new CurlFile(str_replace('@', '', $value));
}
} else {
$_request = array_merge($_request, $_file);
}
if ($_timeout < 1200) {
$_timeout = 1200;
}
}
$nbRetry = 0;
while ($nbRetry < $_maxRetry) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->apiAddr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, $_timeout);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $_request);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
if ($this->getCertificate_path() != '' && file_exists($this->getCertificate_path())) {
curl_setopt($ch, CURLOPT_CAINFO, $this->getCertificate_path());
}
if ($this->getNoSslCheck()) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
$response = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$nbRetry++;
if (curl_errno($ch) && $nbRetry < $_maxRetry) {
curl_close($ch);
usleep(500000);
} else {
$nbRetry = $_maxRetry + 1;
}
}
if ($http_status == 301) {
if (preg_match('/<a href="(.*)">/i', $response, $r)) {
$this->apiAddr = trim($r[1]);
return $this->send($_request, $_timeout, $_file, $_maxRetry);
}
}
if ($http_status != 200) {
$this->error = 'Erreur http : ' . $http_status . ' Details : ' . $response;
}
if (curl_errno($ch)) {
$this->error = 'Erreur curl sur : ' . $this->apiAddr . '. Détail :' . curl_error($ch);
}
curl_close($ch);
return $response;
}
/* * ********Getteur Setteur******************* */
public function getError() {
return $this->error;
}
public function getResult() {
return $this->result;
}
public function getRawResult() {
return $this->rawResult;
}
public function getErrorCode() {
return $this->errorCode;
}
public function getErrorMessage() {
return $this->errorMessage;
}
public function getCb_function() {
return $this->cb_function;
}
public function getCb_class() {
return $this->cb_class;
}
public function setCb_function($cb_function) {
$this->cb_function = $cb_function;
return $this;
}
public function setCb_class($cb_class) {
$this->cb_class = $cb_class;
return $this;
}
public function setCertificate_path($certificate_path) {
$this->certificate_path = $certificate_path;
return $this;
}
public function getCertificate_path() {
return $this->certificate_path;
}
public function setDisable_ssl_verifiy($noSslCheck) {
$this->noSslCheck = $noSslCheck;
return $this;
}
public function getNoSslCheck() {
return $this->noSslCheck;
}
public function setNoSslCheck($noSslCHeck) {
$this->noSslCheck = $noSslCHeck;
return $this;
}
}
$urlJeedom = "http://127.0.0.1:80";
$apiKey = "XXXXX";
$chartWidth = ( IsSet($_GET['chartWidth']) ? $_GET['chartWidth'] : 300 );
$chartHeight = ( IsSet($_GET['chartHeight']) ? $_GET['chartHeight'] : 115 );
$cmdId = ( IsSet($_GET['cmdId']) ? $_GET['cmdId'] : 1 );
// changer le forcage pour la durée d'affichage (voir plus bas)
$period = ( IsSet($_GET['period']) ? $_GET['period'] : 0 );
if ($period==1)
{
$startTime=date("Y-m-d H:i:s",time()-72*60*60);
$endTime=date("Y-m-d H:i:s",time());
}else{
// $startTime=date("Y-m-d",time())." 00:00:00";
$startTime=date("Y-m-d H:i:s",time()-72*60*60);
$endTime=date("Y-m-d H:i:s",time());
}
$jsonrpc = new jsonrpcClient($urlJeedom, $apiKey);
$data = array();
if($jsonrpc->sendRequest('cmd::getHistory', array('apikey' => $apiKey, 'id' => $cmdId, 'startTime' => $startTime, 'endTime' => $endTime ))) {
foreach ($jsonrpc->getResult() as $result) {
$data[] = array("ts" => strtotime($result["datetime"]),"value"=> $result["value"]);
}
} else {
echo $jsonrpc->getError();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Language" content="fr" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width">
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
<script>
$(function () {
var data = {color: 'rgb(0,128,128)', name: 'command #<?= $cmdId;?>', lineWidth: 1, data:[
<?php
foreach ($data as $row){
echo "\t\t\t\t[Date.UTC(".date("Y",$row['ts']).",".(date("m",$row['ts'])-1).",".date("d",$row['ts']).",".date("H",$row['ts']).",".date("i",$row['ts']).",".date("s",$row['ts'])."),".$row['value']."],\n";
}
?>
]};
var myChart = Highcharts.chart('container', {
chart: {
backgroundColor:'rgba(255, 255, 255, 0.0)',
type: 'area'
},
title: {
text: ''
},
xAxis: {
type: 'datetime',
lineWidth: 0,
minorGridLineWidth: 1,
lineColor: 'rgba(255,255,255,0.5)',
labels: {
enabled: true
},
minorTickLength: 0,
tickLength: 0
},
plotOptions: {
area: {
fillColor: {
linearGradient: {
x1: 0,
y1: 0,
x2: 0,
y2: 1
},
stops: [
[0, 'rgba(0,128,128,0.7)'],
[0.5, 'rgba(0,128,128,0.0)'],
[1, 'rgba(0,128,128,0.0)']
]
}
},
series: {
marker:{
enabled: false
}
}
},
yAxis: {
title: {
text: ''
},
lineWidth: 0,
minorGridLineWidth: 1,
lineColor: 'rgba(255,255,255,0.5)',
labels: {
enabled: true
},
minorTickLength: 0,
tickLength: 0,
gridLineColor: 'rgba(255,255,255,0.1)',
},
tooltip: {
enabled: false
},
credits: {
enabled: false
},
legend: {
enabled: false
},
series: [data]
});
});
</script>
<div id="container" style="width:<?= $chartWidth;?>px; height:<?= $chartHeight;?>px;"></div>
</body>
</html>