From ea726710183a99101ff3e0f9af594bfbd18f7095 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 29 Sep 2019 12:18:09 +0200 Subject: [PATCH] Fix Energy Off-Peak detection calculation Fix Energy Off-Peak detection calculation (#6500) --- sonoff/xdrv_03_energy.ino | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index 55bf1a15f..cd5cc0f45 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -134,13 +134,18 @@ bool EnergyTariff1Active() // Off-Peak hours dst = 1; } if (Settings.tariff[0][dst] != Settings.tariff[1][dst]) { + if (Settings.flag3.energy_weekend && ((RtcTime.day_of_week == 1) || + (RtcTime.day_of_week == 7))) { + return true; + } uint32_t minutes = MinutesPastMidnight(); - return ((minutes < Settings.tariff[1][dst]) || // Tarrif1 = Off-Peak - (minutes >= Settings.tariff[0][dst]) || - (Settings.flag3.energy_weekend && ((RtcTime.day_of_week == 1) || - (RtcTime.day_of_week == 7))) - ); - + if (Settings.tariff[0][dst] > Settings.tariff[1][dst]) { + // {"Tariff":{"Off-Peak":{"STD":"22:00","DST":"23:00"},"Standard":{"STD":"06:00","DST":"07:00"},"Weekend":"OFF"}} + return ((minutes >= Settings.tariff[0][dst]) || (minutes < Settings.tariff[1][dst])); + } else { + // {"Tariff":{"Off-Peak":{"STD":"00:29","DST":"01:29"},"Standard":{"STD":"07:29","DST":"08:29"},"Weekend":"OFF"}} + return ((minutes >= Settings.tariff[0][dst]) && (minutes < Settings.tariff[1][dst])); + } } else { return false; }