From db4399d89b91b8248edba2f32af332b061517cd6 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 6 Apr 2021 11:09:12 +0200 Subject: [PATCH] Add relay power control emulation Add relay power control emulation (#10640) --- tasmota/xnrg_20_dummy.ino | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/tasmota/xnrg_20_dummy.ino b/tasmota/xnrg_20_dummy.ino index 913067dc5..4787cae21 100644 --- a/tasmota/xnrg_20_dummy.ino +++ b/tasmota/xnrg_20_dummy.ino @@ -20,7 +20,7 @@ #ifdef USE_ENERGY_SENSOR #ifdef USE_ENERGY_DUMMY /*********************************************************************************************\ - * Provides dummy energy monitoring + * Provides dummy energy monitoring for up to three channels based on relay count * * User is supposed to enter valid data for Voltage, Current and Power * Active Power is adjusted to calculated Apparent Power (=U*I) if the latter is smaller than the first @@ -30,7 +30,6 @@ #define XNRG_20 20 -#define NRG_DUMMY_PHASES 1 // 1 to 3 channels as x phases #define NRG_DUMMY_U_COMMON true // Phase voltage = false, Common voltage = true #define NRG_DUMMY_F_COMMON true // Phase frequency = false, Common frequency = true #define NRG_DUMMY_DC false // AC = false, DC = true; @@ -45,17 +44,18 @@ void NrgDummyEverySecond(void) { if (Energy.power_on) { // Powered on float energy = 0; - uint32_t max_channel = (NRG_DUMMY_PHASES < 4) ? NRG_DUMMY_PHASES : 3; - for (uint32_t channel = 0; channel < max_channel; channel++) { - Energy.data_valid[channel] = 0; + for (uint32_t channel = 0; channel < Energy.phase_count; channel++) { Energy.voltage[channel] = ((float)Settings.energy_voltage_calibration / 100); // V Energy.frequency[channel] = ((float)Settings.energy_frequency_calibration / 100); // Hz - Energy.active_power[channel] = ((float)Settings.energy_power_calibration / 100); // W - if (0 == Energy.active_power[channel]) { - Energy.current[channel] = 0; - } else { - Energy.current[channel] = ((float)Settings.energy_current_calibration / 100000); // A - energy += Energy.active_power[channel]; + if (bitRead(TasmotaGlobal.power, channel)) { // Emulate power read only if device is powered on + Energy.active_power[channel] = ((float)Settings.energy_power_calibration / 100); // W + if (0 == Energy.active_power[channel]) { + Energy.current[channel] = 0; + } else { + Energy.current[channel] = ((float)Settings.energy_current_calibration / 100000); // A + energy += Energy.active_power[channel]; + } + Energy.data_valid[channel] = 0; } } @@ -113,10 +113,10 @@ void NrgDummyDrvInit(void) { Settings.energy_power_calibration = NRG_DUMMY_PREF; } - Energy.type_dc = NRG_DUMMY_DC; // AC = false, DC = true; - Energy.phase_count = NRG_DUMMY_PHASES; // 1 to 3 channels as x phases + Energy.phase_count = (TasmotaGlobal.devices_present < 3) ? TasmotaGlobal.devices_present : 3; Energy.voltage_common = NRG_DUMMY_U_COMMON; // Phase voltage = false, Common voltage = true Energy.frequency_common = NRG_DUMMY_F_COMMON; // Phase frequency = false, Common frequency = true + Energy.type_dc = NRG_DUMMY_DC; // AC = false, DC = true; TasmotaGlobal.energy_driver = XNRG_20; }