Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option in my_user_config.h to turn on SDM630 import active energy #9124

Merged
merged 1 commit into from
Oct 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tasmota/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions tasmota/my_user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this setting depend on USE_SDM630 somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, Tasmota reads multiple ModBus registers from SDM630 but without 0x015A, 0X015C, 0x015E (phase 1, 2 and 3 import active energy). I have been using the extended version that reads these registers for four months now and it works very well. For users who need to read the consumed energy separately for each phase, there is this switch - #SDM630_IMPORT. This works ONLY if the SDM630 is compiled in the firmware as before (tasmota-sensors etc).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I mean, does the code compile if SDM630_IMPORT is defined but USE_SDM630 is not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SDM630_IMPORT work only if USE_SDM630 is defined.

//#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)
Expand Down
31 changes: 30 additions & 1 deletion tasmota/xdrv_03_energy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]);
}

Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand Down
22 changes: 19 additions & 3 deletions tasmota/xnrg_10_sdm630.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down Expand Up @@ -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;
}
Expand Down