Power Sensor Guidance

Looking for some guidance around if its possible to set up an energy sensor to work with OH2

i have picked up a few parts hoping a could get this working and have already hit a wall

equipment i was looking at using
Current Transformer AC current sensor 100A SCT-013-000
ESP8266 Mains Power Sensor
Wemos D1 Mini

as set up in the link - ESP8266 Mains Power Sensor by Dimwit-Dave - Thingiverse

i normal content a sensor with Esp easy and use MQTT however cant this time so found this code but the is no way to add user name and password for my MQTT Broker?

/* Connection detials for WiFi and board functions

// Select Static IP Mode, uncomment below to enable
//#define STATIC_IP
IPAddress ip(192, 168, 1, 33);
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 255, 0);

// Add your Wifi details below
const char* SSID_1 = "AP";
const char* Password_1 = "Password";

const char* SSID_2 = "AP";
const char* Password_2 = "Password";

const char* SSID_3 = "AP";
const char* Password_3 = "Password";

const char* SSID_4 = "AP";
const char* Password_4 = "Password";

// MQTT Broker
const char* mqtt_server = "";
// MQTT Topics
const char* InStatus = "Power/Status";
const char* InControl = "Power/Control";
String Broadcast_All = "*ALL";                    // Message used to broadcast to all devices subscribed to above topic

// Heatbeat items
#define Heartbeat_Range   99                      // Event count max value
#define Heatbeat    1000                         // Heartbeat timer value, in mS

// Watchdog items
volatile int Watchdog_Timout = 1200;              // Time in seconds before watchdog times out, 1200 = 1200 seconds or 20 minutes

// Heatbeat timer
int Heart_Value = 0;                              // Timer
long LastMsg = 0;                                 // Message sent counter

// Custom default values
String WiFi_SSID = "None";                        // SSID string
String My_MAC = "";                               // MAC address, tobe Read from ESP8266
char MAC_array[13] = "000000000000";              // Better MAC definition
//String Mode = "Off";                            // Default mode
volatile int Report_Request = 0;                  // Set to 1 if report required
String Event = "Boot";                            // Default

// I/O
#define Status_LED 2                              // D4
#define Status_LED_On   digitalWrite(Status_LED, HIGH)
#define Status_LED_Off  digitalWrite(Status_LED, LOW)

// Power monitor items
double Calib = 1;//10.545662
double Kilos;
unsigned long StartMillis;
unsigned long EndMillis;
double RMSCurrent;
int RMSPower;
int PeakPower;

void ReadPower ()      // Method to read information from CTs
  int Current = 0;
  int MaxCurrent = 0;
  int MinCurrent = 1023;
  int PeakCurrent = 0;

  // Needs to sample for at least one and half mains cycles or > 30mS
  for (int j = 0 ; j <= 600 ; j++)

    //         digitalWrite(D8, HIGH);
    Current =  analogRead(A0);    //Reads A/D input and records maximum and minimum current
    //        digitalWrite(D8, LOW);

    if (Current >= MaxCurrent)
      MaxCurrent = Current;

    if (Current <= MinCurrent)
      MinCurrent = Current;
  } // End of samples loop

  PeakCurrent = MaxCurrent - MinCurrent;

RMSCurrent = PeakCurrent;

 // http://www.referencedesigner.com/rfcal/vrms-to-vpeak-conversion.php
 // RMSCurrent = (PeakCurrent * 0.3535) / Calib; //Calculates RMS current based on maximum value and scales according to calibration
 // RMSPower = 248 * RMSCurrent;  //Calculates RMS Power Assuming Voltage 240VAC, change to 110VAC accordingly

} // End of function

full code here GitHub - Mottramlabs/MQTT-Power-Sensor

can anyone give me any advise or other way to do this as i have been researching for a few days and still haven’t got an answer


This is pretty much well outside the scope of openHAB so you will likely find your answer on some other forum.

A quick scan of the code shows it to be massively incomplete. There are no imports of any MQTT libraries. Nor are any of the variables defined for connecting to the wifi used anywhere. There isn’t a loop function either.

I see sorry for posting this question I thought someone may have completed something similar and been able to offer support. Most of the guides on other sites have no way to link to OH that I can see.

Also sorry for the confusion that was only part of the code to highlight my issue with not having a way to set the password and use for the broker

The full code it in the link here GitHub - Mottramlabs/MQTT-Power-Sensor


Rarely will you find openHAB mentioned on these sorts of tutorials. But if they can use MQTT there’s an add-on for that in openHAB. If they can use HTTP there’s an add-on for that in openHAB.