Note de ce sujet :
  • Moyenne : 0 (0 vote(s))
  • 1
  • 2
  • 3
  • 4
  • 5
Intégration shelly PRO em
#42
(14-10-2024, 03:20 PM)Raphael591 a écrit : Qui peut tester ?
C'est fonctionnel pour le shelly pro 50 EM.

Besoin d'un test avec un pro 3 em en monophasé et un avec un triphasé.

Paramétrage de la voie pour le shelly pro 3 em :
   - 3 sur le triphasé.
   - 0 ou 1 ou 2 sur le monophasé fonction de la pince à utiliser.

Fichier Bin :  https://uploadnow.io/f/gMbYjnw
Source_ShellyEm.ino
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";
  //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");
  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 Pw1, Pw2, Pw3;
    float pf1, pf2, pf3;
    float volt1, volt2, volt3;

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

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

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

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

    Pw = (Pw1 + Pw2 + Pw3) / 3;
    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>Voie : " + 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;
  }
}

Hello, 
je m'insère dans la conversation ;-)
Je suis en triphasé,
J'ai acheté un Pro3EM il y a 4 mois dans le but de faire le routeur
Et vu après l'avoir installé que le routeur était indiqué comme "pas fonctionnel" en tri avec le PRO3EM. Je m'étais dit que je regarderai comment c'est fait le jour où je démarrerai le routeur.
J'ai commencé mercredi, v12.01 etc, J'ai également un Shelly 3EM donc je peux switcher de l'un à l'autre : 3EM OK, Pro3EM marche pas mais effectivement on voyait les valeurs passer dans les données brutes.
Je regarde sur le forum, et, oh bonheur cette mise à jour de code de Raphael591!

Copier coller, injecté et hop ça fonctionne sous la 12.0.1 donc avec un PRO3EM et triphasé, voir captures
bien joué et un gros merci.

Veux-tu vérifier d'autres choses afin de valider la modif et passer le code en standard?

       
Répondre


Messages dans ce sujet
Intégration shelly PRO em - par Raphael591 - 12-06-2024, 05:49 PM
RE: Intégration shelly PRO em - par F1ATB - 12-06-2024, 07:10 PM
RE: Intégration shelly PRO em - par Raphael591 - 12-06-2024, 07:16 PM
RE: Intégration shelly PRO em - par F1ATB - 12-06-2024, 07:18 PM
RE: Intégration shelly PRO em - par Raphael591 - 12-06-2024, 07:53 PM
RE: Intégration shelly PRO em - par DanielJ - 17-06-2024, 04:00 PM
RE: Intégration shelly PRO em - par Raphael591 - 23-06-2024, 03:33 PM
RE: Intégration shelly PRO em - par F1ATB - 23-06-2024, 04:31 PM
RE: Intégration shelly PRO em - par DanielJ - 26-06-2024, 12:36 PM
RE: Intégration shelly PRO em - par Raphael591 - 26-06-2024, 02:31 PM
RE: Intégration shelly PRO em - par F1ATB - 03-07-2024, 04:23 PM
RE: Intégration shelly PRO em - par DanielJ - 03-07-2024, 06:56 PM
RE: Intégration shelly PRO em - par Raphael591 - 03-07-2024, 10:01 PM
RE: Intégration shelly PRO em - par F1ATB - 04-07-2024, 08:31 AM
RE: Intégration shelly PRO em - par olivr2s - 23-08-2024, 12:13 PM
RE: Intégration shelly PRO em - par Raphael591 - 04-07-2024, 09:49 AM
RE: Intégration shelly PRO em - par F1ATB - 24-08-2024, 05:51 AM
RE: Intégration shelly PRO em - par olivr2s - 24-08-2024, 01:51 PM
RE: Intégration shelly PRO em - par manusaxo - 28-08-2024, 08:49 AM
RE: Intégration shelly PRO em - par olivr2s - 28-08-2024, 09:40 AM
RE: Intégration shelly PRO em - par manusaxo - 28-08-2024, 08:27 PM
RE: Intégration shelly PRO em - par vmarchis - 07-10-2024, 06:43 PM
RE: Intégration shelly PRO em - par F1ATB - 29-08-2024, 08:01 AM
RE: Intégration shelly PRO em - par manusaxo - 29-08-2024, 10:55 AM
RE: Intégration shelly PRO em - par olivr2s - 29-08-2024, 11:17 AM
RE: Intégration shelly PRO em - par manusaxo - 30-08-2024, 12:07 PM
RE: Intégration shelly PRO em - par olivr2s - 31-08-2024, 12:33 PM
RE: Intégration shelly PRO em - par manusaxo - 13-10-2024, 07:28 PM
RE: Intégration shelly PRO em - par olivr2s - 13-10-2024, 07:39 PM
RE: Intégration shelly PRO em - par F1ATB - 13-10-2024, 07:37 PM
RE: Intégration shelly PRO em - par Raphael591 - 14-10-2024, 10:43 AM
RE: Intégration shelly PRO em - par Raphael591 - 14-10-2024, 12:37 PM
RE: Intégration shelly PRO em - par olivr2s - 14-10-2024, 01:05 PM
RE: Intégration shelly PRO em - par Raphael591 - 14-10-2024, 02:00 PM
RE: Intégration shelly PRO em - par Raphael591 - 14-10-2024, 03:20 PM
RE: Intégration shelly PRO em - par Robi60 - 18-10-2024, 09:04 PM
RE: Intégration shelly PRO em - par cetin.s - 17-10-2024, 06:12 AM
RE: Intégration shelly PRO em - par Raphael591 - 17-10-2024, 04:23 PM
RE: Intégration shelly PRO em - par F1ATB - 17-10-2024, 04:45 PM
RE: Intégration shelly PRO em - par cetin.s - 17-10-2024, 07:32 PM
RE: Intégration shelly PRO em - par Raphael591 - 17-10-2024, 08:57 PM
RE: Intégration shelly PRO em - par cetin.s - 18-10-2024, 09:38 PM
RE: Intégration shelly PRO em - par Raphael591 - 19-10-2024, 03:25 PM
RE: Intégration shelly PRO em - par F1ATB - 19-10-2024, 04:13 PM
RE: Intégration shelly PRO em - par cetin.s - 19-10-2024, 04:34 PM
RE: Intégration shelly PRO em - par F1ATB - 19-10-2024, 05:15 PM
RE: Intégration shelly PRO em - par F1ATB - 19-10-2024, 05:30 PM
RE: Intégration shelly PRO em - par cetin.s - 19-10-2024, 05:32 PM
RE: Intégration shelly PRO em - par Lolo69 - 19-10-2024, 09:06 PM
RE: Intégration shelly PRO em - par Raphael591 - 19-10-2024, 09:19 PM
RE: Intégration shelly PRO em - par F1ATB - 20-10-2024, 04:17 AM
RE: Intégration shelly PRO em - par Robi60 - 20-10-2024, 11:41 AM

Atteindre :


Utilisateur(s) parcourant ce sujet : 8 visiteur(s)