From a70bebe0adc4d1ebabf31582e9360a23b3fca924 Mon Sep 17 00:00:00 2001 From: Christopher Tremblay Date: Thu, 22 Oct 2020 01:23:47 -0700 Subject: [PATCH] Add support for EZO HUM Adds suppotr for EZO humidity&temp sensor. --- tasmota/ezo.ino | 2 +- tasmota/ezoManager.ino | 12 +++++- tasmota/my_user_config.h | 1 + tasmota/xsns_81_ezohum.ino | 85 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 tasmota/xsns_81_ezohum.ino diff --git a/tasmota/ezo.ino b/tasmota/ezo.ino index 17effbeed..06b447a32 100644 --- a/tasmota/ezo.ino +++ b/tasmota/ezo.ino @@ -17,7 +17,7 @@ along with this program. If not, see . */ #ifdef USE_I2C -#if defined(USE_EZOPH) || defined(USE_EZOORP) || defined(USE_EZORTD) +#if defined(USE_EZOPH) || defined(USE_EZOORP) || defined(USE_EZORTD) || defined(USE_EZOHUM) #define D_EZO_DELAY 300 // Minimum delay for any instruction #define D_EZO_MAX_BUF 40 // Maximum response diff --git a/tasmota/ezoManager.ino b/tasmota/ezoManager.ino index 2a8eba63b..d36462c7c 100644 --- a/tasmota/ezoManager.ino +++ b/tasmota/ezoManager.ino @@ -17,7 +17,7 @@ along with this program. If not, see . */ #ifdef USE_I2C -#if defined(USE_EZOPH) || defined(USE_EZOORP) || defined(USE_EZORTD) +#if defined(USE_EZOPH) || defined(USE_EZOORP) || defined(USE_EZORTD) || defined(USE_EZOHUM) #define XI2C_55 55 // See I2CDEVICES.md @@ -62,7 +62,9 @@ const char EZO_RTD_NAME[] PROGMEM = "RTD"; //const char EZO_CO2_NAME[] PROGMEM = "CO2"; //const char EZO_PRS_NAME[] PROGMEM = "PRS"; //const char EZO_O2_NAME[] PROGMEM = "O2"; -//const char EZO_HUM_NAME[] PROGMEM = "HUM"; +#ifdef USE_EZOHUM +const char EZO_HUM_NAME[] PROGMEM = "HUM"; +#endif //const char EZO_RGB_NAME[] PROGMEM = "RGB"; const char *const EZOSupport[EZO_ADDR_n] PROGMEM = { @@ -97,7 +99,13 @@ const char *const EZOSupport[EZO_ADDR_n] PROGMEM = { EZO_EMPTY, EZO_EMPTY, EZO_EMPTY, + +#ifdef USE_EZOHUM + EZO_HUM_NAME, +#else EZO_EMPTY, +#endif + EZO_EMPTY, }; diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index ec4c47441..99d40eda1 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -565,6 +565,7 @@ // #define USE_EZOPH // [I2cDriver55] Enable support for EZO's pH sensor (+0k6 code) - Shared EZO code required for any EZO device (+1k0 code) // #define USE_EZOORP // [I2cDriver55] Enable support for EZO's ORP sensor (+0k6 code) - Shared EZO code required for any EZO device (+1k0 code) // #define USE_EZORTD // [I2cDriver55] Enable support for EZO's RTD sensor (+0k6 code) - Shared EZO code required for any EZO device (+1k0 code) +// #define USE_EZOHUM // [I2cDriver55] Enable support for EZO's HUM sensor (+0k6 code) - Shared EZO code required for any EZO device (+1k0 code) // #define USE_DISPLAY // Add I2C Display Support (+2k code) #define USE_DISPLAY_MODES1TO5 // Enable display mode 1 to 5 in addition to mode 0 diff --git a/tasmota/xsns_81_ezohum.ino b/tasmota/xsns_81_ezohum.ino new file mode 100644 index 000000000..dada1c31a --- /dev/null +++ b/tasmota/xsns_81_ezohum.ino @@ -0,0 +1,85 @@ +/* + xsns_81_ezortd.ino - EZO HUM I2C HUM sensor support for Tasmota + + Copyright (C) 2020 Christopher Tremblay + + 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_EZOHUM + +#define XSNS_81 81 + +#define EZO_HUM_READ_LATENCY 300 + +struct EZOHUM : public EZOStruct { + void ProcessMeasurement(void) + { + char data[D_EZO_MAX_BUF]; + // Hum, Temp, Dew + + EZOStruct::ProcessMeasurement(data, sizeof(data), EZO_HUM_READ_LATENCY); + + humidity = CharToFloat(data); + + char *next = strchr(data, ','); + if (next) { + temperature = CharToFloat(next + 1); + } + } + + void Show(bool json, uint32_t index) + { + if (valid) { + char name[10]; + snprintf_P(name, sizeof(name), PSTR("%s%c%X"), EZOHUM::name, IndexSeparator(), index + 1); + + if (count == 1) { + name[sizeof("EZOHUM") - 1] = 0; + } + + if (isnan(temperature)) { + char parameter[FLOATSZ]; + + dtostrfd(humidity, Settings.flag2.humidity_resolution, parameter); + WSContentSend_PD(HTTP_SNS_HUM, name, parameter); + } else { + TempHumDewShow(json, (0 == tele_period), name, temperature, humidity); + } + } + } + + static int8_t count; + static EZOHUM *list; + +private: + static const char name[]; + + float humidity = NAN; + float temperature = NAN; +}; + +int8_t EZOHUM::count = -1; +EZOHUM *EZOHUM::list = NULL; +const char EZOHUM::name[] PROGMEM = "EZOHUM"; + + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ +#define Xsns81 XsnsEZO + +#endif // USE_EZOHUM +#endif // USE_I2C