mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 04:36:31 +00:00
Add Energy Export Active support to BL0906 (Athom EM2/EM6)
This commit is contained in:
parent
692a0ca4b1
commit
452031fbbd
@ -86,6 +86,7 @@ typedef struct {
|
|||||||
float import_active[ENERGY_MAX_PHASES]; // 123.123 kWh
|
float import_active[ENERGY_MAX_PHASES]; // 123.123 kWh
|
||||||
float export_active[ENERGY_MAX_PHASES]; // 123.123 kWh
|
float export_active[ENERGY_MAX_PHASES]; // 123.123 kWh
|
||||||
float start_energy[ENERGY_MAX_PHASES]; // 12345.12345 kWh total previous
|
float start_energy[ENERGY_MAX_PHASES]; // 12345.12345 kWh total previous
|
||||||
|
float start_export_energy[ENERGY_MAX_PHASES]; // 12345.12345 kWh total previous
|
||||||
float daily[ENERGY_MAX_PHASES]; // 123.123 kWh
|
float daily[ENERGY_MAX_PHASES]; // 123.123 kWh
|
||||||
float total[ENERGY_MAX_PHASES]; // 12345.12345 kWh total energy
|
float total[ENERGY_MAX_PHASES]; // 12345.12345 kWh total energy
|
||||||
float daily_sum; // 123.123 kWh
|
float daily_sum; // 123.123 kWh
|
||||||
@ -357,10 +358,15 @@ void EnergyUpdateTotal(void) {
|
|||||||
|
|
||||||
if (0 == Energy->start_energy[i] || (Energy->import_active[i] < Energy->start_energy[i])) {
|
if (0 == Energy->start_energy[i] || (Energy->import_active[i] < Energy->start_energy[i])) {
|
||||||
Energy->start_energy[i] = Energy->import_active[i]; // Init after restart and handle roll-over if any
|
Energy->start_energy[i] = Energy->import_active[i]; // Init after restart and handle roll-over if any
|
||||||
|
Energy->start_export_energy[i] = (float)(RtcSettings.energy_kWhexport_ph[i]) / 1000; // Init after restart
|
||||||
}
|
}
|
||||||
else if (Energy->import_active[i] != Energy->start_energy[i]) {
|
else if (Energy->import_active[i] != Energy->start_energy[i]) {
|
||||||
|
if (Energy->local_energy_active_export && (Energy->active_power[i] < 0)) {
|
||||||
|
RtcSettings.energy_kWhexport_ph[i] = (int32_t)((Energy->start_export_energy[i] + Energy->import_active[i] - Energy->start_energy[i]) * 1000);
|
||||||
|
} else {
|
||||||
Energy->kWhtoday[i] = (int32_t)((Energy->import_active[i] - Energy->start_energy[i]) * 100000);
|
Energy->kWhtoday[i] = (int32_t)((Energy->import_active[i] - Energy->start_energy[i]) * 100000);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((Energy->total[i] < (Energy->import_active[i] - 0.01f)) && // We subtract a little offset of 10Wh to avoid continuous updates
|
if ((Energy->total[i] < (Energy->import_active[i] - 0.01f)) && // We subtract a little offset of 10Wh to avoid continuous updates
|
||||||
Settings->flag3.hardware_energy_total) { // SetOption72 - Enable hardware energy total counter as reference (#6561)
|
Settings->flag3.hardware_energy_total) { // SetOption72 - Enable hardware energy total counter as reference (#6561)
|
||||||
@ -779,13 +785,18 @@ void CmndEnergyToday(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CmndEnergyExportActive(void) {
|
void CmndEnergyExportActive(void) {
|
||||||
if (Energy->local_energy_active_export) {
|
// EnergyExportActive 0 - Disable local energy_active_export support
|
||||||
// EnergyExportActive1 24
|
// EnergyExportActive 1 - Enable local energy_active_export support
|
||||||
// EnergyExportActive1 24,1650111291
|
|
||||||
uint32_t values[2] = { 0 };
|
uint32_t values[2] = { 0 };
|
||||||
uint32_t params = ParseParameters(2, values);
|
uint32_t params = ParseParameters(2, values);
|
||||||
|
|
||||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= Energy->phase_count) && (params > 0)) {
|
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= Energy->phase_count) && (params > 0)) {
|
||||||
|
if (!XdrvMailbox.usridx) {
|
||||||
|
Energy->local_energy_active_export = values[0] &1;
|
||||||
|
}
|
||||||
|
else if (Energy->local_energy_active_export) {
|
||||||
|
// EnergyExportActive1 24
|
||||||
|
// EnergyExportActive1 24,1650111291
|
||||||
uint32_t phase = XdrvMailbox.index -1;
|
uint32_t phase = XdrvMailbox.index -1;
|
||||||
// Reset Energy Export Active
|
// Reset Energy Export Active
|
||||||
RtcSettings.energy_kWhexport_ph[phase] = (int32_t)values[0];
|
RtcSettings.energy_kWhexport_ph[phase] = (int32_t)values[0];
|
||||||
@ -794,7 +805,12 @@ void CmndEnergyExportActive(void) {
|
|||||||
Settings->energy_kWhtotal_time = values[1];
|
Settings->energy_kWhtotal_time = values[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (Energy->local_energy_active_export) {
|
||||||
ResponseCmndEnergyTotalYesterdayToday();
|
ResponseCmndEnergyTotalYesterdayToday();
|
||||||
|
} else {
|
||||||
|
Energy->export_active[0] = NAN; // Disable display of unused export_active
|
||||||
|
ResponseCmndStateText(Energy->local_energy_active_export);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,6 +163,7 @@ typedef struct {
|
|||||||
float import_active[ENERGY_MAX_PHASES]; // 123.123 kWh
|
float import_active[ENERGY_MAX_PHASES]; // 123.123 kWh
|
||||||
float export_active[ENERGY_MAX_PHASES]; // 123.123 kWh
|
float export_active[ENERGY_MAX_PHASES]; // 123.123 kWh
|
||||||
float start_energy[ENERGY_MAX_PHASES]; // 12345.12345 kWh total previous
|
float start_energy[ENERGY_MAX_PHASES]; // 12345.12345 kWh total previous
|
||||||
|
float start_export_energy[ENERGY_MAX_PHASES]; // 12345.12345 kWh total previous
|
||||||
float total[ENERGY_MAX_PHASES]; // 12345.12345 kWh total energy
|
float total[ENERGY_MAX_PHASES]; // 12345.12345 kWh total energy
|
||||||
float daily_sum; // 123.123 kWh
|
float daily_sum; // 123.123 kWh
|
||||||
float total_sum; // 12345.12345 kWh total energy
|
float total_sum; // 12345.12345 kWh total energy
|
||||||
@ -613,10 +614,15 @@ void EnergyUpdateTotal(void) {
|
|||||||
|
|
||||||
if (0 == Energy->start_energy[i] || (Energy->import_active[i] < Energy->start_energy[i])) {
|
if (0 == Energy->start_energy[i] || (Energy->import_active[i] < Energy->start_energy[i])) {
|
||||||
Energy->start_energy[i] = Energy->import_active[i]; // Init after restart and handle roll-over if any
|
Energy->start_energy[i] = Energy->import_active[i]; // Init after restart and handle roll-over if any
|
||||||
|
Energy->start_export_energy[i] = RtcEnergySettings.energy_export_kWh[i]; // Init after restart
|
||||||
}
|
}
|
||||||
else if (Energy->import_active[i] != Energy->start_energy[i]) {
|
else if (Energy->import_active[i] != Energy->start_energy[i]) {
|
||||||
|
if (Energy->local_energy_active_export && (Energy->active_power[i] < 0)) {
|
||||||
|
RtcEnergySettings.energy_export_kWh[i] = Energy->start_export_energy[i] + Energy->import_active[i] - Energy->start_energy[i];
|
||||||
|
} else {
|
||||||
Energy->kWhtoday[i] = (int32_t)((Energy->import_active[i] - Energy->start_energy[i]) * 100000);
|
Energy->kWhtoday[i] = (int32_t)((Energy->import_active[i] - Energy->start_energy[i]) * 100000);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((Energy->total[i] < (Energy->import_active[i] - 0.01f)) && // We subtract a little offset of 10Wh to avoid continuous updates
|
if ((Energy->total[i] < (Energy->import_active[i] - 0.01f)) && // We subtract a little offset of 10Wh to avoid continuous updates
|
||||||
Settings->flag3.hardware_energy_total) { // SetOption72 - Enable hardware energy total counter as reference (#6561)
|
Settings->flag3.hardware_energy_total) { // SetOption72 - Enable hardware energy total counter as reference (#6561)
|
||||||
@ -1095,13 +1101,18 @@ void CmndEnergyToday(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CmndEnergyExportActive(void) {
|
void CmndEnergyExportActive(void) {
|
||||||
if (Energy->local_energy_active_export) {
|
// EnergyExportActive 0 - Disable local energy_active_export support
|
||||||
// EnergyExportActive1 24
|
// EnergyExportActive 1 - Enable local energy_active_export support
|
||||||
// EnergyExportActive1 24,1650111291
|
|
||||||
uint32_t values[2] = { 0 };
|
uint32_t values[2] = { 0 };
|
||||||
uint32_t params = ParseParameters(2, values);
|
uint32_t params = ParseParameters(2, values);
|
||||||
|
|
||||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= Energy->phase_count) && (params > 0)) {
|
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= Energy->phase_count) && (params > 0)) {
|
||||||
|
if (!XdrvMailbox.usridx) {
|
||||||
|
Energy->local_energy_active_export = values[0] &1;
|
||||||
|
}
|
||||||
|
else if (Energy->local_energy_active_export) {
|
||||||
|
// EnergyExportActive1 24
|
||||||
|
// EnergyExportActive1 24,1650111291
|
||||||
uint32_t phase = XdrvMailbox.index -1;
|
uint32_t phase = XdrvMailbox.index -1;
|
||||||
// Reset Energy Export Active
|
// Reset Energy Export Active
|
||||||
RtcEnergySettings.energy_export_kWh[phase] = (float)(int32_t)values[0] / 1000;
|
RtcEnergySettings.energy_export_kWh[phase] = (float)(int32_t)values[0] / 1000;
|
||||||
@ -1110,7 +1121,12 @@ void CmndEnergyExportActive(void) {
|
|||||||
Energy->Settings.energy_kWhtotal_time = values[1];
|
Energy->Settings.energy_kWhtotal_time = values[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (Energy->local_energy_active_export) {
|
||||||
ResponseCmndEnergyTotalYesterdayToday();
|
ResponseCmndEnergyTotalYesterdayToday();
|
||||||
|
} else {
|
||||||
|
Energy->export_active[0] = NAN; // Disable display of unused export_active
|
||||||
|
ResponseCmndStateText(Energy->local_energy_active_export);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
* SetOption21 1 - Display Voltage
|
* SetOption21 1 - Display Voltage
|
||||||
* SetOption129 1 - Display energy for each phase instead of single sum
|
* SetOption129 1 - Display energy for each phase instead of single sum
|
||||||
* SetOption150 1 - Display no common voltage/frequency
|
* SetOption150 1 - Display no common voltage/frequency
|
||||||
|
* EnergyExportActive 1 - Enable display of Export Active energy based on negative Active Power
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
#define XNRG_24 24
|
#define XNRG_24 24
|
||||||
|
Loading…
x
Reference in New Issue
Block a user