Bonjour à tous,
pour information, j’ai développé un scénario qui permet de calculer les diverses consommations selon les heures pleines et creuses et en déduire les coûts associés (personnalisation via des variables).
Données calculés :
- conso_hier_hp
- conso_hier_hc
- tarif_hier_hp
- tarif_hier_hc
- tarif_hier
- conso_mois_hc
- conso_mois_hp
- moyenne_conso_jour_hc
- moyenne_conso_jour_hp
- jour_restant_mois
- estimation_conso_mois_hc
- estimation_conso_mois_hp
- estimation_conso_mois
- estimation_prix_mois_hc
- estimation_prix_mois_hp
- estimation_prix_mois_global
Note: les variables sont appelées « hier » car les données dates de hier, mais j’ajoute dans l’history à la date de hier, ce qui implique que les données finales seront à la bonne date, comme ce qui est fait avec le plugin Enedis.
Le scénario permet de contrôler si les données sont présentes ou non et se relance automatiquement si jamais les données n’ont pas encore été récupérées par le plugin Enedis.
Plusieurs scénarios de plages horaires existent, pour éviter de faire un script qui gère tous les cas possibles et que beaucoup de choses ne servent à rien, je vais découper le code selon les plages possibles (update au fur et à mesure qu’ils seront créés, n’hésitez pas à transmettre votre adaptation si elle n’est pas encore créée). Il faudra donc choisir son code selon le type de plage horaire d’HC et HP que vous avez. Pour le restes des besoins, ils sont similaires entre tous les scénarios.
1 / Besoins pour faire fonctionner le scénario
- Un virtuel avec l’ensemble des commandes infos citées au dessus
- Un ensemble de variables afin de gérer les HC et HP ainsi que les coûts d’abonnement
- Un scénario scheduler (qui peut être mutualisé pour plein de choses) pour piloter en asynchrone le scénario final (il y a donc 2 scénarios)
Note: les variables sont maintenant directement créées par le scénario, il ne suffit que de personnaliser ses valeurs par défaut.
a - Le virtuel nommé « Variables EDF »
et toutes ses variables à créer:
#[Appartement][Variables EDF][Conso Jour HP]#
#[Appartement][Variables EDF][Conso Jour HC]#
#[Appartement][Variables EDF][Tarif Jour HP]#
#[Appartement][Variables EDF][Tarif Jour HC]#
#[Appartement][Variables EDF][Tarif Jour]#
#[Appartement][Variables EDF][Conso Mois HP]#
#[Appartement][Variables EDF][Conso Mois HC]#
#[Appartement][Variables EDF][Moyenne Conso Jour HP]#
#[Appartement][Variables EDF][Moyenne Conso Jour HC]#
#[Appartement][Variables EDF][Estimation Conso Mois HP]#
#[Appartement][Variables EDF][Estimation Conso Mois HC]#
#[Appartement][Variables EDF][Estimation Conso Mois]#
#[Appartement][Variables EDF][Estimation Prix Mois HP]#
#[Appartement][Variables EDF][Estimation Prix Mois HC]#
#[Appartement][Variables EDF][Estimation Prix Mois Global]#
b - Les variables à personnaliser les valeurs dans le script
- EDF_HP_Start
- EDF_HC_Start
- EDF_Tarif_KWh_HP (et HP2)
- EDF_Tarif_KWh_HC (et HC2)
- EDF_Tarif_Abo_Mois
- EDF_Last_Var_Update (information mise à jour par le scénario)
c - Le scénario scheduler (mutualisable)
Je fais appel à ce scénario avec envoi de tags pour relancer les calculs
d - Le scénario final de création des variables EDF « Mise Jour Donnees EDF »
— Une seule plage horaire —
1/ Cas début heures creuses avant minuit
Exemple cas concret : 22h30 => 7h30
Version code du 26/03/2021 : Fonctionnement validé
################################################
## Scenario début heures creuses avant minuit ##
################################################
## Vérification présence des variables ou implémentation avec valeurs par défaut
(empty($scenario->getData("EDF_HP_Start"))) ? $scenario->setData("EDF_HP_Start", "06:30") : null;
(empty($scenario->getData("EDF_HC_Start"))) ? $scenario->setData("EDF_HC_Start", "22:30") : null;
(empty($scenario->getData("EDF_Tarif_KWh_HP"))) ? $scenario->setData("EDF_Tarif_KWh_HP", "0.1727") : null;
(empty($scenario->getData("EDF_Tarif_KWh_HC"))) ? $scenario->setData("EDF_Tarif_KWh_HC", "0.1296") : null;
(empty($scenario->getData("EDF_Tarif_Abo_Mois"))) ? $scenario->setData("EDF_Tarif_Abo_Mois", "11.60") : null;
(empty($scenario->getData("EDF_Last_Var_Update"))) ? $scenario->setData("EDF_Last_Var_Update", date('Y-m-d H:i:s',strtotime("now - 1 days"))) : null;
## Vérification de la dernière exécution réussie
$commande_conso_hier_hp = cmd::byString("#[Appartement][Variables EDF][Conso Jour HP]#");
$collectDate_conso_hier_hp = $commande_conso_hier_hp->getCollectDate();
if (date('Y-m-d', strtotime($collectDate_conso_hier_hp)) == date('Y-m-d',strtotime("yesterday"))){
$scenario->setLog("Scenario déjà lancé, annulation. Date dernier enregistrement valeurs:".date('Y-m-d', strtotime($collectDate_conso_hier_hp)));
} else {
## récupération de la date de dernière maj et vérification du nombre de jours à updater
$derniere_maj_donnees = date('Y-m-d',strtotime($scenario->getData("EDF_Last_Var_Update")));
$nb_jour_a_updater = scenarioExpression::time_diff($derniere_maj_donnees, "now",d);
if ($nb_jour_a_updater == 1){
$scenario->setLog("Seulement 1 jour a updater");
} else {
$scenario->setLog("Attention: ".$nb_jour_a_updater." jours a updater");
}
### Verification presences donnees horaires
$commande_ConsoHoraire = cmd::byString("#[Appartement][Compteur Linky][Consommation horaire]#");
$collectDate_ConsoHoraire = $commande_ConsoHoraire->getCollectDate();
if (date('Y-m-d', strtotime($collectDate_ConsoHoraire)) == date('Y-m-d',strtotime("now"))) {
### Get and Set variables
$debut_heure_pleine = $scenario->getData("EDF_HP_Start");
$debut_heure_creuse = $scenario->getData("EDF_HC_Start");
$tarif_heure_pleine = $scenario->getData("EDF_Tarif_KWh_HP");
$tarif_heure_creuse = $scenario->getData("EDF_Tarif_KWh_HC");
$tarif_abonnement = $scenario->getData("EDF_Tarif_Abo_Mois");
## Commandes
$commande_conso_hier_hc = cmd::byString("#[Appartement][Variables EDF][Conso Jour HC]#");
$commande_tarif_hier_hp = cmd::byString("#[Appartement][Variables EDF][Tarif Jour HP]#");
$commande_tarif_hier_hc = cmd::byString("#[Appartement][Variables EDF][Tarif Jour HC]#");
$commande_tarif_hier = cmd::byString("#[Appartement][Variables EDF][Tarif Jour]#");
$commande_conso_mois_hp = cmd::byString("#[Appartement][Variables EDF][Conso Mois HP]#");
$commande_conso_mois_hc = cmd::byString("#[Appartement][Variables EDF][Conso Mois HC]#");
$commande_moyenne_conso_jour_hp = cmd::byString("#[Appartement][Variables EDF][Moyenne Conso Jour HP]#");
$commande_moyenne_conso_jour_hc = cmd::byString("#[Appartement][Variables EDF][Moyenne Conso Jour HC]#");
$commande_estimation_conso_mois_hp = cmd::byString("#[Appartement][Variables EDF][Estimation Conso Mois HP]#");
$commande_estimation_conso_mois_hc = cmd::byString("#[Appartement][Variables EDF][Estimation Conso Mois HC]#");
$commande_estimation_conso_mois = cmd::byString("#[Appartement][Variables EDF][Estimation Conso Mois]#");
$commande_estimation_prix_mois_hp = cmd::byString("#[Appartement][Variables EDF][Estimation Prix Mois HP]#");
$commande_estimation_prix_mois_hc = cmd::byString("#[Appartement][Variables EDF][Estimation Prix Mois HC]#");
$commande_estimation_prix_mois = cmd::byString("#[Appartement][Variables EDF][Estimation Prix Mois Global]#");
$id_commande_ConsoHoraire = $commande_ConsoHoraire->getId();
$id_commande_ConsoHoraireCreux = $commande_conso_hier_hc->getId();
$id_commande_ConsoHorairePlein = $commande_conso_hier_hp->getId();
### Lancement du calcul des données pour x jours
for($n=($nb_jour_a_updater-1); $n >= 0; $n--){
$date_valeurs = date('Y-m-d H:i:s', strtotime("yesterday - $n days 00:01"));
$date_JourEt1_minuit = date('Y-m-d H:i:s', strtotime("today - $n days 00:00"));
$scenario->setLog("Ajout du ".date('Y-m-d', strtotime("yesterday - $n days")));
$jour_restant_mois = scenarioExpression::time_diff("now - $n days", "first day of next month",d);
## NOTE: la valeur de la minute 0 ne doit pas être prise => ajout de 1mn
$debut_hp = date('Y-m-d H:i:s', strtotime("yesterday - $n days $debut_heure_pleine +1 minute"));
$debut_hc = date('Y-m-d H:i:s', strtotime("yesterday - $n days $debut_heure_creuse + 1 minute"));
$conso_hier_hp = history::getStatistique($id_commande_ConsoHoraire, $debut_hp, $debut_hc)["sum"] /2;
## Si donnée horaire à 0, envoyer un message dans le centre de message et utiliser les moyennes
if (empty($conso_hier_hp)) {
$title = 'Scénario Variables EDF';
$message = 'Données de consommation horaire vide pour le '.date('Y-m-d', strtotime("yesterday - $n days")).'. Estimation des valeurs via les statistiques de consommation du mois en cours.';
message::add($title, $message);
#Récupération de la consommation du jour
$id_commande_ConsoJour = cmd::byString("#[Appartement][Compteur Linky][Consommation Jour]#")->getId();
$conso_hier = history::getStatistique($id_commande_ConsoJour, date('Y-m-d H:i:s', strtotime("yesterday - $n days 00:00:00")), date('Y-m-d H:i:s', strtotime("yesterday - $n days 23:59:59")))["last"];
$moyenne_conso_jour_hc = $commande_moyenne_conso_jour_hc->execCmd();
$moyenne_conso_jour_hp = $commande_moyenne_conso_jour_hp->execCmd();
$ratio_conso_hp = ($moyenne_conso_jour_hp / ($moyenne_conso_jour_hp + $moyenne_conso_jour_hc)) * 100;
$conso_hier_hp = ($conso_hier * $ratio_conso_hp) / 100;
$conso_hier_hc = ($conso_hier * (100 - $ratio_conso_hp)) / 100;
} else {
#Calcul de l'heure creuse si valeurs journalières OK
$conso_hier_hc = (history::getStatistique($id_commande_ConsoHoraire, $date_valeurs, $debut_hp)["sum"] + history::getStatistique($id_commande_ConsoHoraire, $debut_hc, $date_JourEt1_minuit)["sum"] ) /2;
}
# Si les données ne sont pas vides ou nulls, continuer les calculs
if (!empty($conso_hier_hc) && !empty($conso_hier_hp)) {
# Finalisation des calculs divers
$tarif_hier_hp = $conso_hier_hp * $tarif_heure_pleine;
$tarif_hier_hc = $conso_hier_hc * $tarif_heure_creuse;
$tarif_hier = $tarif_hier_hp + $tarif_hier_hc;
# Historisation intermédiaire
$commande_conso_hier_hp->event($conso_hier_hp, $date_valeurs);
$commande_conso_hier_hc->event($conso_hier_hc, $date_valeurs);
$commande_tarif_hier_hp->event($tarif_hier_hp, $date_valeurs);
$commande_tarif_hier_hc->event($tarif_hier_hc, $date_valeurs);
$commande_tarif_hier->event($tarif_hier, $date_valeurs);
# Calculs
$conso_mois_hc = scenarioExpression::statisticsBetween($id_commande_ConsoHoraireCreux, "sum", "first day of this month midnight", "now");
$conso_mois_hp = scenarioExpression::statisticsBetween($id_commande_ConsoHorairePlein, "sum", "first day of this month midnight", "now");
$moyenne_conso_jour_hc = scenarioExpression::statisticsBetween($id_commande_ConsoHoraireCreux, "avg", "first day of this month midnight", "now");
$moyenne_conso_jour_hp = scenarioExpression::statisticsBetween($id_commande_ConsoHorairePlein, "avg", "first day of this month midnight", "now");
$estimation_conso_mois_hc = $conso_mois_hc + ($moyenne_conso_jour_hc * $jour_restant_mois);
$estimation_conso_mois_hp = $conso_mois_hp + ($moyenne_conso_jour_hp * $jour_restant_mois);
$estimation_conso_mois = $estimation_conso_mois_hc + $estimation_conso_mois_hp;
$estimation_prix_mois_hc = $estimation_conso_mois_hc * $tarif_heure_creuse;
$estimation_prix_mois_hp = $estimation_conso_mois_hp * $tarif_heure_pleine;
$estimation_prix_mois_global = $estimation_prix_mois_hc + $estimation_prix_mois_hp + $tarif_abonnement;
## Log dans le scénario pour tracer si besoin
$scenario->setLog("conso_hier_hp = ".$conso_hier_hp);
$scenario->setLog("conso_hier_hc = ".$conso_hier_hc);
$scenario->setLog("tarif_hier_hp = ".$tarif_hier_hp);
$scenario->setLog("tarif_hier_hc = ".$tarif_hier_hc);
$scenario->setLog("tarif_hier = ".$tarif_hier);
$scenario->setLog("conso_mois_hc = ".$conso_mois_hc);
$scenario->setLog("conso_mois_hp = ".$conso_mois_hp);
$scenario->setLog("moyenne_conso_jour_hc = ".$moyenne_conso_jour_hc);
$scenario->setLog("moyenne_conso_jour_hp = ".$moyenne_conso_jour_hp);
$scenario->setLog("jour_restant_mois = ".$jour_restant_mois);
$scenario->setLog("estimation_conso_mois_hc = ".$estimation_conso_mois_hc);
$scenario->setLog("estimation_conso_mois_hp = ".$estimation_conso_mois_hp);
$scenario->setLog("estimation_conso_mois = ".$estimation_conso_mois);
$scenario->setLog("estimation_prix_mois_hc = ".$estimation_prix_mois_hc);
$scenario->setLog("estimation_prix_mois_hp = ".$estimation_prix_mois_hp);
$scenario->setLog("estimation_prix_mois_global = ".$estimation_prix_mois_global);
# Historisation
$commande_conso_mois_hp->event($conso_mois_hp, $date_valeurs);
$commande_conso_mois_hc->event($conso_mois_hc, $date_valeurs);
$commande_moyenne_conso_jour_hp->event($moyenne_conso_jour_hp, $date_valeurs);
$commande_moyenne_conso_jour_hc->event($moyenne_conso_jour_hc, $date_valeurs);
$commande_estimation_conso_mois_hp->event($estimation_conso_mois_hp, $date_valeurs);
$commande_estimation_conso_mois_hc->event($estimation_conso_mois_hc, $date_valeurs);
$commande_estimation_conso_mois->event($estimation_conso_mois, $date_valeurs);
$commande_estimation_prix_mois_hp->event($estimation_prix_mois_hp, $date_valeurs);
$commande_estimation_prix_mois_hc->event($estimation_prix_mois_hc, $date_valeurs);
$commande_estimation_prix_mois->event($estimation_prix_mois_global, $date_valeurs);
# Mise à jour variable dernière màj en fois boucle terminée si pas d'erreur
$scenario->setData("EDF_Last_Var_Update", date('Y-m-d H:i:s',strtotime("now - $n days")));
} else {
$scenario->setLog("Les données de consommation du ".date('Y-m-d', strtotime("yesterday - $n days"))." n'ont pas pu être traitées ni avec les données horaires ni via les statistiques de consommation du mois");
}
}
} else { ## Si données horaires non présentes, rescheduler un lancement 30mn plus tard
$scenario->setLog("Donnees horaire non presente. Replanification de la tache. Derniere collecte horaire EDF presente: ".$collectDate_ConsoHoraire);
# Infos sur le schéduleur
$scenario_scheduler = scenario::byString("#[Technique][Tools][Scenario Scheduler]#");
#Récupération des tags du scénario
$tags = $scenario_scheduler->getTags();
#Modification des tags
$tags['#cible#'] = "EDF";
$tags['#action#'] = "LAUNCH";
$tags['#duree#'] = 30 ;
#Envoi des tags et le lancement de la reprogrammation
$scenario_scheduler->setTags($tags);
$scenario_scheduler->launch();
}
}
2/ Cas début heures creuses dès minuit
Exemple cas concret : 00h00 => 7h30
Version code du 26/03/2021 : Fonctionnement validé
##############################################
## Scenario début heures creuses dès minuit ##
##############################################
## Vérification présence des variables ou implémentation avec valeurs par défaut
(empty($scenario->getData("EDF_HP_Start"))) ? $scenario->setData("EDF_HP_Start", "07:30") : null;
(empty($scenario->getData("EDF_HC_Start"))) ? $scenario->setData("EDF_HC_Start", "00:00") : null;
(empty($scenario->getData("EDF_Tarif_KWh_HP"))) ? $scenario->setData("EDF_Tarif_KWh_HP", "0.1727") : null;
(empty($scenario->getData("EDF_Tarif_KWh_HC"))) ? $scenario->setData("EDF_Tarif_KWh_HC", "0.1296") : null;
(empty($scenario->getData("EDF_Tarif_Abo_Mois"))) ? $scenario->setData("EDF_Tarif_Abo_Mois", "11.60") : null;
(empty($scenario->getData("EDF_Last_Var_Update"))) ? $scenario->setData("EDF_Last_Var_Update", date('Y-m-d H:i:s',strtotime("now - 1 days"))) : null;
## Vérification de la dernière exécution réussie
$commande_conso_hier_hp = cmd::byString("#[Appartement][Variables EDF][Conso Jour HP]#");
$collectDate_conso_hier_hp = $commande_conso_hier_hp->getCollectDate();
if (date('Y-m-d', strtotime($collectDate_conso_hier_hp)) == date('Y-m-d',strtotime("yesterday"))){
$scenario->setLog("Scenario déjà lancé, annulation. Date dernier enregistrement valeurs:".date('Y-m-d', strtotime($collectDate_conso_hier_hp)));
} else {
## récupération de la date de dernière maj et vérification du nombre de jours à updater
$derniere_maj_donnees = date('Y-m-d',strtotime($scenario->getData("EDF_Last_Var_Update")));
$nb_jour_a_updater = scenarioExpression::time_diff($derniere_maj_donnees, "now",d);
if ($nb_jour_a_updater == 1){
$scenario->setLog("Seulement 1 jour a updater");
} else {
$scenario->setLog("Attention: ".$nb_jour_a_updater." jours a updater");
}
### Verification presences donnees horaires
$commande_ConsoHoraire = cmd::byString("#[Appartement][Compteur Linky][Consommation horaire]#");
$collectDate_ConsoHoraire = $commande_ConsoHoraire->getCollectDate();
if (date('Y-m-d', strtotime($collectDate_ConsoHoraire)) == date('Y-m-d',strtotime("now"))) {
### Get and Set variables
$debut_heure_pleine = $scenario->getData("EDF_HP_Start");
$debut_heure_creuse = $scenario->getData("EDF_HC_Start");
$tarif_heure_pleine = $scenario->getData("EDF_Tarif_KWh_HP");
$tarif_heure_creuse = $scenario->getData("EDF_Tarif_KWh_HC");
$tarif_abonnement = $scenario->getData("EDF_Tarif_Abo_Mois");
## Commandes
$commande_conso_hier_hc = cmd::byString("#[Appartement][Variables EDF][Conso Jour HC]#");
$commande_tarif_hier_hp = cmd::byString("#[Appartement][Variables EDF][Tarif Jour HP]#");
$commande_tarif_hier_hc = cmd::byString("#[Appartement][Variables EDF][Tarif Jour HC]#");
$commande_tarif_hier = cmd::byString("#[Appartement][Variables EDF][Tarif Jour]#");
$commande_conso_mois_hp = cmd::byString("#[Appartement][Variables EDF][Conso Mois HP]#");
$commande_conso_mois_hc = cmd::byString("#[Appartement][Variables EDF][Conso Mois HC]#");
$commande_moyenne_conso_jour_hp = cmd::byString("#[Appartement][Variables EDF][Moyenne Conso Jour HP]#");
$commande_moyenne_conso_jour_hc = cmd::byString("#[Appartement][Variables EDF][Moyenne Conso Jour HC]#");
$commande_estimation_conso_mois_hp = cmd::byString("#[Appartement][Variables EDF][Estimation Conso Mois HP]#");
$commande_estimation_conso_mois_hc = cmd::byString("#[Appartement][Variables EDF][Estimation Conso Mois HC]#");
$commande_estimation_conso_mois = cmd::byString("#[Appartement][Variables EDF][Estimation Conso Mois]#");
$commande_estimation_prix_mois_hp = cmd::byString("#[Appartement][Variables EDF][Estimation Prix Mois HP]#");
$commande_estimation_prix_mois_hc = cmd::byString("#[Appartement][Variables EDF][Estimation Prix Mois HC]#");
$commande_estimation_prix_mois = cmd::byString("#[Appartement][Variables EDF][Estimation Prix Mois Global]#");
$id_commande_ConsoHoraire = $commande_ConsoHoraire->getId();
$id_commande_ConsoHoraireCreux = $commande_conso_hier_hc->getId();
$id_commande_ConsoHorairePlein = $commande_conso_hier_hp->getId();
### Lancement du calcul des données pour x jours
for($n=($nb_jour_a_updater-1); $n >= 0; $n--){
$date_valeurs = date('Y-m-d H:i:s', strtotime("yesterday - $n days 00:01"));
$date_JourEt1_minuit = date('Y-m-d H:i:s', strtotime("today - $n days 00:00"));
$scenario->setLog("Ajout du ".date('Y-m-d', strtotime("yesterday - $n days")));
$jour_restant_mois = scenarioExpression::time_diff("now - $n days", "first day of next month",d);
## NOTE: la valeur de la minute 0 ne doit pas être prise => ajout de 1mn
$debut_hp = date('Y-m-d H:i:s', strtotime("yesterday - $n days $debut_heure_pleine +1 minute"));
$debut_hc = date('Y-m-d H:i:s', strtotime("today - $n days $debut_heure_creuse + 1 minute"));
$conso_hier_hp = history::getStatistique($id_commande_ConsoHoraire, $debut_hp, $debut_hc)["sum"] /2;
## Si donnée horaire à 0, envoyer un message dans le centre de message et utiliser les moyennes
if (empty($conso_hier_hp)) {
$title = 'Scénario Variables EDF';
$message = 'Données de consommation horaire vide pour le '.date('Y-m-d', strtotime("yesterday - $n days")).'. Estimation des valeurs via les statistiques de consommation du mois en cours.';
message::add($title, $message);
#Récupération de la consommation du jour
$id_commande_ConsoJour = cmd::byString("#[Appartement][Compteur Linky][Consommation Jour]#")->getId();
$conso_hier = history::getStatistique($id_commande_ConsoJour, date('Y-m-d H:i:s', strtotime("yesterday - $n days 00:00:00")), date('Y-m-d H:i:s', strtotime("yesterday - $n days 23:59:59")))["last"];
$moyenne_conso_jour_hc = $commande_moyenne_conso_jour_hc->execCmd();
$moyenne_conso_jour_hp = $commande_moyenne_conso_jour_hp->execCmd();
$ratio_conso_hp = ($moyenne_conso_jour_hp / ($moyenne_conso_jour_hp + $moyenne_conso_jour_hc)) * 100;
$conso_hier_hp = ($conso_hier * $ratio_conso_hp) / 100;
$conso_hier_hc = ($conso_hier * (100 - $ratio_conso_hp)) / 100;
} else {
#Calcul de l'heure creuse si valeurs journalières OK
$conso_hier_hc = (history::getStatistique($id_commande_ConsoHoraire, $date_valeurs, $debut_hp)["sum"] ) /2;
}
# Si les données ne sont pas vides ou nulls, continuer les calculs
if (!empty($conso_hier_hc) && !empty($conso_hier_hp)) {
# Finalisation des calculs divers
$tarif_hier_hp = $conso_hier_hp * $tarif_heure_pleine;
$tarif_hier_hc = $conso_hier_hc * $tarif_heure_creuse;
$tarif_hier = $tarif_hier_hp + $tarif_hier_hc;
# Historisation intermédiaire
$commande_conso_hier_hp->event($conso_hier_hp, $date_valeurs);
$commande_conso_hier_hc->event($conso_hier_hc, $date_valeurs);
$commande_tarif_hier_hp->event($tarif_hier_hp, $date_valeurs);
$commande_tarif_hier_hc->event($tarif_hier_hc, $date_valeurs);
$commande_tarif_hier->event($tarif_hier, $date_valeurs);
# Calculs
$conso_mois_hc = scenarioExpression::statisticsBetween($id_commande_ConsoHoraireCreux, "sum", "first day of this month midnight", "now");
$conso_mois_hp = scenarioExpression::statisticsBetween($id_commande_ConsoHorairePlein, "sum", "first day of this month midnight", "now");
$moyenne_conso_jour_hc = scenarioExpression::statisticsBetween($id_commande_ConsoHoraireCreux, "avg", "first day of this month midnight", "now");
$moyenne_conso_jour_hp = scenarioExpression::statisticsBetween($id_commande_ConsoHorairePlein, "avg", "first day of this month midnight", "now");
$estimation_conso_mois_hc = $conso_mois_hc + ($moyenne_conso_jour_hc * $jour_restant_mois);
$estimation_conso_mois_hp = $conso_mois_hp + ($moyenne_conso_jour_hp * $jour_restant_mois);
$estimation_conso_mois = $estimation_conso_mois_hc + $estimation_conso_mois_hp;
$estimation_prix_mois_hc = $estimation_conso_mois_hc * $tarif_heure_creuse;
$estimation_prix_mois_hp = $estimation_conso_mois_hp * $tarif_heure_pleine;
$estimation_prix_mois_global = $estimation_prix_mois_hc + $estimation_prix_mois_hp + $tarif_abonnement;
## Log dans le scénario pour tracer si besoin
$scenario->setLog("conso_hier_hp = ".$conso_hier_hp);
$scenario->setLog("conso_hier_hc = ".$conso_hier_hc);
$scenario->setLog("tarif_hier_hp = ".$tarif_hier_hp);
$scenario->setLog("tarif_hier_hc = ".$tarif_hier_hc);
$scenario->setLog("tarif_hier = ".$tarif_hier);
$scenario->setLog("conso_mois_hc = ".$conso_mois_hc);
$scenario->setLog("conso_mois_hp = ".$conso_mois_hp);
$scenario->setLog("moyenne_conso_jour_hc = ".$moyenne_conso_jour_hc);
$scenario->setLog("moyenne_conso_jour_hp = ".$moyenne_conso_jour_hp);
$scenario->setLog("jour_restant_mois = ".$jour_restant_mois);
$scenario->setLog("estimation_conso_mois_hc = ".$estimation_conso_mois_hc);
$scenario->setLog("estimation_conso_mois_hp = ".$estimation_conso_mois_hp);
$scenario->setLog("estimation_conso_mois = ".$estimation_conso_mois);
$scenario->setLog("estimation_prix_mois_hc = ".$estimation_prix_mois_hc);
$scenario->setLog("estimation_prix_mois_hp = ".$estimation_prix_mois_hp);
$scenario->setLog("estimation_prix_mois_global = ".$estimation_prix_mois_global);
# Historisation
$commande_conso_mois_hp->event($conso_mois_hp, $date_valeurs);
$commande_conso_mois_hc->event($conso_mois_hc, $date_valeurs);
$commande_moyenne_conso_jour_hp->event($moyenne_conso_jour_hp, $date_valeurs);
$commande_moyenne_conso_jour_hc->event($moyenne_conso_jour_hc, $date_valeurs);
$commande_estimation_conso_mois_hp->event($estimation_conso_mois_hp, $date_valeurs);
$commande_estimation_conso_mois_hc->event($estimation_conso_mois_hc, $date_valeurs);
$commande_estimation_conso_mois->event($estimation_conso_mois, $date_valeurs);
$commande_estimation_prix_mois_hp->event($estimation_prix_mois_hp, $date_valeurs);
$commande_estimation_prix_mois_hc->event($estimation_prix_mois_hc, $date_valeurs);
$commande_estimation_prix_mois->event($estimation_prix_mois_global, $date_valeurs);
# Mise à jour variable dernière màj en fois boucle terminée si pas d'erreur
$scenario->setData("EDF_Last_Var_Update", date('Y-m-d H:i:s',strtotime("now - $n days")));
} else {
$scenario->setLog("Les données de consommation du ".date('Y-m-d', strtotime("yesterday - $n days"))." n'ont pas pu être traitées ni avec les données horaires ni via les statistiques de consommation du mois");
}
}
} else { ## Si données horaires non présentes, rescheduler un lancement 30mn plus tard
$scenario->setLog("Donnees horaire non presente. Replanification de la tache. Derniere collecte horaire EDF presente: ".$collectDate_ConsoHoraire);
# Infos sur le schéduleur
$scenario_scheduler = scenario::byString("#[Technique][Tools][Scenario Scheduler]#");
#Récupération des tags du scénario
$tags = $scenario_scheduler->getTags();
#Modification des tags
$tags['#cible#'] = "EDF";
$tags['#action#'] = "LAUNCH";
$tags['#duree#'] = 30 ;
#Envoi des tags et le lancement de la reprogrammation
$scenario_scheduler->setTags($tags);
$scenario_scheduler->launch();
}
}
La suite des autres cas possibles dans le commentaire suivant