Como instalar e configurar um Medidor de Energia SDM120


(Rodolfo) #42

@Nuno_Figueiredo podes postar uma foto do conversor que tas a usar? quais foram as ligações? foram as mesmas que postei acima no topico?


(Nuno Figueiredo) #43

as ligações são as mesmas, apenas como é um MAX485 temos de ativar o DERE pin

fiz assim

sdm<2400, 12, 13, 4) - D6/D7/D4

no max485 uni o DE com o RE e levei essa ligação ao D4 do nodemcu. e estou a alimentar com 3,3v o max485 mas tb podia ser com 5v

onde consigo saber uma lista dos PIN com o que fica no arduino ide, por exemplo, ando as aranhas pq nunca sei que o pino do Tx ou Rx ou outro = no arduino a ??
como ja sei que por exemplo, 12 = D6, 13 = D7, 2 = D4.

o conversor é exatamente este.


(Rodolfo) #44

@Nuno_Figueiredo faz me um favor… pega uma folha A4 e faz um desenho das ligações para esse conversor, há muita gente que não sabe ligar isso e tu conseguiste. podes fazer isso e colocar aqui por favor?


(Frederico Oliveira) #45

WObrigada Nuno vou testar isso a noite.
Quando escreveste 2400 falas do baudrate entre o SDM e o weemos correcto?
O meu SDM é um 220 e tem vários parâmetros da comunicação que são configuráveis:
Baudrate, parity, stop bit e ModBus adress.
Fica cá a foto das possíveis configurações do meu SDM!
FB_IMG_1527262888650|286x480


(Rogério Figueiredo) #46

Também andei as cabeçadas durante muito tempo e nao consegui meter a funcionar se poderes partilhas tuas coisas com screen o HA a funcionar agradecia


(Nuno Figueiredo) #47

nao alterei nada do sdm, esta como vinha.


(Nuno Figueiredo) #48

uma coisa que ainda nao percebi como resolver e o nodemcu ficar sem wireless, já testei um delay de 30 segundos entre leituras, ou pode ser problema da minha rede, de qualquer das formas se alguem tiver o mesmo problema e tenha de ideia de como resolver avise, talvez seja possivel no codigo do arduino pedir para o wifi reconectar, basta desligar o nodemcu e voltar a ligar e fica a funcionar.

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <SDM.h>                                                                //import SDM template library
//SDM<2400, 12, 13> sdm;                                                        //SDM120T  baud, rx pin, tx pin
//SDM<4800, 12, 13> sdm;                                                        //SDM120C baud, rx pin, tx pin
//SDM<9600, 12, 13> sdm;                                                        //SDM630  baud, rx pin, tx pin
//or without parameters (default from SDM.h will be used): 
SDM<2400, 12, 13, 4> sdm;
float m = 0;
char charBuf[50];
String s;

  const char* ssid = "SSID";                                                // Wifi SSID
  const char* password = "PASSWORD WIFI";                                          // Wifi password

  IPAddress ip(192,168,1,25);                                                  // IP address
  IPAddress dns(8,8,8,8);                                                       // DNS server
  IPAddress gateway(192,168,1,254);                                               // Gateway
  IPAddress subnet(255,255,255,0);                                              // Subnet mask
const char* mqtt_server = "192.168.1.132";

#define mqtt_user "user mqtt"
#define mqtt_password "password mqtt"
  int MQTT_WILL_QOS = 1;                                                        // MQTT last will QoS (0,1 or 2)
  int MQTT_WILL_RETAIN = 1;                                                     // MQTT last will retain (0 or 1)

WiFiClient espClient;
PubSubClient client(espClient);
long lastMsg = 0;
char msg[50];
int value = 0;

void setup() {
  pinMode(BUILTIN_LED, OUTPUT);     // Initialize the BUILTIN_LED pin as an output
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
  Serial.begin(115200);                                                         //initialize serial
  sdm.begin();                                                                  //initalize SDM220 communication baudrate
}

void setup_wifi() {
  delay(10);
  // config static IP
  Serial.print(F("Setting static ip to : "));
  Serial.println(ip);
      WiFi.config(ip, gateway, subnet, dns);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();

  // Switch on the LED if an 1 was received as first character
  if ((char)payload[0] == '1') {
    digitalWrite(BUILTIN_LED, LOW);   // Turn the LED on (Note that LOW is the voltage level
    // but actually the LED is on; this is because
    // it is acive low on the ESP-01)
  } else {
    digitalWrite(BUILTIN_LED, HIGH);  // Turn the LED off by making the voltage HIGH
  }

}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("SDM120",mqtt_user,mqtt_password,"sdm120/status", 2, 0, "0")) {
      Serial.println("connected");
      // Once connected, publish an announcement...
      client.publish("sdm120/status", "1");
      // ... and resubscribe
      client.subscribe("inTopic");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

  long now = millis();
  if (now - lastMsg > 2000) {
    lastMsg = now;
    
    s = String(sdm.readVal(SDM220T_VOLTAGE));
    if (s != "nan") {
      s.toCharArray(charBuf, 50);
      client.publish("sdm120/volt", charBuf);
      Serial.print("Voltage:   ");
      Serial.print(s);
      Serial.println(" V");
    }
    delay(50);

    s = String(sdm.readVal(SDM220T_CURRENT));
    if (s != "nan") {
    s.toCharArray(charBuf, 50);
    client.publish("sdm120/curr", charBuf);
    Serial.print("Current:   ");    
    Serial.print(s);
    Serial.println(" A");
    }
    delay(50);

    s = String(sdm.readVal(SDM220T_POWER));
    if (s != "nan") {
    s.toCharArray(charBuf, 50);
    client.publish("sdm120/pow", charBuf);
    Serial.print("Power:   ");    
    Serial.print(s);
    Serial.println(" W");
    }
    delay(50);   
  
    s = String(sdm.readVal(SDM220T_ACTIVE_APPARENT_POWER));
    if (s != "nan") {
    s.toCharArray(charBuf, 50);
    client.publish("sdm120/act_app_pow", charBuf);
    Serial.print("Active apparent power:   ");    
    Serial.print(s);
    Serial.println(" VA");
    }
    delay(50);   

    s = String(sdm.readVal(SDM220T_REACTIVE_APPARENT_POWER));
    if (s != "nan") {
    s.toCharArray(charBuf, 50);
    client.publish("sdm120/react_app_pow", charBuf);
    Serial.print("Active apparent power:   ");    
    Serial.print(s);
    Serial.println(" VAR");
    }
    delay(50);   
  
    s = String(sdm.readVal(SDM220T_POWER_FACTOR));
    if (s != "nan") {
    s.toCharArray(charBuf, 50);
    client.publish("sdm120/pow_factor", charBuf);
    Serial.print("Power factor:   ");    
    Serial.print(s);
    Serial.println(" ");
    }
    delay(50);   
  
    s = String(sdm.readVal(SDM220T_PHASE_ANGLE));
    if (s != "nan") {
    s.toCharArray(charBuf, 50);
    client.publish("sdm120/phase_angle", charBuf);
    Serial.print("Phase angle:   ");    
    Serial.print(s);
    Serial.println(" Degree");
    }
    delay(50);     

    s = String(sdm.readVal(SDM220T_FREQUENCY));
    if (s != "nan") {
    s.toCharArray(charBuf, 50);
    client.publish("sdm120/freq", charBuf);
    Serial.print("Frequency:   ");    
    Serial.print(s);
    Serial.println(" Hz");
    }
    delay(50);    

    s = String(sdm.readVal(SDM220T_TOTAL_ACTIVE_ENERGY));
    if (s != "nan") {
    s.toCharArray(charBuf, 50);
    client.publish("sdm120/tot_act_en", charBuf);
    Serial.print("Total active energy:   ");    
    Serial.print(s);
    Serial.println(" Wh");
    }
    delay(50);    

    s = String(sdm.readVal(SDM220T_TOTAL_REACTIVE_ENERGY));
    if (s != "nan") {
    s.toCharArray(charBuf, 50);
    client.publish("sdm120/tot_react_en", charBuf);
    Serial.print("Total reactive energy:   ");    
    Serial.print(s);
    Serial.println(" Wh");
    }
    delay(50);    

    s = String(sdm.readVal(SDM220T_IMPORT_ACTIVE_ENERGY));
    if (s != "nan") {
    s.toCharArray(charBuf, 50);
    client.publish("sdm120/import_act_en", charBuf);
    Serial.print("Import active energy:   ");    
    Serial.print(s);
    Serial.println(" Wh");
    }
    delay(50);    

    s = String(sdm.readVal(SDM220T_EXPORT_ACTIVE_ENERGY));
    if (s != "nan") {
    s.toCharArray(charBuf, 50);
    client.publish("sdm120/export_act_en", charBuf);
    Serial.print("Export active energy:   ");    
    Serial.print(s);
    Serial.println(" Wh");
    }
    delay(50);    

    s = String(sdm.readVal(SDM220T_IMPORT_REACTIVE_ENERGY));
    if (s != "nan") {
    s.toCharArray(charBuf, 50);
    client.publish("sdm120/import_react_en", charBuf);
    Serial.print("Import reactive energy:   ");    
    Serial.print(s);
    Serial.println(" VARh");
    }
    delay(50); 

    s = String(sdm.readVal(SDM220T_EXPORT_REACTIVE_ENERGY));
    if (s != "nan") {
    s.toCharArray(charBuf, 50);
    client.publish("sdm120/export_react_en", charBuf);
    Serial.print("Export reactive energy:   ");    
    Serial.print(s);
    Serial.println(" VARh");
    }
    delay(30000);

    Serial.println("----------------------------------------");

  }
  //wait a while before next loop
}

Libraria do arduino SDM.H , criem pasta na librarias.

/* Template library for reading SDM 120/220/630 Modbus Energy meters.
*  Reading via Software Serial library & rs232<->rs485 converter
*  2016 Reaper7 (tested on wemos d1 mini->ESP8266 with Arduino 1.6.9 & 2.3.0 esp8266 core)
*  crc calculation by Jaime García (https://github.com/peninquen/Modbus-Energy-Monitor-Arduino/)
*/

//#define USE_HARDWARESERIAL                                                    //option - use hardware serial

#ifndef SDM_h
#define SDM_h
//------------------------------------------------------------------------------
#include <Arduino.h>
#if !defined ( USE_HARDWARESERIAL )
#include <SoftwareSerial.h>
#endif
//------------------------------------------------------------------------------
#define SDM_BAUD                            4800                                //baudrate
#define MAX_MILLIS_TO_WAIT                  500                                 //max time to wait for response from SDM

#if !defined ( USE_HARDWARESERIAL )
#define SDMSER_RX_PIN                       13                                  //RX-D7(wemos)-13
#define SDMSER_TX_PIN                       15                                  //TX-D8(wemos)-15
#else
#define SWAPHWSERIAL                        0                                   //when hwserial used, then swap uart pins from 3/1 to 13/15
#endif

#define DERE_PIN                            NOT_A_PIN                           //digital pin for control MAX485 DE/RE lines (connect DE & /RE together to this pin)

#define FRAMESIZE                           9                                   //size of out/in array
//------------------------------------------------------------------------------
#define SDM_REPLY_BYTE_COUNT                0x04                                //number of bytes with data

#define SDM_B_01                            0x01                                //BYTE 1 -> slave address (default value 1 read from node 1)
#define SDM_B_02                            0x04                                //BYTE 2 -> function code (default value 0x04 read from 3X input registers)
                                                                                //BYTES 3 & 4 (BELOW)
//SDM 120 registers
#define SDM120C_VOLTAGE                     0x0000                              //V
#define SDM120C_CURRENT                     0x0006                              //A
#define SDM120C_POWER                       0x000C                              //W
#define SDM120C_ACTIVE_APPARENT_POWER       0x0012                              //VA
#define SDM120C_REACTIVE_APPARENT_POWER     0x0018                              //VAR
#define SDM120C_POWER_FACTOR                0x001E                              //
#define SDM120C_FREQUENCY                   0x0046                              //Hz
#define SDM120C_IMPORT_ACTIVE_ENERGY        0x0048                              //Wh
#define SDM120C_EXPORT_ACTIVE_ENERGY        0x004A                              //Wh
#define SDM120C_TOTAL_ACTIVE_ENERGY         0x0156                              //Wh
//SDM 220 registers
#define SDM220T_VOLTAGE                     0x0000                              //V
#define SDM220T_CURRENT                     0x0006                              //A
#define SDM220T_POWER                       0x000C                              //W
#define SDM220T_ACTIVE_APPARENT_POWER       0x0012                              //VA
#define SDM220T_REACTIVE_APPARENT_POWER     0x0018                              //VAR
#define SDM220T_POWER_FACTOR                0x001E                              //
#define SDM220T_PHASE_ANGLE                 0x0024                              //DEGREE
#define SDM220T_FREQUENCY                   0x0046                              //Hz
#define SDM220T_IMPORT_ACTIVE_ENERGY        0x0048                              //Wh
#define SDM220T_EXPORT_ACTIVE_ENERGY        0x004A                              //Wh
#define SDM220T_IMPORT_REACTIVE_ENERGY      0x004C                              //VARh
#define SDM220T_EXPORT_REACTIVE_ENERGY      0x004E                              //VARh
#define SDM220T_TOTAL_ACTIVE_ENERGY         0x0156                              //Wh
#define SDM220T_TOTAL_REACTIVE_ENERGY       0x0158                              //VARh
//SDM 630 registers
#define SDM630_VOLTAGE1                     0x0000                              //V
#define SDM630_VOLTAGE2                     0x0002                              //V
#define SDM630_VOLTAGE3                     0x0004                              //V
#define SDM630_CURRENT1                     0x0006                              //A
#define SDM630_CURRENT2                     0x0008                              //A
#define SDM630_CURRENT3                     0x000A                              //A
#define SDM630_CURRENTSUM                   0x0030                              //A
#define SDM630_POWER1                       0x000C                              //W
#define SDM630_POWER2                       0x000E                              //W
#define SDM630_POWER3                       0x0010                              //W
#define SDM630_POWERTOTAL                   0x0034                              //W
#define SDM630_VOLT_AMPS1                   0x0012                              //VA
#define SDM630_VOLT_AMPS2                   0x0014                              //VA
#define SDM630_VOLT_AMPS3                   0x0016                              //VA
#define SDM630_VOLT_AMPS_TOTAL              0x0038                              //VA
#define SDM630_VOLT_AMPS_REACTIVE1          0x0018                              //VAr
#define SDM630_VOLT_AMPS_REACTIVE2          0x001A                              //VAr
#define SDM630_VOLT_AMPS_REACTIVE3          0x001C                              //VAr
#define SDM630_VOLT_AMPS_REACTIVE_TOTAL     0x003C                              //VAr
#define SDM630_POWER_FACTOR1                0x001E
#define SDM630_POWER_FACTOR2                0x0020
#define SDM630_POWER_FACTOR3                0x0022
#define SDM630_POWER_FACTOR_TOTAL           0x003E
#define SDM630_PHASE_ANGLE1                 0x0024                              //Degrees
#define SDM630_PHASE_ANGLE2                 0x0026                              //Degrees
#define SDM630_PHASE_ANGLE3                 0x0028                              //Degrees
#define SDM630_PHASE_ANGLE_TOTAL            0x0042                              //Degrees
#define SDM630_VOLTAGE_AVERAGE              0x002A                              //V
#define SDM630_CURRENT_AVERAGE              0x002E                              //A
#define SDM630_FREQUENCY                    0x0046                              //HZ
#define SDM630_IMPORT_ACTIVE_ENERGY         0x0048                              //Wh
#define SDM630_EXPORT_ACTIVE_ENERGY         0x004A                              //Wh
#define SDM630_IMPORT_REACTIVE_ENERGY       0x004C                              //VARh
#define SDM630_EXPORT_REACTIVE_ENERGY       0x004E                              //VARh
#define SDM630_TOTAL_SYSTEM_POWER_DEMAND    0x0054                              //W
#define SDM630_MAXIMUM_TOTAL_SYSTEM_POWER   0x0056                              //W

#define SDM_B_05                            0x00                                //BYTE 5
#define SDM_B_06                            0x02                                //BYTE 6
//------------------------------------------------------------------------------
#define SDM_ERR_NO_ERROR                    0                                   //no error
#define SDM_ERR_CRC_ERROR                   1                                   //crc error
#define SDM_ERR_WRONG_BYTES                 2                                   //bytes b0,b1 or b2 wrong
#define SDM_ERR_NOT_ENOUGHT_BYTES           3                                   //not enough bytes from sdm
#define SDM_ERR_TIMEOUT                     4                                   //timeout
//------------------------------------------------------------------------------
#if !defined ( USE_HARDWARESERIAL )
template <long _speed = SDM_BAUD, int _rx_pin = SDMSER_RX_PIN, int _tx_pin = SDMSER_TX_PIN, int _dere_pin = DERE_PIN>
#else
template <long _speed = SDM_BAUD, int _dere_pin = DERE_PIN, bool _swapuart = SWAPHWSERIAL>
#endif
struct SDM {

#if !defined ( USE_HARDWARESERIAL )
#if defined ( ESP8266 )
  SoftwareSerial sdmSer = SoftwareSerial(_rx_pin, _tx_pin, false, 32);          //for esp8266 SoftwareSerial (https://github.com/plerup/espsoftwareserial)
#else
  SoftwareSerial sdmSer = SoftwareSerial(_rx_pin, _tx_pin);                     //for standard avr SoftwareSerial library
#endif
#else
#if defined ( ESP8266 )
  HardwareSerial sdmSer = HardwareSerial(0);
#else
  #error Hardware Serial option available only for ESP8266.
#endif
#endif

  private:

    uint16_t readingerrcode = SDM_ERR_NO_ERROR;                                 //4 = timeout; 3 = not enough bytes; 2 = number of bytes OK but bytes b0,b1 or b2 wrong, 1 = crc error
    uint16_t readingerrcount = 0;                                               //total errors couter 

    uint16_t calculateCRC(uint8_t *array, uint8_t num) {
      uint16_t temp, flag;
      temp = 0xFFFF;
      for (uint8_t i = 0; i < num; i++) {
        temp = temp ^ array[i];
        for (uint8_t j = 8; j; j--) {
          flag = temp & 0x0001;
          temp >>= 1;
          if (flag)
            temp ^= 0xA001;
        }
      }
      return temp;
    };

  public:

    void clearErrCode() {                                                       //clear last errorcode 
      readingerrcode = SDM_ERR_NO_ERROR;
    };

    void clearErrCount() {                                                      //clear total errors count 
      readingerrcount = 0;
    };

    uint16_t getErrCode(bool _clear = false) {                                  //return last errorcode (optional clear this value, default flase)
      uint16_t _tmp = readingerrcode;
      if (_clear == true)
        clearErrCode();
      return (_tmp);
    };

    uint16_t getErrCount(bool _clear = false) {                                 //return total errors count (optional clear this value, default flase)
      uint16_t _tmp = readingerrcount;
      if (_clear == true)
        clearErrCount();
      return (_tmp);
    };

    void begin() {
      sdmSer.begin(_speed);
#if defined ( USE_HARDWARESERIAL )
      if (_swapuart)
        sdmSer.swap();
#endif
      if (_dere_pin != NOT_A_PIN)                                               //set output pin mode for DE/RE pin when used (for control MAX485)
        pinMode(_dere_pin, OUTPUT);
    };

    float readVal(uint16_t reg, uint8_t node = SDM_B_01) {                      //read value from register = reg and from deviceId = node
      uint16_t temp;
      unsigned long resptime;
      uint8_t sdmarr[FRAMESIZE] = {node, SDM_B_02, 0, 0, SDM_B_05, SDM_B_06, 0, 0, 0};
      float res = NAN;
      uint16_t readErr = SDM_ERR_NO_ERROR;

      sdmarr[2] = highByte(reg);
      sdmarr[3] = lowByte(reg);

      temp = calculateCRC(sdmarr, FRAMESIZE - 3);                               //calculate out crc only from first 6 bytes

      sdmarr[6] = lowByte(temp);
      sdmarr[7] = highByte(temp);

#if !defined ( USE_HARDWARESERIAL )
      sdmSer.listen();                                                          //enable softserial rx interrupt
#endif

      while (sdmSer.available() > 0)  {                                         //read serial if any old data is available
        sdmSer.read();
      }

      if (_dere_pin != NOT_A_PIN)                                               //transmit to SDM  -> DE Enable, /RE Disable (for control MAX485)
        digitalWrite(_dere_pin, HIGH);

      delay(2);                                                                 //fix for issue (nan reading) by sjfaustino: https://github.com/reaper7/SDM_Energy_Meter/issues/7#issuecomment-272111524

      sdmSer.write(sdmarr, FRAMESIZE - 1);                                      //send 8 bytes

      sdmSer.flush();                                                           //clear out tx buffer

      if (_dere_pin != NOT_A_PIN)                                               //receive from SDM -> DE Disable, /RE Enable (for control MAX485)
        digitalWrite(_dere_pin, LOW);

      resptime = millis() + MAX_MILLIS_TO_WAIT;

      while (sdmSer.available() < FRAMESIZE) {
        if (resptime < millis()) {
          readErr = SDM_ERR_TIMEOUT;                                            //err debug (4)
          break;
        }
        yield();
      }

      if (readErr == SDM_ERR_NO_ERROR) {                                        //if no timeout...

        if(sdmSer.available() == FRAMESIZE) {
          for(int n=0; n<FRAMESIZE; n++) {
            sdmarr[n] = sdmSer.read();
          }

          if (sdmarr[0] == node && sdmarr[1] == SDM_B_02 && sdmarr[2] == SDM_REPLY_BYTE_COUNT) {

            if ((calculateCRC(sdmarr, FRAMESIZE - 2)) == ((sdmarr[8] << 8) | sdmarr[7])) {  //calculate crc from first 7 bytes and compare with received crc (bytes 7 & 8)
              ((uint8_t*)&res)[3]= sdmarr[3];
              ((uint8_t*)&res)[2]= sdmarr[4];
              ((uint8_t*)&res)[1]= sdmarr[5];
              ((uint8_t*)&res)[0]= sdmarr[6];
            } else {
              readErr = SDM_ERR_CRC_ERROR;                                      //err debug (1)
            }
          } else {
            readErr = SDM_ERR_WRONG_BYTES;                                      //err debug (2)
          }
        } else {
          readErr = SDM_ERR_NOT_ENOUGHT_BYTES;                                  //err debug (3)
        }
      }

      if (readErr != SDM_ERR_NO_ERROR) {                                        //if error then copy temp error value to global val and increment global error counter
        readingerrcode = readErr;
        readingerrcount++; 
      }

#if !defined ( USE_HARDWARESERIAL )
      sdmSer.end();                                                             //disable softserial rx interrupt
#endif

      return (res);
    };

};
#endif

(Nuno Figueiredo) #49

no home assistant esta como estava aqui,

###############Medidor Energia##################
#### READINGS

  - platform: mqtt
    state_topic: 'sdm120/volt'
    name: 'Voltagem'
    unit_of_measurement: "V"
    icon: mdi:speedometer

  - platform: mqtt
    state_topic: 'sdm120/curr'
    name: 'Corrente'
    unit_of_measurement: "A"                   
    icon: mdi:speedometer

  - platform: mqtt
    state_topic: 'sdm120/pow'
    name: "Potência (W)"
    unit_of_measurement: "W"             
    icon: mdi:speedometer

  - platform: mqtt
    state_topic: 'sdm120/act_app_pow'
    name: 'Active apparent power'
    unit_of_measurement: "VA"
    icon: mdi:speedometer
  
  - platform: mqtt
    state_topic: 'sdm120/react_app_pow'
    name: 'Reactive apparent power'
    unit_of_measurement: "VAR"
    icon: mdi:speedometer

  - platform: mqtt
    state_topic: 'sdm120/pow_factor'
    name: 'Factor Power'
    unit_of_measurement: ""
    icon: mdi:speedometer

  - platform: mqtt
    state_topic: 'sdm120/freq'
    name: 'Frequencia'
    unit_of_measurement: "HZ"
    icon: mdi:speedometer

  - platform: mqtt
    state_topic: 'sdm120/phase_angle'
    name: 'Phase Angle'
    unit_of_measurement: "Degree"
    icon: mdi:speedometer
    
  - platform: mqtt
    state_topic: 'sdm120/tot_act_en'
    name: 'Total active energy'
    unit_of_measurement: "Wh"
    icon: mdi:speedometer

  - platform: mqtt
    state_topic: 'sdm120/tot_react_en'
    name: 'Total reactive energy'
    unit_of_measurement: "Wh"                              
    icon: mdi:speedometer
  
  - platform: mqtt
    state_topic: 'sdm120/import_act_en'
    name: 'Import active energy'
    unit_of_measurement: "Wh"                              
    icon: mdi:speedometer
  
  - platform: mqtt
    state_topic: 'sdm120/export_act_en'
    name: 'Export active energy'
    unit_of_measurement: "Wh"                              
    icon: mdi:speedometer
  
  - platform: mqtt
    state_topic: 'sdm120/import_react_en'
    name: 'Import reactive energy'
    unit_of_measurement: "VARh"                              
    icon: mdi:speedometer
  
  - platform: mqtt
    state_topic: 'sdm120/export_react_en'
    name: 'Export reactive energy'
    unit_of_measurement: "VARh"                              
    icon: mdi:speedometer

(Frederico Oliveira) #50

Resumindo o que tenho de alterar para activar o pino 4 é isto?
//or without parameters (default from SDM.h will be used):
SDM<2400, 12, 13, 4> sdm
Eu uso o weemos, então o gpio4 corresponde ao D…?


(Rodolfo) #51


(Nuno Figueiredo) #52

desculpa frederico, eu ainda ando a tentar perceber os gpios no arduino ide, o D2 corresponde ao pin 4 no arduino ide, e chego aqui e termino, nao sei mais :smiley:


(Nuno Figueiredo) #53

obrigado, ja esclarece :slight_smile:

será que o problema de perder o wifi esta na libraria? estou a usar o arduino ide que estava neste post.
o mesmo nodemcu com tasmota nao perde ligação.


(Jorge Assunção) #54

mas o meu código do HA faz isso. E publica os valores por MQTT com retain para se reiniciares a placa ele vai ler o valor ao arrancar.


(Frederico Oliveira) #55

Falas do retain last state? Como o fizeste?


(Nuno Figueiredo) #56

bem tentei compilar com as mais recentes librarias do esp e o nodemcu funciona bem, mas passado 2 comunicações perde a ligação ao MQTT, estou a tentar resolver o problema da perda de wireless ao usar as novas librarias, sem sucesso :S
os craques do arduino ide que ajudem :smiley:


(Frederico Oliveira) #57

Eu com a adicão do 3o fio consegui comunicação e estou neste momento a editar para ter tensao, frequencia e afins em tempo real. Um muito obrigado ao @Nuno_Figueiredo pela grande ajuda.
Eu estou a usar um conversor desses e um weemos d1 mini para os que queiram saber se funcionam


(Nuno Figueiredo) #58

partilha cmg depois se perdes ligação com o tempo e aleatoriamente, é o meu dilema de momento :\


(Frederico Oliveira) #59

O meu tá a comunicar mas como volta e meia ainda ando a fazer reboots e afins não posso propriamente ver se está a cair ou não.
Estás a usar o nodemcu ou weemos?


(Nuno Figueiredo) #60

nodemcu, mas ja testei 3, e nao é do nodemcu, deve ser mesmo algo do codigo, ha arranjei outro codigo, mas tenho de estudar para poder publicar no HA.
vou reportando news se as existir :smiley:


(Frederico Oliveira) #61

É isso eu pelo meu lado vou testar no weemos e depois dou feedback.
Não vale a pena testar no meu luamcu se dizes que já testaste com 3 e o mesmo resultado