Je suis utilisateur de Domoticz depuis peu pour le début de la domotisation de ma maison ! ( 2 ampoules et un chauffage pour l' instant )
Et ce forum est une grande source d' exemple concret .( Merci à vous ) Et maintenant à moi de me lancer.
Donc je possède un Poêle à pellets de marque Rika et depuis deux semaines j' ai investi dans la clé FIRENET ( gestion par le net ); Mais autant que ça travaille avec domoticz ! Pour l' instant je n' est eu le temps de travailler que la récupération des données mais à terme je vais envoyé des trames via domoticz pour le pilotage complet.
Donc pour commencer j' ai crée un matériel Dummy : ensuite j' ai crée des capteurs virtuels
Ensuite je lance mon programme php via crontab toutes les deux minutes ( il va falloir installer php sur votre franboise ! )
Rika_Get.php
Code : Tout sélectionner
#!/usr/bin/php
<?php
//---------------------------------
//-- Script de récupération de données pour poéles à pellets Rika via FIRENET
//-- Auteur : Celtic80
//-- Date : 1 octobre 2016
//-- Modifiez vos codes acces au site et l adresse IP du Raspberry
//---------------------------------
# Rika_Get.php
// Pour régler le probléme dans Domoticz : /usr/bin/php^M: bad interpreter: No such file or directory
// sed -i -e 's/\r$//' /home/pi/domoticz/scripts/php/Rika_Get.php
// Dev mode ON :)
$mod_debug = false; // Mettre a true en mode developpement
if($mod_debug){
error_reporting(E_ALL); // On affiche les erreurs php
ini_set("display_errors", 1); // On affiche les erreurs php
}
$display_result = true;
//UserName et Password pour l' acces
$rika_username = 'VotreAdresseMailPourAccesSiteRika';
$rika_password = 'MotDePasseDuSiteRika';
$rika_Numero_Identification = 'NumeroIdentificationDonnéParVotrePoéle';
$Domoticz_URL = 'IPduRaspberry:Port';
// Demande l' heure UNIX pour l' envoi sur l' URL (ne pas corriger heure ete/hiver sinon ne fonctionne plus)
$string = " \r\n";
echo nl2br($string);
$UnixDate = time();
echo 'unix Time : '.$UnixDate;
$string = " \r\n";
echo nl2br($string);
$timeout1 = 30;
$timeout2 = 10;
$Conso_Pelet_2015 = 2062; // ici je gere mes consos par année
// cookie file name/location
$path_cookie = 'Cookie_connexion_Rika.txt';
$StatusFile = "status.json";
/**************************************************
Première requête : Connexion sur site principal
**************************************************/
$string = " \r\n";
echo nl2br($string);
echo ' Now Phase 1 ! ';
$string = " \r\n";
echo nl2br($string);
//login form action url
$url = 'https://www.rika-firenet.com/web/login';
$postinfo = "email=".$rika_username."&password=".$rika_password;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $path_cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $path_cookie); // file to read cookies in
//set the cookie the site has for certain features, this is optional
curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
curl_setopt($ch, CURLOPT_USERAGENT,
"Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
$return = curl_exec($ch);
// Retourne le numéro d'erreur de la dernière opération cURL.
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
if ($curl_errno > 0) {
echo "cURL Error ($curl_errno): $curl_error\n";
exit; // mettre en veille en mode développement
}
else
{
echo "Data received phase 1 : $return\n";
}
curl_close($ch);
$string = " \r\n";
echo nl2br($string);
/**************************************************
Seconde requête : Récupération du contenu
**************************************************/
$string = "\r\n Now Phase 2 ! \r\n";
echo nl2br($string);
$api_url = 'https://www.rika-firenet.com/api/client/'.$rika_Numero_Identification.'/status?nocache='.$UnixDate.'970';
// Initiate curl
$ch = curl_init();
// Options
curl_setopt($ch, CURLOPT_URL, $api_url); // set url
$fp = fopen ($StatusFile,"w");
curl_setopt($ch, CURLOPT_USERAGENT,
"Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout2); // 10s timeout time for cURL connection
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // allow https verification if true
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // check common name and verify with host name
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "VeriSignClass3PublicPrimaryCertificationAuthority-G5.pem"); // allow ssl cert direct comparison
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_COOKIEFILE, $path_cookie); // file to read cookies in
curl_setopt($ch, CURLOPT_FILE, $fp);
$fp = fopen ($StatusFile,"w");
curl_setopt($ch, CURLOPT_FILE, $fp);
// Execution
$data = curl_exec($ch);
// Retourne le numéro d'erreur de la dernière opération cURL.
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
// close cURL connection, save cookie file, free up system resources
curl_close($ch);
if ($curl_errno > 0) {
echo "cURL Error ($curl_errno): $curl_error\r\n";
$string = " \r\n";
echo nl2br($string);
exit; // mettre en veille en mode développement !
}
else
{
echo "Data received phase 2 : $data\r\n";
$string = " \r\n";
echo nl2br($string);
}
// Verifie si le fichier telecharger est vide si oui exit sinon parse
$File_Data = file_get_contents($StatusFile);
if (!$File_Data || strlen($File_Data) == 0)
{
exit;
}
else
{
$json = file_get_contents($StatusFile);
$parsed_json = json_decode($json, true);
$Allum_Eteint = $parsed_json['controls']['onOff'];
$Temp_Consigne = $parsed_json['controls']['targetTemperature'];
$Status_Chauf_Main = $parsed_json['sensors']['statusMainState'];
$Status_Chauf_Sub = $parsed_json['sensors']['statusSubState'];
$Temp_Bureau = $parsed_json['sensors']['inputRoomTemperature'];
$Conso_Pelet_Total = $parsed_json['sensors']['parameterFeedRateTotal'];
$Avant_Entretien = $parsed_json['sensors']['parameterFeedRateService'];
/*
Eteint :
Allumé et éteint : main = 1 sub = 0 ; // en arret
allumé et veille : main = 1 sub = 3 ; // en veille
Allumé et allumage : main = 2 sub = 6 ;
Allumé et Demarrage : main = 3 sub = 1 ;
Allumé et Controle : main = 4 sub = 4 ; // en fonction total
Allumé et Fin de combustion : main =6
*/
if ($Allum_Eteint == false)
{
$string = " \r\n";
echo nl2br($string);
echo 'Poéle éteint : '.$Allum_Eteint;
$string = " \r\n";
echo nl2br($string);
}
else
{
if ($Status_Chauf_Main == '1')
{
if($Status_Chauf_Sub == '3')
{
$string = " \r\n";
echo nl2br($string);
echo 'Poéle en fonction et en Veille';
$string = " \r\n";
echo nl2br($string);
}
else
{
$string = " \r\n";
echo nl2br($string);
echo 'Poéle en fonction et en Chauffe';
$string = " \r\n";
echo nl2br($string);
}
}
else
if ($Status_Chauf_Main == '2')
{
$string = " \r\n";
echo nl2br($string);
echo 'Allumage du Poéle';
$string = " \r\n";
echo nl2br($string);
}
else
if ($Status_Chauf_Main == '3')
{
$string = " \r\n";
echo nl2br($string);
echo 'Démarrage de Chauff. du Poéle';
$string = " \r\n";
echo nl2br($string);
}
else
if ($Status_Chauf_Main == '4')
{
$string = " \r\n";
echo nl2br($string);
echo 'Poéle en Chauffe';
$string = " \r\n";
echo nl2br($string);
}
else
if ($Status_Chauf_Main == '6')
{
$string = " \r\n";
echo nl2br($string);
echo 'Fin de Combustion';
$string = " \r\n";
echo nl2br($string);
}
}
$string = " \r\n";
echo nl2br($string);
echo 'Temperature bureau : '.$Temp_Bureau.' °';
$string = " \r\n";
echo nl2br($string);
echo 'Temp_Consigne : '.$Temp_Consigne.' °';
$string = " \r\n";
echo nl2br($string);
$Conso_Pelet_Total = $Conso_Pelet_Total - $Conso_Pelet_2015;
echo 'Conso Pelet Total : '.$Conso_Pelet_Total.' Kg';
$string = " \r\n";
echo nl2br($string);
echo 'Reste avant Entretien : '.$Avant_Entretien.' Kg';
$string = " \r\n";
echo nl2br($string);
}
//Ferme le flux sur le fichier
fclose($fp);
// Test la réussite de la connection
if (!$data)
exit("\r\n Une erreur est survenue pendant l'éxecution de la session cURL \r\n");
/**************************************************
Derniére requête : Déconnexion
**************************************************/
$string = " \r\n";
echo nl2br($string);
$string = "\r\n Now Phase 3 ! \r\n";
echo nl2br($string);
$url = 'https://www.rika-firenet.com/web/logout';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout2);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout2);
if (preg_match('`^https://`i', $url))
{
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
}
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
curl_close($ch);
unlink($path_cookie); // Supprime le fichier cookie
$string = "Logout ! \r\n";
echo nl2br($string);
/**************************************************
Envoi des donées vers Domoticz
**************************************************/
$string = " \r\n";
echo nl2br($string);
$string = "\r\n Now Send Data ! \r\n";
echo nl2br($string);
/*----------------------------------------------------------------
USERVARIABLENAME with the name of your variable
USERVARIABLETYPE according to the table from "Store a new variable"
USERVARIABLEVALUE with the new value
Where type is 0 to 4:
0 = Integer, e.g. -1, 1, 0, 2, 10
1 = Float, e.g. -1.1, 1.2, 3.1
2 = String
3 = Date in format DD/MM/YYYY
4 = Time in 24 hr format HH:MM
$Allum_Eteint = $parsed_json['controls']['onOff']; // idx =
$Temp_Consigne = $parsed_json['controls']['targetTemperature']; // idx = 0014089 / 58 / Température Désirée Poéle
$Status_Chauf = $parsed_json['sensors']['statusSubState']; // idx =
$Temp_Bureau = $parsed_json['sensors']['inputRoomTemperature']; // idx = 1408A / 59 / Température Bureau / Cuisine
$Conso_Pelet_Total = $parsed_json['sensors']['parameterFeedRateTotal']; // idx = 1408D / 62 / Conso. Pellets Total
$Avant_Entretien = $parsed_json['sensors']['parameterFeedRateService']; // idx = 1408C / 61 / Conso. Pellets avant Entretien
Lancer par Crontab -e
# * /2 * * * * i/domoticz/scripts/php/Rika.php
-----------------------------------------------------------------*/
//$Url_Send = 'http://'.$Domoticz_URL.'/json.htm?type=command¶m=udevice&idx=59&nvalue=0&svalue=19'; // Custom Sensor
$Url_Send_Consigne = 'http://'.$Domoticz_URL.'/json.htm?type=command¶m=udevice&idx=58&nvalue=0&svalue='.$Temp_Consigne; // Temperature Sensor
$Url_Send_Bureau = 'http://'.$Domoticz_URL.'/json.htm?type=command¶m=udevice&idx=59&nvalue=0&svalue='.$Temp_Bureau; // Temperature Sensor
$Url_Entretien = 'http://'.$Domoticz_URL.'/json.htm?type=command¶m=udevice&idx=61&svalue='.$Avant_Entretien; // Counter
$Url_Send_Total = 'http://'.$Domoticz_URL.'/json.htm?type=command¶m=udevice&idx=62&svalue='.$Conso_Pelet_Total; // Counter
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $Url_Send_Consigne);
$result1 = curl_exec($curl);
echo 'Temp Consigne : '.$Temp_Consigne;
$string = " \r\n";
echo nl2br($string);
curl_close($curl);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $Url_Send_Bureau);
$result2 = curl_exec($curl);
echo 'Bureau : '.$Temp_Bureau;
$string = " \r\n";
echo nl2br($string);
curl_close($curl);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $Url_Entretien);
$result3 = curl_exec($curl);
echo 'Av entretien : '.$Avant_Entretien;
$string = " \r\n";
echo nl2br($string);
curl_close($curl);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $Url_Send_Total);
$result4 = curl_exec($curl);
echo 'Conso Tot : '.$Conso_Pelet_Total;
curl_close($curl);
?>Si vous avez des idées ou modifications possible n' hésitez pas .
Merci !