Add command ``SspmEnergyTotal<relay>``

Add command ``SspmEnergyTotal<relay>`` to (p)reset Sonoff SPM total energy without today's energy
This commit is contained in:
Theo Arends 2022-01-25 16:51:40 +01:00
parent d7664c02a7
commit 62458e3676
3 changed files with 53 additions and 27 deletions

View File

@ -12,12 +12,13 @@ All notable changes to this project will be documented in this file.
- Command ``Json {<Tasmota commands>}`` to enable input of any command as JSON tokens (#14568) - Command ``Json {<Tasmota commands>}`` to enable input of any command as JSON tokens (#14568)
- Rule variable %color% (#14572) - Rule variable %color% (#14572)
- Command ``SspmDisplay 1`` to display Sonoff SPM energy data in GUI for relays powered on only - Command ``SspmDisplay 1`` to display Sonoff SPM energy data in GUI for relays powered on only
- Command ``SspmHistory<relay>`` to retrieve daily energy of last six month (as defined by ARM firmware) - Command ``SspmEnergyTotal<relay>`` to (p)reset Sonoff SPM total energy without today's energy
- Command ``SspmHistory<relay>`` to retrieve Sonoff SPM daily energy up to last six month (as defined by ARM firmware)
- Command ``SspmIAmHere<relay>`` to (faintly) blink Sonoff SPM-4Relay module error light of requested relay - Command ``SspmIAmHere<relay>`` to (faintly) blink Sonoff SPM-4Relay module error light of requested relay
- Command ``SspmLog<relay> [x]`` to retrieve relay power state change and cause logging - Command ``SspmLog<relay> [x]`` to retrieve Sonoff SPM relay power state change and cause logging
- Command ``SspmScan`` to rescan Sonoff SPM modbus - Command ``SspmScan`` to rescan Sonoff SPM modbus
- Support for MQ analog sensor for air quality by Francesco Adriani (#14581) - Support for MQ analog sensor for air quality by Francesco Adriani (#14581)
- PWM auto-phasing for lights by default (new behavior) unless ``SetOption134 1`` - Command ``SetOption134 1`` to disable PWM auto-phasing for lights by default (new behavior) (#14590)
### Changed ### Changed
- BME68x-Sensor-API library from v3.5.9 to v4.4.7 - BME68x-Sensor-API library from v3.5.9 to v4.4.7

View File

@ -102,16 +102,18 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo
## Changelog v2022.01.3 ## Changelog v2022.01.3
### Added ### Added
- Command ``Json {<Tasmota commands>}`` to enable input of any command as JSON tokens [#14568](https://github.com/arendst/Tasmota/issues/14568)
- Command ``SetOption44 1..100`` to set base tolerance percentage for matching incoming IR messages (default 25, max 100) [#14555](https://github.com/arendst/Tasmota/issues/14555)
- Command ``SetOption134 1`` to disable PWM auto-phasing for lights by default (new behavior) [#14590](https://github.com/arendst/Tasmota/issues/14590)
- Command ``SSerialConfig <serialconfig>`` to change Serial Bridge configuration - Command ``SSerialConfig <serialconfig>`` to change Serial Bridge configuration
- Command ``WebTime <start_pos>,<end_pos>`` to show part of date and/or time in web gui based on "2017-03-07T11:08:02-07:00"
- Command ``SspmDisplay 1`` to display Sonoff SPM energy data in GUI for relays powered on only - Command ``SspmDisplay 1`` to display Sonoff SPM energy data in GUI for relays powered on only
- Command ``SspmHistory<relay>`` to retrieve daily energy of last six month (as defined by ARM firmware) - Command ``SspmEnergyTotal<relay>`` to (p)reset Sonoff SPM total energy without today's energy
- Command ``SspmHistory<relay>`` to retrieve Sonoff SPM daily energy up to last six month (as defined by ARM firmware)
- Command ``SspmIAmHere<relay>`` to (faintly) blink Sonoff SPM-4Relay module error light of requested relay - Command ``SspmIAmHere<relay>`` to (faintly) blink Sonoff SPM-4Relay module error light of requested relay
- Command ``SspmLog<relay> [x]`` to retrieve relay power state change and cause logging - Command ``SspmLog<relay> [x]`` to retrieve Sonoff SPM relay power state change and cause logging
- Command ``SspmMap 2,1,..`` to map Sonoff SPM scanned module to physical module [#14281](https://github.com/arendst/Tasmota/issues/14281) - Command ``SspmMap 2,1,..`` to map Sonoff SPM scanned module to physical module [#14281](https://github.com/arendst/Tasmota/issues/14281)
- Command ``SspmScan`` to rescan Sonoff SPM modbus - Command ``SspmScan`` to rescan Sonoff SPM modbus
- Command ``SetOption44 1..100`` to set base tolerance percentage for matching incoming IR messages (default 25, max 100) [#14555](https://github.com/arendst/Tasmota/issues/14555) - Command ``WebTime <start_pos>,<end_pos>`` to show part of date and/or time in web gui based on "2017-03-07T11:08:02-07:00"
- Command ``Json {<Tasmota commands>}`` to enable input of any command as JSON tokens [#14568](https://github.com/arendst/Tasmota/issues/14568)
- Commands for ESP32 ethernet configuration ``EthIpAddress``, ``EthGateway``, ``EthSubnetmask``, ``EthDnsServer1`` and ``EthDnsServer2`` [#14385](https://github.com/arendst/Tasmota/issues/14385) - Commands for ESP32 ethernet configuration ``EthIpAddress``, ``EthGateway``, ``EthSubnetmask``, ``EthDnsServer1`` and ``EthDnsServer2`` [#14385](https://github.com/arendst/Tasmota/issues/14385)
- Support for Eastron SDM230 modBus energy meter [#13443](https://github.com/arendst/Tasmota/issues/13443) - Support for Eastron SDM230 modBus energy meter [#13443](https://github.com/arendst/Tasmota/issues/13443)
- PWM Dimmer two button support [#13993](https://github.com/arendst/Tasmota/issues/13993) - PWM Dimmer two button support [#13993](https://github.com/arendst/Tasmota/issues/13993)

View File

@ -102,8 +102,12 @@
* relay = 0 to 127 Relays * relay = 0 to 127 Relays
\*********************************************************************************************/ \*********************************************************************************************/
#ifndef SSPM_JSON_ENERGY_TODAY
#define SSPM_JSON_ENERGY_TODAY // Show JSON energy today #define SSPM_JSON_ENERGY_TODAY // Show JSON energy today
#endif
#ifndef SSPM_JSON_ENERGY_YESTERDAY
#define SSPM_JSON_ENERGY_YESTERDAY // Show JSON energy yesterday #define SSPM_JSON_ENERGY_YESTERDAY // Show JSON energy yesterday
#endif
/*********************************************************************************************\ /*********************************************************************************************\
* Fixed defines - Do not change * Fixed defines - Do not change
@ -146,9 +150,9 @@
/*********************************************************************************************/ /*********************************************************************************************/
#define SSPM_FINAL_MAX_MODULES 32 // Max number of SPM-4RELAY units for a total of 128 relays #define SSPM_TOTAL_MODULES 32 // Max number of SPM-4RELAY units for a total of 128 relays
const uint32_t SSPM_VERSION = 0x01010101; // Latest driver version (See settings deltas below) const uint32_t SSPM_VERSION = 0x01010103; // Latest driver version (See settings deltas below)
enum SspmMachineStates { SPM_NONE, // Do nothing enum SspmMachineStates { SPM_NONE, // Do nothing
SPM_WAIT, // Wait 100ms SPM_WAIT, // Wait 100ms
@ -172,7 +176,8 @@ TasmotaSerial *SspmSerial;
typedef struct { typedef struct {
uint32_t crc32; // To detect file changes uint32_t crc32; // To detect file changes
uint32_t version; // To detect driver function changes uint32_t version; // To detect driver function changes
uint16_t module_map[SSPM_FINAL_MAX_MODULES]; // Max possible SPM relay modules uint16_t module_map[SSPM_TOTAL_MODULES]; // Max possible SPM relay modules
float energy_total[SSPM_TOTAL_MODULES][4]; // Total energy in hecto kWh (30.12 kwH is stored as 3012)
} tSspmSettings; } tSspmSettings;
typedef struct { typedef struct {
@ -275,7 +280,6 @@ void SSPMSettingsLoad(void) {
void SSPMSettingsSave(void) { void SSPMSettingsSave(void) {
// Called from FUNC_SAVE_SETTINGS every SaveData second and at restart // Called from FUNC_SAVE_SETTINGS every SaveData second and at restart
if (SSPMSettingsCrc32() != Sspm->Settings.crc32) { if (SSPMSettingsCrc32() != Sspm->Settings.crc32) {
// Try to save file /.drvset086 // Try to save file /.drvset086
Sspm->Settings.crc32 = SSPMSettingsCrc32(); Sspm->Settings.crc32 = SSPMSettingsCrc32();
@ -870,26 +874,30 @@ void SSPMHandleReceivedData(void) {
} }
} }
float energy_today = 0; float last_energy_today = Sspm->energy_yesterday[module][channel];
float energy_yesterday = 0;
float energy_total = 0; float energy_total = 0;
for (uint32_t i = 0; i <= entries; i++) { for (uint32_t i = 0; i <= entries; i++) {
float today_energy = SspmBuffer[41 + (i*2)] + (float)SspmBuffer[42 + (i*2)] / 100; // x.xxkWh float energy = SspmBuffer[41 + (i*2)] + (float)SspmBuffer[42 + (i*2)] / 100; // x.xxkWh
if (112.30 == today_energy) { today_energy = 0; } // Unknown why sometimes 0x701E (=112.30kWh) pops up if (112.30 == energy) { energy = 0; } // Unknown why sometimes 0x701E (=112.30kWh) pops up
if (Sspm->history_relay < 255) { if (Sspm->history_relay < 255) {
ResponseAppend_P(PSTR("%s%*_f"), (i)?",":"", Settings->flag2.energy_resolution, &today_energy); ResponseAppend_P(PSTR("%s%*_f"), (i)?",":"", Settings->flag2.energy_resolution, &energy);
} }
if (0 == i) { energy_today = today_energy; } if (0 == i) {
if (1 == i) { energy_yesterday = today_energy; } Sspm->energy_today[module][channel] = energy;
energy_total += today_energy; } else {
if (1 == i) { Sspm->energy_yesterday[module][channel] = energy; }
energy_total += energy;
} }
}
Sspm->energy_today[module][channel] = energy_today; if (0 == Sspm->Settings.energy_total[module][channel]) { // Initial save
Sspm->energy_yesterday[module][channel] = energy_yesterday; Sspm->Settings.energy_total[module][channel] = energy_total;
Sspm->energy_total[module][channel] = energy_total; // x.xxkWh }
if (Sspm->energy_today[module][channel] < last_energy_today) { // Daily incremental save
Sspm->Settings.energy_total[module][channel] += last_energy_today;
}
Sspm->energy_total[module][channel] = Sspm->Settings.energy_total[module][channel] + Sspm->energy_today[module][channel];
if (Sspm->history_relay < 255) { if (Sspm->history_relay < 255) {
ResponseAppend_P(PSTR("]}")); ResponseAppend_P(PSTR("]}"));
@ -1522,10 +1530,25 @@ void SSPMEnergyShow(bool json) {
\*********************************************************************************************/ \*********************************************************************************************/
const char kSSPMCommands[] PROGMEM = "SSPM|" // Prefix const char kSSPMCommands[] PROGMEM = "SSPM|" // Prefix
"Log|Energy|History|Scan|IamHere|Display|Reset|Map" ; "Log|Energy|History|Scan|IamHere|Display|Reset|Map|" D_CMND_ENERGYTOTAL;
void (* const SSPMCommand[])(void) PROGMEM = { void (* const SSPMCommand[])(void) PROGMEM = {
&CmndSSPMLog, &CmndSSPMEnergy, &CmndSSPMHistory, &CmndSSPMScan, &CmndSSPMIamHere, &CmndSSPMDisplay, &CmndSSPMReset, &CmndSSPMMap }; &CmndSSPMLog, &CmndSSPMEnergy, &CmndSSPMHistory, &CmndSSPMScan, &CmndSSPMIamHere,
&CmndSSPMDisplay, &CmndSSPMReset, &CmndSSPMMap, &CmndSpmEnergyTotal };
void CmndSpmEnergyTotal(void) {
// Reset Energy Total
// SspmEnergyTotal<relay> 0 - Set total energy from midnight with sum of last month history
// SspmEnergyTotal<relay> 4.23 - Set total energy from midnight (without today's energy)
uint32_t relay = XdrvMailbox.index -1;
uint32_t module = relay >> 2;
uint32_t channel = relay & 0x03;
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= TasmotaGlobal.devices_present) && XdrvMailbox.data_len) {
Sspm->Settings.energy_total[module][channel] = CharToFloat(XdrvMailbox.data);
Sspm->energy_total[module][channel] = Sspm->Settings.energy_total[module][channel] + Sspm->energy_today[module][channel];
}
ResponseCmndFloat(Sspm->energy_total[module][channel], Settings->flag2.energy_resolution);
}
void CmndSSPMLog(void) { void CmndSSPMLog(void) {
// SspmLog<relay> - Report from up to 29 latest log entries // SspmLog<relay> - Report from up to 29 latest log entries