@link http://blog.idleman.fr @licence CC by nc sa @version 1.0.0 @description Permet la récuperations d'informations de temperatures, humidités, lumière, mouvement et sons dans une pièce a travers la sonde yana "poolp" */ function propise_vocal_command(&$response,$actionUrl){ global $conf; $response['commands'][] = array( 'command'=>$conf->get('VOCAL_ENTITY_NAME').' diagnostique de la pièce', 'callback'=>'propise_diagnostic', 'confidence'=>0.8); } function propise_diagnostic($text,$confidence,$parameters,$myUser){ global $conf; require_once('Sensor.class.php'); require_once('Data.class.php'); $data = new Data(); $sensor = Sensor::load(array('location'=>$text)); $data = Data::load(array('sensor'=>$sensor->id)); $cli = new Client(); $cli->connect(); $cli->talk("Diagnostique pièce : ".$text); $cli->talk("Humidité : ".$data->humidity .", température : ".$data->temperature .", Luminosité : ".$data->temperature ."%, mouvement : ".$data->mouvment ); $cli->disconnect(); } function propise_action(){ global $_,$conf; switch($_['action']){ case 'propise_save_sensor': Action::write( function($_,&$response){ require_once('Sensor.class.php'); if(empty($_['labelSensor'])) throw new Exception("Le nom est obligatoire"); $sensor = !empty($_['id']) ? Sensor::getById($_['id']): new Sensor(); $sensor->label = $_['labelSensor']; $sensor->location = $_['locationSensor']; $sensor->save(); //Reference device for other plugins $device = new Device(); $device->label = $sensor->label; $device->plugin = 'propise'; $device->type = Device::CAPTOR; $device->location = $sensor->location; $device->icon = 'fa-heartbeat'; $device->setValue('humidity',0); $device->setValue('temperature',0); $device->setValue('light',0); $device->setValue('mouvment',0); $device->setValue('sound',0); $device->state = 1; $device->uid = $sensor->id; $device->save(); $response['message'] = 'Sonde enregistrée avec succès'; }, array('propise'=>'c') ); break; case 'propise_delete_sensor': Action::write( function($_,$response){ require_once('Sensor.class.php'); Data::delete(array('sensor'=>$_['id'])); Sensor::deleteById($_['id']); }, array('propise'=>'d') ); break; case 'propise_get_data': Action::write( function($_,&$response){ require_once('Sensor.class.php'); require_once('Data.class.php'); $datas = Data::loadAll(array('sensor'=>$_['id']),'time DESC'); $response['light'] = propise_convert_light($datas[0]->light); $response['humidity'] = $datas[0]->humidity; $response['temperature'] = $datas[0]->temperature; $response['mouvment'] = $datas[0]->mouvment; }, array('propise'=>'r') ); break; case 'propise_add_data': require_once('Sensor.class.php'); require_once('Data.class.php'); $sensor = Sensor::getById($_['id']); if($sensor == null || $sensor->id==0) return; $sensor->ip = $_['ip']; $sensor->save(); $data = new Data(); $data->time = time(); $data->humidity = $_['humidity']; $data->temperature = $_['temperature']; $data->light = $_['light']; $data->mouvment = $_['mouvment']; $data->sensor = $sensor->id; $data->save(); echo '1'; break; case 'propise_select_widget_menu': require_once(__DIR__.'/../dashboard/Widget.class.php'); Action::write( function($_,&$response){ $widget = new Widget(); $widget = $widget->getById($_['id']); $data = $widget->data(); $data['menu'] = $_['menu']; $widget->data($data); $widget->save(); }); break; case 'propise_load_widget': require_once(__DIR__.'/../dashboard/Widget.class.php'); Action::write( function($_,&$response){ $widget = new Widget(); $widget = $widget->getById($_['id']); $parameters = $widget->data(); if(empty($parameters['sensor'])){ $content = 'Choisissez une localisation en cliquant sur l \'icone de la barre du widget'; }else{ global $conf; require_once('Data.class.php'); require_once('Sensor.class.php'); $sensor = Sensor::getById($parameters['sensor']); $datas = Data::loadAll(array('sensor'=>$sensor->id),'time DESC',1); $response['title'] = $sensor->label; $content = ' '; $content .= '
'; $content .= '
'; $content .= ''; $content .= '
'; $content .= ' '; } $response['content'] = $content; } ); break; case 'propise_edit_widget': require_once(dirname(__FILE__).'/../dashboard/Widget.class.php'); require_once(dirname(__FILE__).'/Sensor.class.php'); $widget = new Widget(); $widget = $widget->getById($_['id']); $data = $widget->data(); $sensor = new Sensor(); $sensors = $sensor->populate(); $content = '

Choix de la sonde

'; if(count($sensors) == 0): $content = 'Aucune sonde enregistrée,enregistrer une sonde'; else : $content .= ''; endif; echo $content; break; case 'propise_save_widget': require_once(dirname(__FILE__).'/../dashboard/Widget.class.php'); $widget = new Widget(); $widget = $widget->getById($_['id']); $data = $widget->data(); $data['sensor'] = $_['sensor']; $widget->data($data); $widget->save(); echo $content; break; } } function propise_convert_light($light){ return round(($light*100)/1024,1); } function propise_plugin_setting_page(){ global $_,$myUser,$conf; if(isset($_['section']) && $_['section']=='propise' ){ require_once('Data.class.php'); require_once('Sensor.class.php'); if(!$myUser) throw new Exception('Vous devez être connecté pour effectuer cette action'); $sensorManager = new Sensor(); $sensors = $sensorManager->populate(); $roomManager = new Room(); $rooms = $roomManager->loadAll(array('state'=>'0')); $selected = new Sensor(); //Si on est en mode modification if (isset($_['id'])) $selected = $sensorManager->getById($_['id']); ?>

Sondes Poolp

Gestion des multi-sondes

Ajouter/Modifier une sonde


Consulter les sondes existants load(array('id'=>$sensor->location)); ?>
Nom UID Pièce A copier dans la sonde
label; ?> uid; ?> getName(); ?> Guide Installation
  • Démarrer la sonde en appuyant sur le boutton jusqu'a ce que la lumière s'allume en bleu
  • Se connecter au wifi de la sonde (PROPISE-XX) avec le mot de passe bananeflambee
  • Ouvrir l'interface de la sonde sur http://192.168.4.1
  • Remplir les identifiant WIFI de votre réseau
  • Dans le dernier champs, mettre le lien suivant : id.'&light={{LIGHT}}&humidity={{HUMIDITY}}&temperature={{TEMPERATURE}}&mouvment={{MOUVMENT}}'; echo ''.$url.''; ?>
Sondes (Poolp)'; } function propise_plugin_page($_){ if(!isset($_['module']) || $_['module']!='propise') return; require_once('Sensor.class.php'); require_once('Data.class.php'); $sensor = Sensor::getById($_['id']); $datas = Data::staticQuery('SELECT * FROM "yana_plugin_propise_data" WHERE time > strftime(\'%s\', \'now\') - 3600 ORDER BY time',array(),true); $tab = array('hours'=>array(),'temperature'=>array(),'humidity'=>array(),'light'=>array()); foreach($datas as $data){ if(date('i',$data->time) == "") continue; $tab['hours'][date('dmYHi',$data->time)] = date('H:i',$data->time); $tab['temperature'][date('dmYHi',$data->time)] =$data->temperature; $tab['humidity'][date('dmYHi',$data->time)]=$data->humidity; $tab['light'] [date('dmYHi',$data->time)]=$data->light; $tab['mouvment'] [date('dmYHi',$data->time)]=$data->mouvment; } ?>

Température

Humidité

Lumière

Mouvement

'dash_propise', 'icon' => 'fa fa-tint', 'label' => 'Sonde Poolp', 'background' => '#ffffff', 'color' => '#222222', 'onLoad' => 'action.php?action=propise_load_widget', 'onEdit' => 'action.php?action=propise_edit_widget', 'onSave' => 'action.php?action=propise_save_widget', ); } Plugin::addJs("/js/main.js"); //Lie wireRelay_plugin_setting_page a la zone réglages Plugin::addHook("setting_bloc", "propise_plugin_setting_page"); //Lie wireRelay_plugin_setting_menu au menu de réglages Plugin::addHook("setting_menu", "propise_plugin_setting_menu"); Plugin::addHook("action_post_case", "propise_action"); Plugin::addHook("vocal_command", "propise_vocal_command"); Plugin::addHook("widgets", "propise_plugin_widget"); Plugin::addHook("home", "propise_plugin_page"); ?>