From b3dc33f3a0d2af634888a53a88b0036d5c2cb6a3 Mon Sep 17 00:00:00 2001 From: Janusz Date: Tue, 18 Aug 2020 22:09:33 +0200 Subject: [PATCH] SDM630 optional import active energy --- tasmota/i18n.h | 1 + tasmota/my_user_config.h | 1 + tasmota/xdrv_03_energy.ino | 31 ++++++++++++++++++++++++++++++- tasmota/xnrg_10_sdm630.ino | 22 +++++++++++++++++++--- 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index a1623fe14..519679b38 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -192,6 +192,7 @@ #define D_JSON_PV2_POWER "Pv2Power" #define D_JSON_SOLAR_POWER "SolarPower" #define D_JSON_USAGE "Usage" +#define D_JSON_IMPORT "Import" #define D_JSON_EXPORT "Export" #define D_JSON_TOTAL_ACTIVE "TotalActive" diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index c1bdcdb79..e8dac6109 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -637,6 +637,7 @@ #define SDM120_SPEED 2400 // SDM120-Modbus RS485 serial speed (default: 2400 baud) //#define USE_SDM630 // Add support for Eastron SDM630-Modbus energy monitor (+0k6 code) #define SDM630_SPEED 9600 // SDM630-Modbus RS485 serial speed (default: 9600 baud) +//#define SDM630_IMPORT // Show import active energy in MQTT and Web (+0k3 code) //#define USE_DDS2382 // Add support for Hiking DDS2382 Modbus energy monitor (+0k6 code) #define DDS2382_SPEED 9600 // Hiking DDS2382 Modbus RS485 serial speed (default: 9600 baud) //#define USE_DDSU666 // Add support for Chint DDSU666 Modbus energy monitor (+0k6 code) diff --git a/tasmota/xdrv_03_energy.ino b/tasmota/xdrv_03_energy.ino index 4d53af77c..9f61960a0 100644 --- a/tasmota/xdrv_03_energy.ino +++ b/tasmota/xdrv_03_energy.ino @@ -80,7 +80,9 @@ struct ENERGY { float power_factor[3] = { NAN, NAN, NAN }; // 0.12 float frequency[3] = { NAN, NAN, NAN }; // 123.1 Hz -// float import_active[3] = { NAN, NAN, NAN }; // 123.123 kWh + #ifdef SDM630_IMPORT + float import_active[3] = { NAN, NAN, NAN }; // 123.123 kWh +#endif float export_active[3] = { NAN, NAN, NAN }; // 123.123 kWh float start_energy = 0; // 12345.12345 kWh total previous @@ -879,6 +881,11 @@ const char HTTP_ENERGY_SNS2[] PROGMEM = const char HTTP_ENERGY_SNS3[] PROGMEM = "{s}" D_EXPORT_ACTIVE "{m}%s " D_UNIT_KILOWATTHOUR "{e}"; + +#ifdef SDM630_IMPORT +const char HTTP_ENERGY_SNS4[] PROGMEM = + "{s}" D_IMPORT_ACTIVE "{m}%s " D_UNIT_KILOWATTHOUR "{e}"; +#endif // SDM630_IMPORT #endif // USE_WEBSERVER char* EnergyFormatIndex(char* result, char* input, bool json, uint32_t index, bool single = false) @@ -966,11 +973,17 @@ void EnergyShow(bool json) char voltage_chr[Energy.phase_count][FLOATSZ]; char current_chr[Energy.phase_count][FLOATSZ]; char active_power_chr[Energy.phase_count][FLOATSZ]; +#ifdef SDM630_IMPORT + char import_active_chr[Energy.phase_count][FLOATSZ]; +#endif char export_active_chr[Energy.phase_count][FLOATSZ]; for (uint32_t i = 0; i < Energy.phase_count; i++) { dtostrfd(Energy.voltage[i], Settings.flag2.voltage_resolution, voltage_chr[i]); dtostrfd(Energy.current[i], Settings.flag2.current_resolution, current_chr[i]); dtostrfd(Energy.active_power[i], Settings.flag2.wattage_resolution, active_power_chr[i]); +#ifdef SDM630_IMPORT + dtostrfd(Energy.import_active[i], Settings.flag2.energy_resolution, import_active_chr[i]); +#endif dtostrfd(Energy.export_active[i], Settings.flag2.energy_resolution, export_active_chr[i]); } @@ -1013,6 +1026,17 @@ void EnergyShow(bool json) energy_yesterday_chr, energy_daily_chr); + #ifdef SDM630_IMPORT + if (!isnan(Energy.import_active[0])) { + ResponseAppend_P(PSTR(",\"" D_JSON_IMPORT_ACTIVE "\":%s"), + EnergyFormat(value_chr, import_active_chr[0], json)); + if (energy_tariff) { + ResponseAppend_P(PSTR(",\"" D_JSON_IMPORT D_CMND_TARIFF "\":%s"), + EnergyFormatIndex(value_chr, energy_return_chr[0], json, 2)); + } + } +#endif + if (!isnan(Energy.export_active[0])) { ResponseAppend_P(PSTR(",\"" D_JSON_EXPORT_ACTIVE "\":%s"), EnergyFormat(value_chr, export_active_chr[0], json)); @@ -1117,6 +1141,11 @@ void EnergyShow(bool json) if (!isnan(Energy.export_active[0])) { WSContentSend_PD(HTTP_ENERGY_SNS3, EnergyFormat(value_chr, export_active_chr[0], json)); } + #ifdef SDM630_IMPORT + if (!isnan(Energy.import_active[0])) { + WSContentSend_PD(HTTP_ENERGY_SNS4, EnergyFormat(value_chr, import_active_chr[0], json)); + } +#endif XnrgCall(FUNC_WEB_SENSOR); #endif // USE_WEBSERVER diff --git a/tasmota/xnrg_10_sdm630.ino b/tasmota/xnrg_10_sdm630.ino index d239c1c73..92b8e98e4 100644 --- a/tasmota/xnrg_10_sdm630.ino +++ b/tasmota/xnrg_10_sdm630.ino @@ -60,9 +60,11 @@ const uint16_t sdm630_start_addresses[] { 0x0160, // + + + kWh Phase 1 export active energy 0x0162, // + + + kWh Phase 2 export active energy 0x0164, // + + + kWh Phase 3 export active energy -// 0x015A, // + + + kWh Phase 1 import active energy -// 0x015C, // + + + kWh Phase 2 import active energy -// 0x015E, // + + + kWh Phase 3 import active energy + #ifdef SDM630_IMPORT + 0x015A, // + + + kWh Phase 1 import active energy + 0x015C, // + + + kWh Phase 2 import active energy + 0x015E, // + + + kWh Phase 3 import active energy +#endif 0x0156 // + + + kWh Total active energy }; @@ -177,6 +179,20 @@ void SDM630Every250ms(void) break; case 19: + #ifdef SDM630_IMPORT + Energy.import_active[0] = value; + break; + + case 20: + Energy.import_active[1] = value; + break; + + case 21: + Energy.import_active[2] = value; + break; + + case 22: +#endif EnergyUpdateTotal(value, true); break; }