F1ATB forum
Intégration shelly PRO em - Version imprimable

+- F1ATB forum (https://f1atb.fr/forum_f1atb)
+-- Forum : Forum de F1ATB (https://f1atb.fr/forum_f1atb/forum-3.html)
+--- Forum : Routeur Photovoltaïque (https://f1atb.fr/forum_f1atb/forum-4.html)
+---- Forum : Evolutions faites, à faire, dont vous rêvez... (https://f1atb.fr/forum_f1atb/forum-10.html)
+---- Sujet : Intégration shelly PRO em (/thread-91.html)

Pages : 1 2 3 4 5 6 7


RE: Intégration shelly PRO em - Raphael591 - 19-10-2024

Nickel.
Libellé paramétrage voie à changer de " Monophasé : Numéro de voie (0 ou 1) mesurant l'entrée du courant maison" à "Monophasé : Numéro de voie (0 ou 1 ou 2) mesurant l'entrée du courant maison "
3 pour triphasé ne change pas.

NB : pour le pro EM 50, la seconde sonde de mesure est ramené automatiquement en seconde sonde dans le routeur. Chez moi, mon routeur affiche donc ma conso et ma production solaire.

Code du fichier Source_ShellyProEm.ino
a+

Code :
//****************************************************************
// Variante Shelly Pro Em proposé par Raphael591 (Juillet 2024)
//  + Correction Octobre 2024
// ****************************************************
// * Client d'un Shelly Em sur voie 0 ou 1 ou triphasé*
// ****************************************************

void LectureShellyProEm()
{
  String S = "";
  String Shelly_Data = "";
  String Shelly_Name = "";
  float Pw = 0;
  float voltage = 0;
  float pf = 0;

  // ADD PERSO : AJOUT VARIABLE JSON pour facilité la lecture des infos EM PRO
  String tmp; // ADD PERSO

  // Use WiFiClient class to create TCP connections
  WiFiClient clientESP_RMS;
  byte arr[4];
  arr[0] = RMSextIP & 0xFF;         // 0x78
  arr[1] = (RMSextIP >> 8) & 0xFF;  // 0x56
  arr[2] = (RMSextIP >> 16) & 0xFF; // 0x34
  arr[3] = (RMSextIP >> 24) & 0xFF; // 0x12

  String host = String(arr[3]) + "." + String(arr[2]) + "." + String(arr[1]) + "." + String(arr[0]);
  if (!clientESP_RMS.connect(host.c_str(), 80))
  {
    StockMessage("connection to Shelly Em failed : " + host);
    delay(200);
    return;
  }
  int voie = EnphaseSerial.toInt();
  int Voie = voie % 2;

  if (ShEm_comptage_appels == 1)
  {
    Voie = (Voie + 1) % 2;
  }

  // Connaître modèle du shelly *******************************************
  String url = "/rpc/Shelly.GetDeviceInfo";
  clientESP_RMS.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
  unsigned long timeout = millis();
  while (clientESP_RMS.available() == 0)
  {
    if (millis() - timeout > 5000)
    {
      StockMessage("client Shelly Em Timeout ! : " + host);
      clientESP_RMS.stop();
      return;
    }
  }
  timeout = millis();
  // Lecture des données brutes distantes
  while (clientESP_RMS.available() && (millis() - timeout < 5000))
  {
    Shelly_Data += clientESP_RMS.readStringUntil('\r');
  }
  Shelly_Name = StringJson("id", Shelly_Data);
  int p = Shelly_Name.indexOf("-");
  Shelly_Name = Shelly_Name.substring(0,p);
  Shelly_Data = "";
  // Modèle shelly FIN *****************************************************
 
  if (!clientESP_RMS.connect(host.c_str(), 80))
  {
    StockMessage("connection to Shelly Em failed : " + host);
    delay(200);
    return;
  }

  url = "/rpc/Shelly.GetStatus";                  // pour Pro Em
  ShEm_comptage_appels = (ShEm_comptage_appels + 1) % 5; // 1 appel sur 6 vers la deuxième voie qui ne sert pas au routeur
  clientESP_RMS.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
  timeout = millis();
  while (clientESP_RMS.available() == 0)
  {
    if (millis() - timeout > 5000)
    {
      StockMessage("client Shelly Em Timeout 2 ! : " + host);
      clientESP_RMS.stop();
      return;
    }
  }
  timeout = millis();
  // Lecture des données brutes distantes
  while (clientESP_RMS.available() && (millis() - timeout < 5000))
  {
    Shelly_Data += clientESP_RMS.readStringUntil('\r');
  }
  p = Shelly_Data.indexOf("{");
  Shelly_Data = Shelly_Data.substring(p);
  if (Shelly_Name == "shellypro3em" && voie == 3) {
    // 3 em Triphasé
    ShEm_dataBrute = "<strong>"+Shelly_Name+"</strong><br>" + Shelly_Data;

    float pf1, pf2, pf3;
    float volt1, volt2, volt3;

    tmp = PrefiltreJson("em:0", ":", Shelly_Data);

    Pw = ValJson("total_act_power", tmp);   

    volt1 = ValJson("a_voltage", tmp);
    pf1 = ValJson("a_pf", tmp);

    volt2 = ValJson("b_voltage", tmp);
    pf2 = ValJson("b_pf", tmp);

    volt3 = ValJson("c_voltage", tmp);
    pf3 = ValJson("c_pf", tmp);

    voltage = (volt1 + volt2 + volt3) / 3;
    pf = abs((pf1 + pf2 + pf3) / 3);
    if (pf > 1) pf = 1;
    if (Pw >= 0) {
      PuissanceS_M_inst = Pw;
      PuissanceI_M_inst = 0;
      if (pf > 0.01) {
        PVAS_M_inst = PfloatMax(Pw / pf);
      } else {
        PVAS_M_inst = 0;
      }
      PVAI_M_inst = 0;
    }
    else {
      PuissanceS_M_inst = 0;
      PuissanceI_M_inst = -Pw;
      if (pf > 0.01)
      {
        PVAI_M_inst = PfloatMax(-Pw / pf);
      }
      else
      {
        PVAI_M_inst = 0;
      }
      PVAS_M_inst = 0;
    }
    tmp = PrefiltreJson("emdata:0", ":", Shelly_Data); // ADD PERSO
    Energie_M_Soutiree = myLongJson("total_act", tmp);         // ADD PERSO
    Energie_M_Injectee = myLongJson("total_act_ret", tmp);     // ADD PERSO
    PowerFactor_M = pf;
    Tension_M = voltage;
    Pva_valide = true;
  }
  else if (Shelly_Name == "shellypro3em")
  {
    // 3 em Monophasé : Voie != 3
    ShEm_dataBrute = "<strong>"+Shelly_Name+"</strong><br>" + Shelly_Data;

    tmp = PrefiltreJson("em1:" + String(Voie), ":", Shelly_Data); // Voie mono
    Pw = ValJson("act_power", tmp);
    voltage = ValJson("voltage", tmp);
    pf = ValJson("pf", tmp);
    pf = abs(pf);
    if (pf > 1) pf = 1;
    if (Pw >= 0)
    {
      PuissanceS_M_inst = Pw;
      PuissanceI_M_inst = 0;
      if (pf > 0.01)
      {
        PVAS_M_inst = PfloatMax(Pw / pf);
      }
      else
      {
        PVAS_M_inst = 0;
      }
      PVAI_M_inst = 0;
    }
    else
    {
      PuissanceS_M_inst = 0;
      PuissanceI_M_inst = -Pw;
      if (pf > 0.01)
      {
        PVAI_M_inst = PfloatMax(-Pw / pf);
      }
      else
      {
        PVAI_M_inst = 0;
      }
      PVAS_M_inst = 0;
    }
    tmp = PrefiltreJson("em1data:" + String(Voie), ":", Shelly_Data); // ADD PERSO
    Energie_M_Soutiree = myLongJson("total_act_energy", tmp);         // ADD PERSO
    Energie_M_Injectee = myLongJson("total_act_ret_energy", tmp);     // ADD PERSO
    PowerFactor_M = pf;
    Tension_M = voltage;
    Pva_valide = true;
  }
  else if (Shelly_Name == "shellyproem50" )
  { // Monophasé pro EM
    ShEm_dataBrute = "<strong>" + Shelly_Name + "</strong><br>" + Shelly_Data;
    Shelly_Data = Shelly_Data + ",";
    if (Shelly_Data.indexOf("true") > 0)
    {                                                               // Donnée valide
      tmp = PrefiltreJson("em1:" + String(Voie), ":", Shelly_Data); // ADD PERSO
      Pw = ValJson("act_power", tmp);                               // ADD PERSO
      voltage = ValJson("voltage", tmp);                            // ADD PERSO
      pf = ValJson("pf", tmp);                                      // ADD PERSO
      pf = abs(pf);
      if (pf > 1) pf = 1;
      if (Voie == voie)
      { // voie du routeur
        if (Pw >= 0)
        {
          PuissanceS_M_inst = Pw;
          PuissanceI_M_inst = 0;
          if (pf > 0.01)
          {
            PVAS_M_inst = PfloatMax(Pw / pf);
          }
          else
          {
            PVAS_M_inst = 0;
          }
          PVAI_M_inst = 0;
        }
        else
        {
          PuissanceS_M_inst = 0;
          PuissanceI_M_inst = -Pw;
          if (pf > 0.01)
          {
            PVAI_M_inst = PfloatMax(-Pw / pf);
          }
          else
          {
            PVAI_M_inst = 0;
          }
          PVAS_M_inst = 0;
        }
        tmp = PrefiltreJson("em1data:" + String(Voie), ":", Shelly_Data); // ADD PERSO
        Energie_M_Soutiree = myLongJson("total_act_energy", tmp);         // ADD PERSO
        Energie_M_Injectee = myLongJson("total_act_ret_energy", tmp);     // ADD PERSO
        PowerFactor_M = pf;
        Tension_M = voltage;
        Pva_valide = true;
      }
      else
      { // voie secondaire
        if (LissageLong)
        {
          PwMoy2 = 0.2 * Pw + 0.8 * PwMoy2; // Lissage car moins de mesure sur voie secondaire
          pfMoy2 = 0.2 * pf + 0.8 * pfMoy2;
          Pw = PwMoy2;
          pf = pfMoy2;
        }
        if (Pw >= 0)
        {
          PuissanceS_T_inst = Pw;
          PuissanceI_T_inst = 0;
          if (pf > 0.01)
          {
            PVAS_T_inst = PfloatMax(Pw / pf);
          }
          else
          {
            PVAS_T_inst = 0;
          }
          PVAI_T_inst = 0;
        }
        else
        {
          PuissanceS_T_inst = 0;
          PuissanceI_T_inst = -Pw;
          if (pf > 0.01)
          {
            PVAI_T_inst = PfloatMax(-Pw / pf);
          }
          else
          {
            PVAI_T_inst = 0;
          }
          PVAS_T_inst = 0;
        }
        tmp = PrefiltreJson("em1data:" + String(Voie), ":", Shelly_Data); // ADD PERSO
        Energie_T_Soutiree = myLongJson("total_act_energy", tmp);         // ADD PERSO
        Energie_T_Injectee = myLongJson("total_act_ret_energy", tmp);     // ADD PERSO
        PowerFactor_T = pf;
        Tension_T = voltage;
      }
    }
  }
  filtre_puissance();
  PuissanceRecue = true; // Reset du Watchdog à chaque trame du Shelly reçue
  if (ShEm_comptage_appels > 1)
    EnergieActiveValide = true;
  if (cptLEDyellow > 30)
  {
    cptLEDyellow = 4;
  }
}



RE: Intégration shelly PRO em - F1ATB - 19-10-2024

Version 12.04
***********
Cette nouvelle version 12.04 inclut le code mis à jour par Rapahel591 pour les Shelly Pro, Shelly Pro3em et Shelly Pro Em50. Merci à lui. N'ayant pas de Shelly Pro , il m'était impossible de tester.

Cordialement
André


RE: Intégration shelly PRO em - F1ATB - 19-10-2024

Comprend pas, j'ai repris son code du 14/10
André


RE: Intégration shelly PRO em - F1ATB - 19-10-2024

Je viens de constater que le code d'il y a une heure est différent de celui du 14/10. J'ai donc repris la compilation de la version 12.04. Je l'ai mis en ligne sans changer le numéro de version.

Cdlt
André


RE: Intégration shelly PRO em - Raphael591 - 19-10-2024

(19-10-2024, 09:06 PM)Lolo69 a écrit : La 12.04 genere un bug d affichage sur la page donnée brute pour un routeur avec mesure Shelly Em

Shelly em ?
Ici les modif concernent les modèles pro 3em et pro em 50.


RE: Intégration shelly PRO em - F1ATB - 20-10-2024

Je ne comprend pas pourquoi. Il y a eu 0 modifications pour le Shelly Em entre V12.03 et V12.04. Uniquement ShellyProEm.ino a été touché ainsi que la page web de gestion des Actions.
C'est quoi le bug sur la page données brutes?
Cdlt
André


RE: Intégration shelly PRO em - Robi60 - 20-10-2024

Bonjour,
Pas de soucis pour ma part avec la 12.04 : 3EM ou PRO3EM tout fonctionne bien

Merci pour la compilation de la 12.04


RE: Intégration shelly PRO em - manusaxo - 03-11-2024

Bonjour.
Pas eu le temps de faire un tour ici.

Avec 3 EM pro en triphasé. Et routeur en 12.06

Je confirme que désormais la lecture se fait correctement directement depuis le Shelly.

Merci beaucoup !


RE: Intégration shelly PRO em - Isaak - 03-01-2025

bonjour
avec la V13 et un shelly pro 3 em en monophasé, impossible d'avoir sur le tableau d'accueil la bonne voie de puissance ( mes 3 pinces mesurent respectivement ballon ECS, Solaire et arrivée EDF)
que je mette 0,1 ou 2 le routeur ne remonte que la voie 1 qui correspond à mon solaire...
j'ai manqué qque chose ?
merci

données brutes :

shellypro3em
{ble:{}
bthome:{errors:[bluetooth_disabled]}
cloud:{connected:false}
em1:0:{id:0
current:0.028
voltage:233.4
act_power:0.0
aprt_power:6.6
pf:0.00
freq:50.0
calibration:factory
flags:[count_disabled]}
em1:1:{id:1
current:0.079
voltage:233.5
act_power:-3.5
aprt_power:18.5
pf:0.18
freq:50.0
calibration:factory
flags:[count_disabled]}
em1:2:{id:2
current:2.338
voltage:233.6
act_power:313.0
aprt_power:546.3
pf:0.57
freq:50.0
calibration:factory
flags:[count_disabled]}
em1data:0:{id:0
total_act_energy:56178.37
total_act_ret_energy:29.54}
em1data:1:{id:1
total_act_energy:25304.81
total_act_ret_energy:1108.21}
em1data:2:{id:2
total_act_energy:146469.63
total_act_ret_energy:1245.59}
eth:{ip:null}
modbus:{}
mqtt:{connected:false}
switch:100:{id:100
source:init
output:false
temperature:{tC:28.9
tF:84.0}}
sys:{mac:08F9E0E6C514
restart_required:false
time:00:23
unixtime:1735860211
uptime:2924
ram_size:246840
ram_free:100636
fs_size:524288
fs_free:176128
cfg_rev:31
kvs_rev:0
schedule_rev:13
webhook_rev:1
available_updates:{}
reset_reason:3}
temperature:0:{id: 0
tC:35.1
tF:95.3}
wifi:{sta_ip:192.168.1.85
status:got ip
ssidBig Grinada _EXT
rssi:-41}
ws:{connected:false}}


RE: Intégration shelly PRO em - Chris - 03-01-2025

Bonjour,
Je ne vois pas de différences avec mes données brutes.
Tu as reset après avoir sauvegardé ?