Add support for HYTxxx temperature and humidity sensor (#15715)

This commit is contained in:
Theo Arends 2022-06-04 14:15:16 +02:00
parent 4d9977ef04
commit d7ffd01f1f
5 changed files with 133 additions and 0 deletions

View File

@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
## [11.1.0.4]
### Added
- Support for HYTxxx temperature and humidity sensor (#15715)
### Changed
- Restructured tasmota source directories taking benefit from PlatformIO Core v6.0.2

View File

@ -119,6 +119,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo
- Support for Sonoff Zigbee Bridge Pro by Stephan Hadinger [#15701](https://github.com/arendst/Tasmota/issues/15701)
- Support for flowrate meters like YF-DN50 and similary [#15474](https://github.com/arendst/Tasmota/issues/15474)
- Support for 5-channel light dimmer driver BP5758D used in Tuya bulbs [#15713](https://github.com/arendst/Tasmota/issues/15713)
- Support for HYTxxx temperature and humidity sensor [#15715](https://github.com/arendst/Tasmota/issues/15715)
- ESP32 Command ``Restart 3`` to switch between SafeBoot and Production
### Breaking Changed

View File

@ -150,6 +150,7 @@
//#define USE_T67XX // [I2cDriver61] Enable Telaire T67XX CO2 sensor (I2C address 0x15) (+1k3 code)
//#define USE_HDC2010 // [I2cDriver64] Enable HDC2010 temperature/humidity sensor (I2C address 0x40) (+1k5 code)
//#define USE_DS3502 // [I2CDriver67] Enable DS3502 digital potentiometer (I2C address 0x28 - 0x2B) (+0k4 code)
//#define USE_HYT // [I2CDriver68] Enable HYTxxx temperature and humidity sensor (I2C address 0x28) (+0k5 code)
//#define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one
// #define USE_DS3231 // [I2cDriver26] Enable DS3231 RTC (I2C address 0x68) (+1k2 code)

View File

@ -405,6 +405,7 @@
//#define USE_AM2320 // [I2cDriver60] Enable AM2320 temperature and humidity Sensor (I2C address 0x5C) (+1k code)
//#define USE_T67XX // [I2cDriver61] Enable Telaire T67XX CO2 sensor (I2C address 0x15) (+1k3 code)
//#define USE_DS3502 // [I2CDriver67] Enable DS3502 digital potentiometer (I2C address 0x28 - 0x2B) (+0k4 code)
//#define USE_HYT // [I2CDriver68] Enable HYTxxx temperature and humidity sensor (I2C address 0x28) (+0k5 code)
//#define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one
// #define USE_DS3231 // [I2cDriver26] Enable DS3231 RTC (I2C address 0x68) (+1k2 code)
@ -610,6 +611,7 @@
//#define USE_EZOPMP // [I2cDriver55] Enable support for EZO's PMP sensor (+0k3 code) - Shared EZO code required for any EZO device (+1k2 code)
//#define USE_SEESAW_SOIL // [I2cDriver56] Enable Capacitice Soil Moisture & Temperature Sensor (I2C addresses 0x36 - 0x39) (+1k3 code)
//#define USE_DS3502 // [I2CDriver67] Enable DS3502 digital potentiometer (I2C address 0x28 - 0x2B) (+0k4 code)
//#define USE_HYT // [I2CDriver68] Enable HYTxxx temperature and humidity sensor (I2C address 0x28) (+0k5 code)
//#define USE_RTC_CHIPS // Enable RTC chip support and NTP server - Select only one
// #define USE_DS3231 // [I2cDriver26] Enable DS3231 RTC (I2C address 0x68) (+1k2 code)

View File

@ -0,0 +1,128 @@
/*
xsns_97_hyt.ino - HYT I2C temperature and humidity sensor support for Tasmota
Copyright (C) 2020 Thomas Schnittcher
Copyright (C) 2022 Adjan Kretz, fix compatibility issues with current HYT
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 <http://www.gnu.org/licenses/>.
*/
#ifdef USE_I2C
#ifdef USE_HYT
/*********************************************************************************************\
* HYT221, HYT271, HYT371 and HYT939 Temperature and Humidity
* https://www.ist-ag.com/en/products-services/humidity-modules-sensors
*
* I2C Address: 0x28
\*********************************************************************************************/
#define XSNS_97 97
#define XI2C_68 68 // See I2CDEVICES.md
#define HYT_ADDR 0x28 // I2C address of HYT 221, 271, 371 etc.
struct HYT {
float humidity = NAN;
float temperature = NAN;
uint8_t valid = 0;
uint8_t count = 0;
char name[6] = "HYT";
} HYT;
bool HYT_Read(void) {
if (HYT.valid) { HYT.valid--; }
Wire.beginTransmission(HYT_ADDR);
Wire.requestFrom(HYT_ADDR, 4);
if (Wire.available() == 4) {
uint8_t data1 = Wire.read();
uint8_t data2 = Wire.read();
uint8_t data3 = Wire.read();
uint8_t data4 = Wire.read();
Wire.endTransmission();
// Convert the data to 14-bits
float humidity = ((((data1 & 0x3F) * 256) + data2) * 100.0) / 16383.0;
int temp = ((data3 * 256) + (data4 & 0xFC)) / 4;
float temperature = (temp / 16384.0) * 165.0 - 40.0;
HYT.humidity = ConvertHumidity(humidity);
HYT.temperature = ConvertTemp(temperature);
}
if (isnan(HYT.temperature) || isnan(HYT.humidity)) { return false; }
HYT.valid = SENSOR_MAX_MISS;
// HYT.valid = 1;
return true;
}
/********************************************************************************************/
void HYT_Detect(void) {
if (I2cSetDevice(HYT_ADDR)) {
I2cSetActiveFound(HYT_ADDR, "HYT");
HYT.count = 1;
}
}
/********************************************************************************************/
void HYT_EverySecond(void) {
if (!(TasmotaGlobal.uptime %4)) { // Every 4 seconds
if (!HYT_Read()) {
AddLogMissed(HYT.name, HYT.valid);
}
}
}
void HYT_Show(bool json) {
if (HYT.valid) {
TempHumDewShow(json, (0 == TasmotaGlobal.tele_period), HYT.name, HYT.temperature, HYT.humidity);
}
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
bool Xsns97(uint8_t function) {
if (!I2cEnabled(XI2C_68)) { return false; }
bool result = false;
if (FUNC_INIT == function) {
HYT_Detect();
}
else if (HYT.count) {
switch (function) {
case FUNC_EVERY_SECOND:
HYT_EverySecond();
break;
case FUNC_JSON_APPEND:
HYT_Show(1);
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_SENSOR:
HYT_Show(0);
break;
#endif // USE_WEBSERVER
}
}
return result;
}
#endif // USE_HYT
#endif // USE_I2C