Hi
I use it to get the meter readings and then I use the energy integration in HA. it is 100% accurate so everything in terms of readings and cost is same on the display and HA.
I use the “Current Use” function live on HA dashboard so I can monitor real time usage, this is the same as what is on the display.
Its a USB socket on the back, that outputs this data in serial but its very disorganised and difficult to capture. I then send these values as MQTT message payloads.
What pictures would u like?
Code is attached. Code is ugly, unformatted and messy but does work. Its hard to capture the data because the beginning of the hex strings spewing out of the IHD often change and jump around and so do their start positions. Someone who can code better than me could make it work im sure.
The USB cable has the serial lines on it (rs232) in a serial plug form.
You’d have to change ur MQTT server IP and WiFi etc
//byte byteOne = 0xFF;
//byte byteTwo = 0xFF;
//byte byteThree = 0xFF;
//byte byteFour = 0xFF;
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
const char* ssid = "xxxxxx";
const char* password = "xxxxxxx";
const char* mqtt_server = "192.168.0.31";
WiFiClient espClient;
PubSubClient client(espClient);
long now = millis();
long lastMeasure = 0;
long readingFilter = 999999999;
long lastdayUsage = 0;
long lastmeterReadingone = 0;
byte byteCheck[150];
byte mreadingData[8];
byte dailyData [4];
byte currentData[4];
char msg1[50];
char msg2[50];
char msg3[50];
// Don't change the function below. This functions connects your ESP8266 to your router
void setup_wifi() {
delay(10);
// 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.print("WiFi connected - ESP IP address: ");
Serial.println(WiFi.localIP());
}
void reconnect() {
// Loop until we're reconnected;
while (!client.connected()) {
Serial.print("MQTT connect..");
// Create a random client ID
String clientId = "ESP8266Client-";
clientId += String(random(0xffff), HEX);
// Attempt to connect
if (client.connect(clientId.c_str())) {
Serial.print("connected");
Serial.print("connected");
Serial.print("connected");
Serial.print("connected");
// Once connected, publish an announcement...
// client.publish("energy/meterread", "hello world");
// ... and resubscribe
//client.subscribe("inTopic");
} else {
Serial.print("failed. Retry.");
//Serial.print(client.state());
//Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void setup() {
setup_wifi();
client.setServer(mqtt_server, 1883);
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("This is a test");
}
void loop() {
// put your main code here, to run repeatedly:
if (!client.connected()) {
reconnect();
}
client.loop();
if (Serial.available() > 0) {
for (int i = 0; i < 150; i++) { //Read
byteCheck[i] = Serial.read();
delay(10);
Serial.println(byteCheck[i], HEX);
Serial.println(i);
// Serial.println("Beginning");
}
// Meter Reading
if (byteCheck[90] == 0x00 && byteCheck[91] == 0x00 && byteCheck[92] == 0x25) {
Serial.print("Got Meter Reading Header");
// Serial.println(byteCheck[29], HEX);
// Serial.println(byteCheck[30], HEX);
// Serial.println(byteCheck[31], HEX);
// Serial.println(byteCheck[32], HEX);
// Serial.println(byteCheck[33], HEX);
long meterReadingone = (byteCheck[96] << 24) + (byteCheck[95] << 16) + (byteCheck[94] << 8) + (byteCheck[93]);
Serial.println(meterReadingone, HEX);
Serial.println(meterReadingone, DEC);
Serial.flush();
if((meterReadingone <= readingFilter) && (meterReadingone > lastmeterReadingone)){
sprintf(msg1,"%u",(meterReadingone));
client.publish("energy/meterread", msg1);
lastmeterReadingone = meterReadingone;
}
}
//
if (byteCheck[89] == 0x00 && byteCheck[90] == 0x00 && byteCheck[91] == 0x25) {
Serial.print("Got Meter Reading Header");
// Serial.println(byteCheck[29], HEX);
// Serial.println(byteCheck[30], HEX);
// Serial.println(byteCheck[31], HEX);
// Serial.println(byteCheck[32], HEX);
// Serial.println(byteCheck[33], HEX);
long meterReadingone = (byteCheck[95] << 24) + (byteCheck[94] << 16) + (byteCheck[93] << 8) + (byteCheck[92]);
Serial.println(meterReadingone, HEX);
Serial.println(meterReadingone, DEC);
Serial.flush();
if((meterReadingone <= readingFilter) && (meterReadingone > lastmeterReadingone)){
sprintf(msg1,"%u",(meterReadingone));
client.publish("energy/meterread", msg1);
lastmeterReadingone = meterReadingone;
}
}
// // Daily Use
if (byteCheck[100] == 0x00 && byteCheck[101] == 0x22){
Serial.println("Got Daily Usage");
// Serial.println(byteCheck[6], HEX);
// Serial.println(byteCheck[7], HEX);
long dayUsage = (byteCheck[103] << 8) + (byteCheck[102]);
Serial.println(byteCheck[103], HEX);
Serial.println(byteCheck[102], HEX);
Serial.println(dayUsage, HEX);
Serial.println(dayUsage, DEC);
Serial.flush();
if((dayUsage >= lastdayUsage) || (dayUsage <= 100)){
sprintf(msg2,"%u",(dayUsage));
client.publish("energy/dayuse", msg2);
lastdayUsage = dayUsage;
}
}
if (byteCheck[101] == 0x00 && byteCheck[102] == 0x22){
Serial.println("Got Daily Usage");
// Serial.println(byteCheck[6], HEX);
// Serial.println(byteCheck[7], HEX);
long dayUsage = (byteCheck[104] << 8) + (byteCheck[103]);
Serial.println(byteCheck[103], HEX);
Serial.println(byteCheck[102], HEX);
Serial.println(dayUsage, HEX);
Serial.println(dayUsage, DEC);
Serial.flush();
if((dayUsage >= lastdayUsage) || (dayUsage <= 100)){
sprintf(msg2,"%u",(dayUsage));
client.publish("energy/dayuse", msg2);
lastdayUsage = dayUsage;
}
// sprintf(msg2,"%u",(dayUsage));
// client.publish("energy/dayuse", msg2);
}
// Current Use
if (byteCheck[27] == 0x00 && byteCheck[28] == 0x2a) {
// for(int j = 24; j < 27; j++){
// currentData[j] = Serial.read();
// }
Serial.println("Got Current Usage");
// Serial.println(byteCheck[24], HEX);
// Serial.println(byteCheck[25], HEX);
// Serial.println(byteCheck[26], HEX);
// Serial.println(byteCheck[27], HEX);
// Serial.println(byteCheck[28], HEX);
// Serial.println(byteCheck[27]+byteCheck[28], HEX);
// Serial.println(byteCheck[27]+byteCheck[28], DEC);
long currentUsedec = (byteCheck[30] << 8) + byteCheck[29];
// Serial.println(byteCheck[30]);
// Serial.println(byteCheck[29]);
Serial.println(currentUsedec);
Serial.flush();
if(currentUsedec > 0){
sprintf(msg3,"%u",(currentUsedec));
client.publish("energy/current", msg3);
}
}
}
//Serial.flush();
}