- Nom du scénario : Gestion OpenEVSE _php_ - Objet parent : Garage - Mode du scénario : provoke - Evènement : #[Garage][Contrôle openevse][Status]# - Evènement : #[Baie Electrique][Infos Linky][HC]# - Evènement : #[Garage][Mode recharge VE][Mode]# CODE (code) $cmdmode = cmd::byString('#3344#'); $cmdniveau = cmd::byString('#3415#'); $cmdstatus = cmd::byString('#3294#'); $cmdamp = cmd::byString('#3288#'); $cmdpilot = cmd::byString('#3287#'); $cmdtemp = cmd::byString('#3295#'); $cmdstate = cmd::byString('#3286#'); $cmdstatetexte = cmd::byString('#3303#'); $cmdelapsed = cmd::byString('#3296#'); $cmdwattsec = cmd::byString('#3297#'); $cmdwatthour = cmd::byString('#3298#'); $cmdkwatth = cmd::byString('#3441#'); $cmdmiipc = cmd::byString('#3442#'); $cmdHC = cmd::byString('#2545#'); $cmdpwallbox = cmd::byString('#3407#'); $cmdtension = cmd::byString('#3405#'); $cmdpeffacable = cmd::byString('#3857#'); $cmdpinstantanee = cmd::byString('#2538#'); $cmdiinstantanee = cmd::byString('#2521#'); $cmdisouscrite = cmd::byString('#2534#'); $cmdGOstate = cmd::byString('#3753#'); $cmdbranche = cmd::byString('#3761#'); $cmdpreseau = cmd::byString('#3401#'); $cmdpreseaulisse = cmd::byString('#2665#'); $cmdprixrevente = cmd::byString('#3849#'); $cmdmodemaison = cmd::byString('#49#'); $cmdcoefrentabilite = cmd::byString('#3945#'); $cmdON = cmd::byString('#3277#'); $cmdOFF = cmd::byString('#3278#'); $cmdPAUSE = cmd::byString('#3279#'); $cmdSETMAX = cmd::byString('#3282#'); // Scenario pour envoi d'alerte $alerte_scenario=scenario::byId(55); $alerte_tags = $alerte_scenario->getTags(); $heureminute = date("Hi",time()); $modeevse = $cmdmode->execCmd(); $niveau = $cmdniveau->execCmd(); $jsonevse = $cmdstatus->execCmd(); $heurecreuse = $cmdHC->execCmd(); $pwallbox_old = $cmdpwallbox->execCmd(); $tension = $cmdtension->execCmd(); $preseau = $cmdpreseau->execCmd(); $preseaulisse = $cmdpreseaulisse->execCmd(); $peffacable = $cmdpeffacable->execCmd(); $pinstantanee = $cmdpinstantanee->execCmd(); $iinstantanee = $cmdiinstantanee->execCmd(); $isouscrite = $cmdisouscrite->execCmd(); $modemaison = $cmdmodemaison->execCmd(); $coefrentabilite = $cmdcoefrentabilite->execCmd(); $openevsepwr = $scenario->getData('openevsepwr'); if ($openevsepwr == '' ) { $openevsepwr = -1; $scenario->setData('openevsepwr', $openevsepwr); } $openevselastchange = $scenario->getData('openevselastchange'); if ($openevselastchange == '' ) { $openevselastchange = 0; $scenario->setData('openevselastchange', $openevselastchange); } $letrigger = cmd::cmdToHumanReadable($scenario->getRealTrigger()); if (strpos($letrigger,'openevse') !== false) { # Update des valeurs venant de openevse if ($jsonevse !='') { $arrayevse = json_decode($jsonevse, true); $mode= $arrayevse['mode']; if ($mode = 'STA') { $amp=(intval($arrayevse['amp']))/1000; $amp_old = $cmdamp->execCmd(); $pilot=intval($arrayevse['pilot']); $pilot_old = $cmdpilot->execCmd(); $temp=(intval($arrayevse['temp1']))/10; $temp_old = $cmdtemp->execCmd(); $state=intval($arrayevse['state']); if ($state==1) $cmdstatetexte->event('ON'); if ($state==2) $cmdstatetexte->event('Connecté'); if ($state==3) $cmdstatetexte->event('En charge'); if ($state==4) $cmdstatetexte->event('Erreur'); if ($state==255) { $state=-1; $cmdstatetexte->event('OFF'); $amp=0; } // Le Off donne un -1 pour plus de facilité à décoder les courbes. if ($state==254) { $state=0; $cmdstatetexte->event('PAUSE'); $amp=0; } // Le Pause donne un 0 pour plus de facilité à décoder les courbes. $state_old = $cmdstate->execCmd(); $elapsed=intval($arrayevse['elapsed']); $elapsed_old = $cmdelapsed->execCmd(); $wattsec = intval($arrayevse['wattsec']); $wattsec_old = $cmdwattsec->execCmd(); $watthour=intval($arrayevse['watthour']); $watthour_old = $cmdwatthour->execCmd(); $pwallbox = round($tension * $amp * 1.01); $lignelog="New: "; $cmdamp->event(($amp)); if ($amp_old != $amp) { $lignelog=$lignelog."Courant($amp) "; } $cmdpilot->event(($pilot)); if ($pilot_old != $pilot) { $lignelog=$lignelog."Ampérage($pilot) "; } $cmdtemp->event(($temp)); if ($temp_old != $temp) { $lignelog=$lignelog."T°($temp) "; } $cmdstate->event(($state)); if ($state_old != $state) { $lignelog=$lignelog."Etat($state) "; } $cmdelapsed->event(($elapsed)); if ($elapsed_old != $elapsed) { $lignelog=$lignelog."Ecoulé($elapsed) ";} if ($wattsec_old != $wattsec) { $lignelog=$lignelog."Watt sec($wattsec) "; } $cmdwattsec->event(($wattsec)); $cmdkwatth->event((round($wattsec/3600000,1))); $cmdmiipc->event((round(100*($wattsec/3600000)/32.2))); $cmdwatthour->event(($watthour)); if ($watthour_old != $watthour) { $lignelog=$lignelog."Watt heure($watthour) "; } $cmdpwallbox->event(($pwallbox)); if ($pwallbox != $pwallbox_old) { $lignelog=$lignelog."pwallbox($pwallbox) "; } } } //Traitement du retour branché ou pas $branche_old = $cmdbranche->execCmd(); $GOstate = $cmdGOstate->execCmd(); if ($GOstate == '$OK 1^31' && $branche_old != 1) { $lignelog=$lignelog."Branché(1) "; $cmdbranche->event((1)); $branche = 1; } elseif ($GOstate == '$OK 0^30' && $branche_old != 0) { $lignelog=$lignelog."Branché(0) "; $cmdbranche->event((0)); $branche = 0; } else $branche = $branche_old; } else { # Pas de mise à jour des valeurs depuis openevse, on récupère les anciennes calculées $amp = $cmdamp->execCmd(); $pilot = $cmdpilot->execCmd(); $temp = $cmdtemp->execCmd(); $state = $cmdstate->execCmd(); $elapsed = $cmdelapsed->execCmd(); $wattsec = $cmdwattsec->execCmd(); $watthour = $cmdwatthour->execCmd(); $branche = $cmdbranche->execCmd(); $pwallbox = round($tension * $amp * 1.01); } $etatchange = -100 ; // ********************************************************************* // *** Debut gestion des modes de charges // ********************************************************************* /* *** Tableau de référence de la charge. Le véhicule programmé pour départ à 7h full charge 7h00 0 mn 100% Programmation du véhicule 6h21 -40 mn 90% Fin de charge avec courant se réduisant de 32A à 14A 5h52 -29 mn 80% Charge 32A 5h23 -29 mn 70% Charge 32A 4h54 -29 mn 60% Charge 32A 4h25 -29 mn 50% Charge 32A 3h56 -29 mn 40% Charge 32A 3h27 -29 mn 30% Charge 32A 2h58 -29 mn 20% Charge 32A 2h29 -29 mn 10% Charge 32A 2h00 -29 mn 0% Charge 32A */ //**************** Gestion mode Nuit if ($modeevse == "Nuit") { $lignelog=$lignelog."| Nuit "; if ($niveau == 'Partielle') $lignelog=$lignelog."charge partielle"; else $lignelog=$lignelog."charge totale"; if ( ($heureminute < 830 || $heureminute > 2200) ) { // Démarrage initial de la charge if ($state <=0 && $openevsepwr == -1 && $iinstantanee < 8 && $heurecreuse == 1) { $etatchange = 32; $scenario->setData('openevsepwr', 0); } // En Partiel, si aucune charge a débuté à 5h10 (~65%) alors que connecté on arrête de tenter de charger if ($state == 2 && $openevsepwr == 0 && $heureminute >510 && $niveau == 'Partielle') { $etatchange = 0; } // En partiel, on arrête la charge à 5h52 soit 80% théorique if ($state == 3 && $niveau == 'Partielle' && ( $heureminute >552 || $heurecreuse == 0 )) { $etatchange = 0; $scenario->setData('openevsepwr', $wattsec); } } else { if ($openevsepwr >=0 && $state <=0 ) $scenario->setData('openevsepwr', -1); if ($state > 0) $etatchange = 0; } //**************** Gestion mode Nuit+PV } elseif ($modeevse == "Nuit+PV") { $lignelog=$lignelog."| Nuit+PV "; if ($niveau == 'Partielle') $lignelog=$lignelog."charge partielle"; else $lignelog=$lignelog."charge totale"; if ( ($heureminute < 830 || $heureminute > 2200) ) { // Démarrage initial de la charge if ($state <=0 && $openevsepwr == -1 && $iinstantanee < 8 && $heurecreuse == 1) { $etatchange = 32; $scenario->setData('openevsepwr', 0); } // En Partiel, si aucune charge a débuté à 5h10 (~65%) alors que connecté on arrête de tenter de charger if ($state == 2 && $openevsepwr == 0 && $heureminute >510 && $niveau == 'Partielle') { $etatchange = 0; } // En partiel, on arrête la charge à 5h52 soit 80% théorique if ($state == 3 && $niveau == 'Partielle' && ( $heureminute >552 || $heurecreuse == 0 )) { $etatchange = 0; $scenario->setData('openevsepwr', $wattsec); } } else { // en dehors de la nuit tout dépend du fait qu'on exporte ou pas assez de puissance vers le réseau.Lorsqu'on exporte la valeur est négative if ($peffacable < -7*$tension * $coefrentabilite) { // Si la voiture n'est pas branché, on envoie un message if ($state<= 0 && $branche == 0 && ($modemaison =='Présence' || $modemaison =='Pyjama')) { $alerte_tags['#alerte_type#'] = 'Attention'; $alerte_tags['#alerte_msg#'] = 'Brancher le véhicule pour charger en solaire.'; $alerte_tags['#alerte_img#'] = 'Aucune'; $alerte_scenario->setTags($alerte_tags); $alerte_scenario->launch(); } $etatchange = floor(max(min((-$preseau + $pwallbox)/$tension,32),6)); } else { if ($openevsepwr >=0 && $state <=0 ) $scenario->setData('openevsepwr', -1); if ($state > 0) $etatchange = 0; } } //**************** Gestion mode PV } elseif ($modeevse == "PV") { $lignelog=$lignelog."| PV "; // en dehors de la nuit tout dépend du fait qu'on exporte ou pas assez de puissance vers le réseau.Lorsqu'on exporte la valeur est négative // Le niveau de démarrage est modulé par le rapport prix de vente divisé par prix d'achat. if ($peffacable < -7*$tension * $coefrentabilite) { // Si la voiture n'est pas branché, on envoie un message if ($state<= 0 && $branche == 0 && ($modemaison =='Présence' || $modemaison =='Pyjama')) { $alerte_tags['#alerte_type#'] = 'Attention'; $alerte_tags['#alerte_msg#'] = 'Brancher le véhicule pour charger en solaire.'; $alerte_tags['#alerte_img#'] = 'Aucune'; $alerte_scenario->setTags($alerte_tags); $alerte_scenario->launch(); } $etatchange = floor(max(min((-$preseau + $pwallbox)/$tension,32),6)); } else { if ($openevsepwr >=0 && $state <=0 ) $scenario->setData('openevsepwr', -1); if ($state > 0) $etatchange = 0; } //**************** Gestion mode Nuit+Jour } elseif ($modeevse == "Nuit+Jour") { $lignelog=$lignelog."| Nuit+Jour "; if ($niveau == 'Partielle') $lignelog=$lignelog."charge partielle"; else $lignelog=$lignelog."charge totale"; // Gestion de la première période la nuit if ( ($heureminute < 830 || $heureminute > 2200) ) { // Démarrage initial de la charge if ($state <=0 && $openevsepwr == -1 && $iinstantanee < 8 && $heurecreuse == 1) { $etatchange = 32; $scenario->setData('openevsepwr', 0); } // En Partiel, si aucune charge a débuté à 5h10 (~65%) alors que connecté on arrête de tenter de charger if ($state == 2 && $openevsepwr == 0 && $heureminute >510 && $niveau == 'Partielle') { $etatchange = 0; } // En partiel, on arrête la charge à 5h52 soit 80% théorique if ($state == 3 && $niveau == 'Partielle' && ( $heureminute >552 || $heurecreuse == 0 )) { $etatchange = 0; $scenario->setData('openevsepwr', $wattsec); } } else { // Gestion de la période heure creuse de jour if ($heurecreuse == 1 ) { // Démarrage initial de la charge if ($state <=0 && $openevsepwr == -1 && $iinstantanee < 8 && $heurecreuse == 1) { $etatchange = 20; $scenario->setData('openevsepwr', 0); } // Autre période, on arrête la charge } else { if ($openevsepwr >=0 && $state <=0 ) $scenario->setData('openevsepwr', -1); if ($state > 0) $etatchange = 0; } } //**************** Gestion mode Tarif HC } elseif ($modeevse == "Tarif HC") { $lignelog=$lignelog."| Tarif HC "; if ($heurecreuse == 1) { if ($heureminute > 800 && $heureminute <2200 ) { if ($state <= 0 && $iinstantanee < 24 ) $etatchange = 16 ; } else { if ($state <= 0 && $iinstantanee < 8 ) $etatchange = 32 ; } } else { if ($state > 0 ) $etatchange = 0; } //**************** Gestion mode Illimité } elseif ($modeevse == "Illimité") { $lignelog=$lignelog."| Illimité "; if ($state <= 0 ) $etatchange = 32 ; //**************** Gestion mode OFF } elseif ($modeevse == "OFF") { $lignelog=$lignelog."| OFF "; if ($state >= 0 ) $etatchange = -1 ; //**************** Gestion mode manuel : facile, on ne fait rien ! } elseif ($modeevse == "Manuel") { $lignelog=$lignelog."| Manuel "; } //***************** Gestion des limites de courant et température **** // Sauvegarde du courant demandé par les modes ci-dessus (c'est une info furtive) if ($etatchange < -1 ) { $openevseamprec = $scenario->getData('openevseamprec'); } elseif ($etatchange >= 6 ) { $openevseamprec = $etatchange; $scenario->setData('openevseamprec', $openevseamprec); } if ($state == 3 && $etatchange != 0 && $etatchange != -1) { // Limitation de la charge par rapport au courant consommé au compteur (marge de 2A) // On utilise Pinstantanée pour savoir si on consomme ou si on produit sur le réseau ( si 0 alors on produit) if ($iinstantanee > $amp && $pinstantanee>3000) { $etatchangecourant = ($isouscrite-2)-($iinstantanee -$amp); if ( $etatchangecourant < $openevseamprec ) $lignelog=$lignelog."| ILimit = $etatchangecourant A "; } else { $etatchangecourant = 48; } // Limitation de la charge par rapport à la température dans openevse if ($temp > 57 ) { if ($temp > 57+2.6 ) { $etatchangetemp = 6; } else { $etatchangetemp = 10 * (57 + 2.6 - $temp ) + 6; } if ( $etatchangetemp < $openevseamprec ) $lignelog=$lignelog."| TLimit = $etatchangetemp A "; } else { $etatchangetemp = 48; } // On applique la modification dynamique de courant si nécessaire $etatchangecorrige = floor(max(min($openevseamprec,$etatchangecourant,$etatchangetemp,32),6)); if ($etatchangecorrige != $pilot) { $etatchange = $etatchangecorrige; } } //************ On vérifie qu'on ne réalise pas trop rapidement de changement en auto de ON à OFF et inversement *************** if (($etatchange == -1 && $state >= 2) || ($etatchange == 0 && $state >= 2) || ($etatchange > 0 && $state <= 0)) { if ( $modeevse != "Illimité" && $modeevse != "OFF" && $modeevse != "Manuel" && (time() - $openevselastchange < 15*60 )) { $etatchange = -100; } else { $scenario->setData('openevselastchange', time()); } } //***************** Envoi des changements **** if ($etatchange == -1 ) { $cmdOFF->execCmd(); $lignelog=$lignelog."| $state--> OFF"; } elseif ($etatchange == 0 ) { $cmdPAUSE->execCmd(); $lignelog=$lignelog."| $state--> Pause"; } elseif ($etatchange >= 6 && $etatchange <= 32) { $options = array('slider'=>"$etatchange"); $cmdSETMAX->execCmd($options, $cache=0); $cmdON->execCmd(); $lignelog=$lignelog."| $state --> ON ($etatchange A)"; } $scenario->setLog($lignelog);