diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino
index aefb1b821..e607ecd09 100644
--- a/sonoff/_changelog.ino
+++ b/sonoff/_changelog.ino
@@ -1,6 +1,7 @@
/*********************************************************************************************\
* 6.6.0.11 20190907
* Change Settings crc calculation allowing short term backward compatibility
+ * Add support for up to 4 INA226 Voltage and Current sensors by Steve Rogers (#6342)
*
* 6.6.0.10 20190905
* Redesign Tuya support by Shantur Rathore (#6353)
diff --git a/sonoff/my_user_config.h b/sonoff/my_user_config.h
index a18adc7b7..3b4ac0e68 100644
--- a/sonoff/my_user_config.h
+++ b/sonoff/my_user_config.h
@@ -341,6 +341,7 @@
// #define USE_ADS1115 // Enable ADS1115 16 bit A/D converter (I2C address 0x48, 0x49, 0x4A or 0x4B) based on Adafruit ADS1x15 library (no library needed) (+0k7 code)
// #define USE_ADS1115_I2CDEV // Enable ADS1115 16 bit A/D converter (I2C address 0x48, 0x49, 0x4A or 0x4B) using library i2cdevlib-Core and i2cdevlib-ADS1115 (+2k code)
// #define USE_INA219 // Enable INA219 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+1k code)
+// #define USE_INA226 // Enable INA226 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+2k3 code)
#define USE_SHT3X // Enable SHT3x (I2C address 0x44 or 0x45) or SHTC3 (I2C address 0x70) sensor (+0k7 code)
// #define USE_TSL2561 // Enable TSL2561 sensor (I2C address 0x29, 0x39 or 0x49) using library Joba_Tsl2561 (+2k3 code)
// #define USE_MGS // Enable Xadow and Grove Mutichannel Gas sensor using library Multichannel_Gas_Sensor (+10k code)
diff --git a/sonoff/settings.h b/sonoff/settings.h
index 3a335b684..a466f0a4d 100644
--- a/sonoff/settings.h
+++ b/sonoff/settings.h
@@ -373,10 +373,10 @@ struct SYSCFG {
char mems[MAX_RULE_MEMS][10]; // 7CE
char rules[MAX_RULE_SETS][MAX_RULE_SIZE]; // 800 uses 512 bytes in v5.12.0m, 3 x 512 bytes in v5.14.0b
TuyaFnidDpidMap tuya_fnid_map[MAX_TUYA_FUNCTIONS]; // E00 32 bytes
- uint16_t ina226_r_shunt[4]; // E20
- uint16_t ina226_i_fs[4]; // E28
+ uint16_t ina226_r_shunt[4]; // E20
+ uint16_t ina226_i_fs[4]; // E28
- uint8_t free_e20[456]; // E30
+ uint8_t free_e30[456]; // E30
uint32_t cfg_timestamp; // FF8
uint32_t cfg_crc32; // FFC
diff --git a/sonoff/sonoff_post.h b/sonoff/sonoff_post.h
index 271325da1..88f29ff5c 100644
--- a/sonoff/sonoff_post.h
+++ b/sonoff/sonoff_post.h
@@ -108,6 +108,7 @@ char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, c
#define USE_ADS1115 // Add I2C code for ADS1115 16 bit A/D converter based on Adafruit ADS1x15 library (no library needed) (+0k7 code)
//#define USE_ADS1115_I2CDEV // Add I2C code for ADS1115 16 bit A/D converter using library i2cdevlib-Core and i2cdevlib-ADS1115 (+2k code)
#define USE_INA219 // Add I2C code for INA219 Low voltage and current sensor (+1k code)
+//#define USE_INA226 // Enable INA226 (I2C address 0x40, 0x41 0x44 or 0x45) Low voltage and current sensor (+2k3 code)
#define USE_SHT3X // Add I2C code for SHT3x sensor (+0k6 code)
#define USE_TSL2561 // Add I2C code for TSL2561 sensor using library Adafruit TSL2561 Arduino (+1k2 code)
#define USE_MGS // Add I2C code for Xadow and Grove Mutichannel Gas sensor using library Multichannel_Gas_Sensor (+10k code)
diff --git a/sonoff/support_features.ino b/sonoff/support_features.ino
index 8265e4cb9..491dbf5af 100644
--- a/sonoff/support_features.ino
+++ b/sonoff/support_features.ino
@@ -438,9 +438,13 @@ void GetFeatures(void)
#ifdef USE_IBEACON
feature5 |= 0x00000004; // xsns_52_ibeacon.ino
#endif
-// feature5 |= 0x00000008;
+#ifdef USE_SML_M
+ feature5 |= 0x00000008; // xsns_53_sml.ino
+#endif
-// feature5 |= 0x00000010;
+#ifdef USE_INA226
+ feature5 |= 0x00000010; // xsns_54_ina226.ino
+#endif
// feature5 |= 0x00000020;
// feature5 |= 0x00000040;
// feature5 |= 0x00000080;
diff --git a/sonoff/xsns_54_ina226.ino b/sonoff/xsns_54_ina226.ino
index dc3d24d51..9fc48c83b 100644
--- a/sonoff/xsns_54_ina226.ino
+++ b/sonoff/xsns_54_ina226.ino
@@ -1,18 +1,24 @@
/*
xsns_54_ina226.ino - INA226 Current Sensor support for Sonoff-Tasmota
+
Copyright (C) 2019 Stephen Rodgers and Theo Arends
+
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
+
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
+#ifdef USE_I2C
+#ifdef USE_INA226
/*
* Setup a single INA226 device at address 0x40:
*
@@ -58,13 +64,9 @@
*
*/
-
-// Conditional compilation of driver
-#ifdef USE_INA226
-
// Define driver ID
-#define XSNS_54 54
+#define XSNS_54 54
#define INA226_MAX_ADDRESSES 4
#define INA226_ADDRESS1 (0x40) // 1000000 (A0+A1=GND)
@@ -522,47 +524,45 @@ void Ina226Show(bool json)
* It provides the Tasmota callback IDs.
*
* @param byte callback_id Tasmota function ID.
- * @return boolean Return value.
+ * @return bool Return value.
* @pre None.
* @post None.
*
*/
-boolean Xsns54(byte callback_id) {
+bool Xsns54(byte callback_id) {
// Set return value to `false`
bool result = false;
// Check if I2C interface mode is enabled
-if(i2c_flg) {
+ if(i2c_flg) {
- // Check which callback ID is called by Tasmota
- switch (callback_id) {
- case FUNC_INIT:
- Ina226Init();
- break;
- case FUNC_EVERY_50_MSECOND:
- break;
- case FUNC_EVERY_SECOND:
- Ina226EverySecond();
- break;
- case FUNC_JSON_APPEND:
- Ina226Show(1);
- break;
+ // Check which callback ID is called by Tasmota
+ switch (callback_id) {
+ case FUNC_EVERY_SECOND:
+ Ina226EverySecond();
+ break;
+ case FUNC_INIT:
+ Ina226Init();
+ break;
+ case FUNC_JSON_APPEND:
+ Ina226Show(1);
+ break;
#ifdef USE_WEBSERVER
- case FUNC_WEB_SENSOR:
- Ina226Show(0);
- break;
+ case FUNC_WEB_SENSOR:
+ Ina226Show(0);
+ break;
#endif // USE_WEBSERVER
- case FUNC_SAVE_BEFORE_RESTART:
- break;
- case FUNC_COMMAND_SENSOR:
- if (XSNS_54 == XdrvMailbox.index) {
- result = Ina226CommandSensor();
- }
- break;
+ case FUNC_COMMAND_SENSOR:
+ if (XSNS_54 == XdrvMailbox.index) {
+ result = Ina226CommandSensor();
+ }
+ break;
}
} // if(i2c_flg)
// Return boolean result
return result;
}
-#endif // USE_
+
+#endif // USE_INA226
+#endif // USE_I2C
diff --git a/tools/decode-status.py b/tools/decode-status.py
index 973c8655c..cc511e5d9 100755
--- a/tools/decode-status.py
+++ b/tools/decode-status.py
@@ -86,17 +86,22 @@ a_setoption = [[
],[
"Key hold time (ms)",
"Sonoff POW Max_Power_Retry",
- "Tuya dimmer device id",
+ "(not used) Tuya MCU device id",
"(not used) mDNS delayed start (Sec)",
"Boot loop retry offset (0 = disable)",
"RGBWW remap",
"IR Unknown threshold",
"CSE7766 invalid power margin",
"Ignore hold time (s)",
- "Number of Tuya relays",
+ "(not used) Number of Tuya MCU relays",
"Over temperature threshold (celsius)",
+ "Tuya MCU max dimmer value",
+ "(not used) Tuya MCU voltage Id",
+ "(not used) Tuya MCU current Id",
+ "(not used) Tuya MCU power Id",
+ "Energy Tariff1 start hour",
+ "Energy Tariff2 start hour",
"",
- "","","","","","",
],[
"Timers enabled",
"Generic ESP8285 GPIO enabled",
@@ -113,12 +118,13 @@ a_setoption = [[
"Do not use retain flag on HOLD messages",
"Do not scan relay power state at restart",
"Use _ instead of - as sensor index separator",
- "Disable Dimmer slider control",
+ "(not used) Disable Dimmer slider control",
"Disable Dimmer range 255 slider control",
"Enable buzzer when available",
"Enable multi-channels PWM instead of Color PWM",
- "",
- "","","","",
+ "Limits Tuya MCU dimmers to minimum of 10% (25) when enabled",
+ "Enable Weekend Energy Tariff",
+ "","","",
"","","","",
"","","",""
]]
@@ -160,8 +166,8 @@ a_features = [[
"USE_ADE7953","USE_SPS30","USE_VL53L0X","USE_MLX90614",
"USE_MAX31865","USE_CHIRP","USE_SOLAX_X1","USE_PAJ7620"
],[
- "USE_BUZZER","USE_RDM6300","USE_IBEACON","",
- "","","","",
+ "USE_BUZZER","USE_RDM6300","USE_IBEACON","USE_SML_M",
+ "USE_INA226","","","",
"","","","",
"","","","",
"","","","",