Browse Source

Set reported power & current values to 0 if relay is OFF

rfm69
Xose Pérez 6 years ago
parent
commit
2b445ec0b3
3 changed files with 29 additions and 4 deletions
  1. +4
    -0
      code/espurna/config/sensors.h
  2. +25
    -3
      code/espurna/sensor.ino
  3. +0
    -1
      code/platformio.ini

+ 4
- 0
code/espurna/config/sensors.h View File

@ -16,6 +16,10 @@
#define SENSOR_USE_INDEX 0 // Use the index in topic (i.e. temperature/0)
// even if just one sensor (0 for backwards compatibility)
#ifndef SENSOR_POWER_CHECK_STATUS
#define SENSOR_POWER_CHECK_STATUS 1 // If set to 1 the reported power/current/energy will be 0 if the relay[0] is OFF
#endif
#ifndef SENSOR_TEMPERATURE_CORRECTION
#define SENSOR_TEMPERATURE_CORRECTION 0.0 // Offset correction
#endif


+ 25
- 3
code/espurna/sensor.ino View File

@ -833,6 +833,11 @@ void sensorLoop() {
// Pre-read hook
_sensorPre();
// Get the first relay state
#if SENSOR_POWER_CHECK_STATUS
bool relay_off = (relayCount() > 0) && (relayStatus(0) == 0);
#endif
// Get readings
for (unsigned char i=0; i<_magnitudes.size(); i++) {
@ -840,17 +845,34 @@ void sensorLoop() {
if (magnitude.sensor->status()) {
unsigned char decimals = _magnitudeDecimals(magnitude.type);
current = magnitude.sensor->value(magnitude.local);
// Completely remove spurious values if relay is OFF
#if SENSOR_POWER_CHECK_STATUS
if (relay_off) {
if (magnitude.type == MAGNITUDE_POWER_ACTIVE ||
magnitude.type == MAGNITUDE_POWER_REACTIVE ||
magnitude.type == MAGNITUDE_POWER_APPARENT ||
magnitude.type == MAGNITUDE_CURRENT ||
magnitude.type == MAGNITUDE_ENERGY_DELTA
) {
current = 0;
}
}
#endif
magnitude.filter->add(current);
// Special case
if (magnitude.type == MAGNITUDE_EVENTS) current = magnitude.filter->result();
if (magnitude.type == MAGNITUDE_EVENTS) {
current = magnitude.filter->result();
}
current = _magnitudeProcess(magnitude.type, current);
_magnitudes[i].current = current;
unsigned char decimals = _magnitudeDecimals(magnitude.type);
// Debug
#if SENSOR_DEBUG
{


+ 0
- 1
code/platformio.ini View File

@ -729,7 +729,6 @@ board_flash_mode = dout
lib_deps = ${common.lib_deps}
lib_ignore = ${common.lib_ignore}
build_flags = ${common.build_flags_1m} -DITEAD_SONOFF_SV
monitor_baud = 115200
upload_port = "192.168.4.1"
upload_flags = --auth=fibonacci --port 8266
monitor_baud = 115200


Loading…
Cancel
Save