Bonjour,
je sais que ça fait un peu boulet mais au final, quelqu’un pourrait il remettre le script définitif ? je suis perdu avec tous ces changements.
Merci d’avance.
Cordialement
Bonjour,
je sais que ça fait un peu boulet mais au final, quelqu’un pourrait il remettre le script définitif ? je suis perdu avec tous ces changements.
Merci d’avance.
Cordialement
En effet, j’ai constaté ça tout à l’heure, il affichait 19 bleu, 0 blanc et 0 rouge, puis après un refresh manuel, il a affiché les bons chiffres (297, 43, 22).
Vous avez déjà réussi à modifier le code de l’ecowatt pour qu’il pointe sur RTE ??
Bonjour @Gardian47,
Je comprends que vous soyez un peu perdu, j’ai eu la même difficulté que vous à tout remettre dans l’ordre et sans le coup de main de @jpty je n’y serai pas arrivé.
Après l’énorme coup de main que j’ai reçu, à mon tour d’aider un tout petit peu. Rien de ce qui suit ne vient de moi, j’en serai bien incapable, c’est le fruit du travail des autres membres et en particulier @jpty .
Je ne fait que résumer ci-dessous le contenu des fichiers qui permettent de faire fonctionner ecowatt à ce jour.
Donc en résumé, il faut :
<?php
/* This file is part of Jeedom.
*
* Jeedom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Jeedom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Jeedom. If not, see <http://www.gnu.org/licenses/>.
*/
/* * ***************************Includes********************************* */
require_once dirname(__FILE__) . '/../../../../core/php/core.inc.php';
require_once dirname(__FILE__) . '/../../vendor/autoload.php';
class ecowatt extends eqLogic {
/* * *************************Attributs****************************** */
public static $_widgetPossibility = array('custom' => true, 'custom::layout' => false);
/* * ***********************Methode static*************************** */
public static function cronHourly() {
$hour = array(
'ejp' => array(1, 6, 12, 16, 19, 23),
'ecowatt' => array(6, 10, 13, 16, 19, 23),
'tempo' => array(6, 10, 13, 16, 19, 23),
);
foreach (self::byType('ecowatt',true) as $ecowatt) {
if (isset($hour[$ecowatt->getConfiguration('datasource')]) && !in_array(date('H'), $hour[$ecowatt->getConfiguration('datasource')])) {
continue;
}
$ecowatt->updateInfo();
}
}
public static function valueFromUrl($_url) {
$InitPage = curl_init();
curl_setopt($InitPage, CURLOPT_URL, $_url);
curl_setopt($InitPage, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($InitPage, CURLOPT_USERAGENT, 'Le site de Jeedom (www.jeedom.com)');
$dataUrl = curl_exec ($InitPage);
curl_close($InitPage);
return json_decode($dataUrl, true);
}
/* * *********************Méthodes d'instance************************* */
public function preSave() {
$this->setCategory('energy', 1);
}
public function postSave() {
$cmd_list = array();
if ($this->getConfiguration('datasource') == 'ejp') {
$cmd_list = array(
'today' => array(
'name' => __('Aujourd\'hui', __FILE__),
'subtype' => 'string',
'order' => 1,
),
'tomorrow' => array(
'name' => __('Demain', __FILE__),
'subtype' => 'string',
'order' => 2,
),
'remainingDays' => array(
'name' => __('EJP restants', __FILE__),
'subtype' => 'numeric',
'order' => 3,
),
'totalDays' => array(
'name' => __('EJP écoulés', __FILE__),
'subtype' => 'numeric',
'order' => 4,
),
);
}
if ($this->getConfiguration('datasource') == 'tempo') {
$cmd_list = array(
'today' => array(
'name' => __('Aujourd\'hui', __FILE__),
'subtype' => 'string',
'order' => 1,
),
'tomorrow' => array(
'name' => __('Demain', __FILE__),
'subtype' => 'string',
'order' => 2,
),
'blue-remainingDays' => array(
'name' => __('Jours Bleus restants', __FILE__),
'subtype' => 'numeric',
'order' => 3,
),
'blue-totalDays' => array(
'name' => __('Total jours Bleus', __FILE__),
'subtype' => 'numeric',
'order' => 4,
),
'white-remainingDays' => array(
'name' => __('Jours Blancs restants', __FILE__),
'subtype' => 'numeric',
'order' => 5,
),
'white-totalDays' => array(
'name' => __('Total jours Blancs', __FILE__),
'subtype' => 'numeric',
'order' => 6,
),
'red-remainingDays' => array(
'name' => __('Jours Rouges restants', __FILE__),
'subtype' => 'numeric',
'order' => 7,
),
'red-totalDays' => array(
'name' => __('Total jours Rouges', __FILE__),
'subtype' => 'numeric',
'order' => 8,
),
);
}
foreach ($this->getCmd() as $cmd) {
if (!isset($cmd_list[$cmd->getLogicalId()]) && $cmd->getLogicalId() != 'refresh') {
$cmd->remove();
}
}
foreach ($cmd_list as $key => $cmd_info) {
$cmd = $this->getCmd(null, $key);
if (!is_object($cmd)) {
$cmd = new ecowattCmd();
$cmd->setLogicalId($key);
$cmd->setIsVisible(1);
$cmd->setName($cmd_info['name']);
$cmd->setOrder($cmd_info['order']);
}
$cmd->setType('info');
$cmd->setSubType($cmd_info['subtype']);
$cmd->setEqLogic_id($this->getId());
$cmd->save();
}
$refresh = $this->getCmd(null, 'refresh');
if (!is_object($refresh)) {
$refresh = new ecowattCmd();
$refresh->setName(__('Rafraichir', __FILE__));
}
$refresh->setEqLogic_id($this->getId());
$refresh->setLogicalId('refresh');
$refresh->setType('action');
$refresh->setSubType('other');
$refresh->setOrder(99);
$refresh->save();
$this->updateInfo();
}
public function updateInfo() {
switch ($this->getConfiguration('datasource')) {
case 'ejp':
$ejpdays = self::valueFromUrl('https://particulier.edf.fr/bin/edf_rc/servlets/ejptemponew?Date_a_remonter=' . date('Y-m-d') . '&TypeAlerte=EJP');
$region = 'Ejp' . ucfirst(strtolower(str_replace(array('_', 'EJP'), '', $this->getConfiguration('region-ejp'))));
$value = 'Non déterminé';
if (isset($ejpdays['JourJ'][$region])) {
if ($ejpdays['JourJ'][$region] == 'NON_EJP') {
$value = 'Pas d\'EJP';
} elseif ($ejpdays['JourJ'][$region] == 'EST_EJP') {
$value = 'EJP';
}
}
$today = $this->getCmd(null, 'today');
if (is_object($today) && $today->execCmd(null, 2) != $today->formatValue($value)) {
$today->event($value);
}
$value = 'Non déterminé';
if (isset($ejpdays['JourJ1'][$region])) {
if ($ejpdays['JourJ1'][$region] == 'NON_EJP') {
$value = 'Pas d\'EJP';
} elseif ($ejpdays['JourJ1'][$region] == 'EST_EJP') {
$value = 'EJP';
}
}
$this->checkAndUpdateCmd('tomorrow', $value);
$ejptotaldays = self::valueFromUrl('https://particulier.edf.fr/services/rest/referentiel/historicEJPStore?searchType=ejp');
$region = str_replace(array('_', 'EJP'), '', $this->getConfiguration('region-ejp'));
$this->fillValue('totalDays', $region . '::Total', $ejptotaldays, -1);
$totalDays = $this->getCmd(null, 'totalDays');
$remainingDays = $this->getCmd(null, 'remainingDays')->event(22 - $totalDays->execCmd(null, 2));
break;
case 'tempo':
$tempodays = self::valueFromUrl('https://particulier.edf.fr/services/rest/referentiel/searchTempoStore?dateRelevant=' .date('Y-m-d'));
$this->fillValue('today', 'couleurJourJ', $tempodays);
$this->fillValue('tomorrow', 'couleurJourJ1', $tempodays);
$tempodays = self::valueFromUrl('https://particulier.edf.fr/services/rest/referentiel/getNbTempoDays?TypeAlerte=TEMPO');
$this->fillValue('white-remainingDays', 'PARAM_NB_J_BLANC', $tempodays);
$this->fillValue('blue-remainingDays', 'PARAM_NB_J_BLEU', $tempodays);
$this->fillValue('red-remainingDays', 'PARAM_NB_J_ROUGE', $tempodays);
$this->checkAndUpdateCmd('blue-totalDays', 300); // Total jours bleu
$this->checkAndUpdateCmd('white-totalDays', 43); // Total jours blanc
$this->checkAndUpdateCmd('red-totalDays', 22); // Total jours rouge
break;
}
$this->refreshWidget();
}
public function fillValue($_logicalId, $_value, $_data, $_default = 'N/A') {
$result = $_default;
foreach (explode('::', $_value) as $key) {
if (isset($_data[$key])) {
$_data = $_data[$key];
} else {
$_data = null;
break;
}
}
if (!is_array($_data) && $_data !== null) {
$result = $_data;
}
$this->checkAndUpdateCmd($_logicalId, $result);
}
public function toHtml($_version = 'dashboard') {
$replace = $this->preToHtml($_version, array('#background-color#' => '#bdc3c7'));
if (!is_array($replace)) {
return $replace;
}
$version = jeedom::versionAlias($_version);
foreach ($this->getCmd('info') as $cmd) {
$replace['#' . $cmd->getLogicalId() . '_history#'] = '';
$replace['#' . $cmd->getLogicalId() . '_id#'] = $cmd->getId();
$replace['#' . $cmd->getLogicalId() . '#'] = $cmd->execCmd(null, 2);
$replace['#' . $cmd->getLogicalId() . '_collect#'] = $cmd->getCollectDate();
if ($cmd->getIsHistorized() == 1) {
$replace['#' . $cmd->getLogicalId() . '_history#'] = 'history cursor';
}
}
$refresh = $this->getCmd(null, 'refresh');
if (is_object($refresh)) {
$replace['#refresh_id#'] = $refresh->getId();
}
if ($this->getConfiguration('datasource') == 'ecowatt') {
return $this->postToHtml($_version, template_replace($replace, getTemplate('core', $version, 'ecowatt_ecowatt', 'ecowatt')));
}
if ($this->getConfiguration('datasource') == 'ejp') {
return $this->postToHtml($_version, template_replace($replace, getTemplate('core', $version, 'ecowatt_ejp', 'ecowatt')));
}
if ($this->getConfiguration('datasource') == 'tempo') {
return $this->postToHtml($_version, template_replace($replace, getTemplate('core', $version, 'ecowatt_tempo', 'ecowatt')));
}
}
/* * **********************Getteur Setteur*************************** */
}
class ecowattCmd extends cmd {
/* * *************************Attributs****************************** */
/* * ***********************Methode static*************************** */
/* * *********************Methode d'instance************************* */
public function execute($_options = array()) {
if ($this->getLogicalId() == 'refresh') {
$eqLogic = $this->getEqLogic();
$eqLogic->updateInfo();
}
}
/* * **********************Getteur Setteur*************************** */
}
?>
<div class="eqLogic eqLogic-widget allowResize allowReorderCmd #custom_layout# #eqLogic_class# #class#" data-eqType="#eqType#" data-eqLogic_id="#id#" data-eqLogic_uid="#uid#" data-version="#version#" data-translate-category="#translate_category#" data-category="#category#" data-tags="#tags#" style="width: #width#;height: #height#;#style#">
<center class="widget-name">
<span class="warning" title="#alert_name#">
<i class='#alert_icon#'></i>
</span>
<span class="cmd refresh pull-right cursor" data-cmd_id="#refresh_id#">
<i class="fas fa-sync"></i>
</span>
<span class="reportModeVisible">#name_display# <span class="object_name">#object_name#</span></span>
<a href="#eqLink#" class="reportModeHidden">#name_display# <span class="object_name">#object_name#</span></a>
</center>
<div class="#isVerticalAlign#">
<center>
<span style="font-weight: bold; Cursor:default">Aujourd'hui
<i class="fa fa-circle fa-lg today" style="color : #95a5a6; Cursor:default"></i>
</span>
<br/>
<span style="font-weight: bold; Cursor:default">Demain
<i class="fa fa-circle fa-lg tomorrow" style="color : #95a5a6; Cursor:default"></i>
</span>
<br/><br/>
<span style="font-weight: bold;">Jours restants :</span>
<br/>
</center>
<div style="margin-left:45px">
<i class="fa fa-circle fa-lg" style="color : #005BBB; Cursor:default"></i>
<span> : #blue-remainingDays# / #blue-totalDays#</span><br/>
<i class="fa fa-circle fa-lg" style="color : #DFDFDF; Cursor:default"></i>
<span> : #white-remainingDays# / #white-totalDays#</span><br/>
<i class="fa fa-circle fa-lg" style="color : #F34B32; Cursor:default"></i>
<span> : #red-remainingDays# / #red-totalDays#</span>
</div>
</div>
<script>
if("#today#" == "TEMPO_BLEU"){
$('.eqLogic[data-eqLogic_id=#id#] .today').css('color','#005BBB');
}else if("#today#" == "TEMPO_BLANC"){
$('.eqLogic[data-eqLogic_id=#id#] .today').css('color','#DFDFDF');
}else if("#today#" == "TEMPO_ROUGE"){
$('.eqLogic[data-eqLogic_id=#id#] .today').css('color','#F34B32');
}
if("#tomorrow#" == "TEMPO_BLEU"){
$('.eqLogic[data-eqLogic_id=#id#] .tomorrow').css('color','#005BBB');
} else if("#tomorrow#" == "TEMPO_BLANC") {
$('.eqLogic[data-eqLogic_id=#id#] .tomorrow').css('color','#DFDFDF');
} else if("#tomorrow#" == "TEMPO_ROUGE") {
$('.eqLogic[data-eqLogic_id=#id#] .tomorrow').css('color','#F34B32');
} else if("#tomorrow#" == "NON_DEFINI") {
$('.eqLogic[data-eqLogic_id=#id#] .tomorrow').css('color','#FFA02F');
}
if ('#refresh_id#' != '') {
$('.eqLogic[data-eqLogic_uid=#uid#] .refresh').on('click', function () {
jeedom.cmd.execute({id: '#refresh_id#'})
})
} else {
$('.eqLogic[data-eqLogic_uid=#uid#] .refresh').remove()
}
</script>
</div>
<div class="eqLogic eqLogic-widget #class#" data-eqLogic_id="#id#" data-eqType="#eqType#" data-version="#version#" data-eqLogic_uid="#uid#" data-translate-category="#translate_category#" data-category="#category#" data-tags="#tags#" style="#style#">
<span class="cmd refresh pull-right cursor" data-cmd_id="#refresh_id#">
<i class="fas fa-sync"></i>
</span>
<center>
<span class="widget-name">
<span class="warning" title="#alert_name#">
<i class='#alert_icon#'></i>
</span>
<span>#name_display# <span class="object_name">#object_name#</span></span><br/>
</span>
</center>
<div style="padding: 5px;">
<center>
<span style="font-weight: bold; Cursor:default">Aujourd'hui
<i class="fa fa-circle fa-lg today" style="color : #95a5a6; Cursor:default"></i>
</span>
<br/>
<span style="font-weight: bold; Cursor:default">Demain
<i class="fa fa-circle fa-lg tomorrow" style="color : #95a5a6; Cursor:default"></i>
</span>
<br/>
</center>
<div style="margin-left:20px;">
<span style="font-weight: bold; Cursor:default">Jours restants:</span>
<div style="margin-left:20px;">
<i class="fa fa-circle fa-lg" style="color : #005BBB; Cursor:default"></i>
<span> : #blue-remainingDays# / #blue-totalDays#</span><br/>
<i class="fa fa-circle fa-lg" style="color : #DFDFDF; Cursor:default"></i>
<span> : #white-remainingDays# / #white-totalDays#</span><br/>
<i class="fa fa-circle fa-lg" style="color : #F34B32; Cursor:default"></i>
<span> : #red-remainingDays# / #red-totalDays#</span>
</div>
</div>
</div>
<script>
if("#today#" == "TEMPO_BLEU"){
$('.eqLogic[data-eqLogic_id=#id#] .today').css('color','#005BBB');
}else if("#today#" == "TEMPO_BLANC"){
$('.eqLogic[data-eqLogic_id=#id#] .today').css('color','#DFDFDF');
}else if("#today#" == "TEMPO_ROUGE"){
$('.eqLogic[data-eqLogic_id=#id#] .today').css('color','#F34B32');
}
if("#tomorrow#" == "TEMPO_BLEU"){
$('.eqLogic[data-eqLogic_id=#id#] .tomorrow').css('color','#005BBB');
} else if("#tomorrow#" == "TEMPO_BLANC") {
$('.eqLogic[data-eqLogic_id=#id#] .tomorrow').css('color','#DFDFDF');
} else if("#tomorrow#" == "TEMPO_ROUGE") {
$('.eqLogic[data-eqLogic_id=#id#] .tomorrow').css('color','#F34B32');
} else if("#tomorrow#" == "NON_DEFINI") {
$('.eqLogic[data-eqLogic_id=#id#] .tomorrow').css('color','#FFA02F');
}
if ('#refresh_id#' != '') {
$('.eqLogic[data-eqLogic_uid=#uid#] .refresh').on('click', function () {
jeedom.cmd.execute({id: '#refresh_id#'})
})
} else {
$('.eqLogic[data-eqLogic_uid=#uid#] .refresh').remove()
}
</script>
</div>
EDIT : suppression du setEventOnly en ligne 146
Merci beaucoup, je teste ça ce soir, sympa la communauté
Bonjour @Jeedom95
Merci pour ce résumé.
Il va falloir une apporter une 1ere modification : dans ton script tu as toujours : setEventOnly
Il ne peut pas fonctionner depuis la version jeedom 4.2.
Peux tu corriger ta procédure?
Merci
Oui, le résultat est l’image de droite. Mais il reste des corrections à faire.
Bien vu, c’est corrigé.
Merci.
Merci à tous, ça marche
Bonjour,
Je viens de souscrire à tempo, donc je suis interessé !
Je ne suis pas expert, pourriez vous m’aider?
J’ai installé Ecowatt, je crée un élément, et en enregistrant, j’ai une erreur 500…
Pour la suite, le code à copier, depuis l’interface jeedom, je peux le faire…?
Merci d’avance.
Pardon, j’ai posté trop vite.
J’ai suivi la procédure au dessus, et édité les 3 fichiers.
Ca s’actualise en combien de temps généralement?
C’est vide pour le moment.
Ca s’actualise immédiatement avec l’action refresh en haut à droite de la tuile.
Ou par le cron à 6h00, 10h00, 13h00, 16h00, 19h00 et 23H00.
J’avais crée l’équipement, puis ensuite modifié les codes.
Mais en le supprimant, puis recrée, ca fonctionne.
AU TOP !
J’ai fait cette PR https://github.com/jeedom/plugin-ecowatt/pull/8 pour que ce fil puisse être oublié.
Toutes les modifications décrites ci-dessus nécessaires ont été intégrées dans le plugin.
Elle a été faite sur la branche beta du plugin.
Il faut maintenant attendre qu’elle soit validée et publiée sur la branche beta.
Puis attendre que Jeedom valide son passage en stable.
Merci. Je vais suivre ca.
Par contre, ce matin, je constate que le aujourd’hui est bleu (normal) et le demain en orange.
J’imagine que c’est car on est avant 11h ?
Bonjour,
Oui, c’est à cause de l’heure. Mais le site EDF où les données sont récupérées peut aussi être en panne.
tant que https://particulier.edf.fr/fr/accueil/gestion-contrat/options/tempo.html#/selection-bp est orange, ça ne devrait pas être autrement dans le plugin.
Avec la source RTE ( non dispo dans le plugin actuel ) c’est déjà bleu pour demain.
Effectivement, c’est bon maintenant.
Et la source RTE, on ne peux pas l’intégrer au plugin ?
J’ai modifié le plugin chez moi.
Les infos des prévisions des coupures de courant du site https://www.monecowatt.fr/ sont également intégrées.
Pour sa diffusion sur le market, j’ai demandé à Jeedom hier de récupérer le plugin ecowatt.
Tu pourras poster ici, si jamais il est dispo sur le market stp ?
Si je récupère le plugin, il y aura une mise à jour.
Vous serez alerté par le centre de mise à jour.
Ah oui c’est vrai.
Une chose étrange depuis aujourd’hui.
avant hier j’ai eu ça
Demain on sera en Bleu jours restants : 294/300 Bleus 0/43 Blancs 0/22 Rouges
hier :
Demain on sera en Bleu jours restants : 19/300 Bleus 0/43 Blancs 0/22 Rouges
et aujourd’hui :
Demain on sera en Bleu jours restants : 292/300 Bleus 43/43 Blancs 22/22 Rouges
Il y a quelque chose qui cloche non ?