Статистика потребления, график pcharts
Пример показывает список сенсоров Простых Устройств, имеющих значения и выводит из в удобном виде через телеграмм.
У этой заметки есть продолжение с альтернативным вариантом вывода графиков https://connect.smartliving.ru/profile/1502/blog32...
Команды
include_once(DIR_MODULES . 'telegram/telegram.class.php');
$telegram_module = new telegram();
$objects=getObjectsByClass("SHumSensors");
foreach($objects as $obj) {
if (gg($obj['TITLE'].".value") ){
if (gg($obj['TITLE'].".linkedRoom")) $lr=" (".gg($obj['TITLE'].".linkedRoom").")"; else $lr="";
$option[] = $telegram_module->buildInlineKeyboardButton($text=$obj['TITLE'].": ".hex2bin('F09F92A7').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":7");
}
}
$objects=getObjectsByClass("STempSensors");
//print_r($objects);
foreach($objects as $obj) {
if (gg($obj['TITLE'].".linkedRoom")) $lr=" (".gg($obj['TITLE'].".linkedRoom").")"; else $lr="";
if (gg($obj['TITLE'].".value") )
$option[] = $telegram_module->buildInlineKeyboardButton($text=$obj['TITLE'].": ".hex2bin('F09F8CA1').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":7");
}
$objects=getObjectsByClass("STempHumSensors");
//print_r($objects);
foreach($objects as $obj) {
if (gg($obj['TITLE'].".linkedRoom")) $lr=" (".gg($obj['TITLE'].".linkedRoom").")"; else $lr="";
if (gg($obj['TITLE'].".value") )
$option[] = $telegram_module->buildInlineKeyboardButton($text=$obj['TITLE'].": ".hex2bin('F09F8CA1').gg($obj['TITLE'].".value")."°;".hex2bin('F09F92A7').gg($obj['TITLE'].".valueHumidity")."%".$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":7");
}
$objects=getObjectsByClass("SGeneralSensors");
//print_r($objects);
foreach($objects as $obj) {
if (gg($obj['TITLE'].".linkedRoom")) $lr=" (".gg($obj['TITLE'].".linkedRoom").")"; else $lr="";
if (gg($obj['TITLE'].".value") )
$option[] = $telegram_module->buildInlineKeyboardButton($text=$obj['TITLE'].": ".hex2bin('F09F92A2').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":7");
}
$objects=getObjectsByClass("SCounters");
//print_r($objects);
foreach($objects as $obj) {
if (gg($obj['TITLE'].".linkedRoom")) $lr=" (".gg($obj['TITLE'].".linkedRoom").")"; else $lr="";
if (gg($obj['TITLE'].".value") )
$option[] = $telegram_module->buildInlineKeyboardButton($text=$obj['TITLE'].": ".hex2bin('F09F939B').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":31");
}
$objects=getObjectsByClass("SPressureSensors");
//print_r($objects);
foreach($objects as $obj) {
if (gg($obj['TITLE'].".linkedRoom")) $lr=" (".gg($obj['TITLE'].".linkedRoom").")"; else $lr="";
if (gg($obj['TITLE'].".value") )
$option[] = $telegram_module->buildInlineKeyboardButton($text=$obj['TITLE'].": ".hex2bin('F09F90A3').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":7");
}
$objects=getObjectsByClass("SLeak");
//print_r($objects);
foreach($objects as $obj) {
if (gg($obj['TITLE'].".linkedRoom")) $lr=" (".gg($obj['TITLE'].".linkedRoom").")"; else $lr="";
if (gg($obj['TITLE'].".value") )
$option[] = $telegram_module->buildInlineKeyboardButton($text=$obj['TITLE'].": ".hex2bin('F09F8EA3').gg($obj['TITLE'].".value").$lr,"","Callback_sensorhistory_".$obj['TITLE'].".value".":7");
}
$count_row = 1;
$option = array_chunk($option, $count_row);
$keyb = $telegram_module->buildInlineKeyBoard($option);
$content = array('chat_id' => $chat_id, 'text' => "Датчики: ", 'reply_markup' => $keyb, 'parse_mode' => 'HTML');
$telegram_module->sendContent($content);
И добавляем callback
include_once(DIR_MODULES . 'telegram/telegram.class.php');
if (substr($callback,9,13)== 'sensorhistory')
{
$obj=explode(':',substr($callback,23))[0];
$days=explode(':',substr($callback,23))[1];
//$telegram_module->sendMessageToAll($obj);
$text=$obj.':'.chr(10);
$ar=getHistoryAvgDay($obj, time()-$days*86400, time());
foreach ($ar as $key=>$val)
{
$diff=round($val['VALUE']-$last,2);
if ($last) $difftxt=' ('.$diff.')';
$text.=$val['VALUE']." : ".$val['ADDED'].$difftxt.chr(10);
$last=$val['VALUE'];
}
$telegram_module->sendMessageToAll($text);
}
Екатеринбург, Россия
На форуме: directman66