From 0a0afe361562598b28ad63f3de8cdbec9542ba4e Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 17 Mar 2020 16:29:59 +0100 Subject: [PATCH] Add Dew point to more sensors Add Dew point to more sensors and refactor JSON Temperature and Humidity message --- tasmota/i18n.h | 2 -- tasmota/support.ino | 14 ++++++++++- tasmota/support_tasmota.ino | 18 ++++---------- tasmota/tasmota_post.h | 1 + tasmota/xdrv_01_webserver.ino | 11 +++++++++ tasmota/xdrv_07_domoticz.ino | 28 ++++++++++++--------- tasmota/xsns_04_snfsc.ino | 15 ++++-------- tasmota/xsns_06_dht.ino | 30 ----------------------- tasmota/xsns_07_sht1x.ino | 30 ----------------------- tasmota/xsns_08_htu21.ino | 30 ----------------------- tasmota/xsns_09_bmp.ino | 2 +- tasmota/xsns_14_sht3x.ino | 38 ---------------------------- tasmota/xsns_17_senseair.ino | 14 +++++------ tasmota/xsns_37_rfsensor.ino | 29 +++++++++------------- tasmota/xsns_38_az7798.ino | 12 +++------ tasmota/xsns_42_scd30.ino | 20 ++++++--------- tasmota/xsns_48_chirp.ino | 4 +-- tasmota/xsns_55_hih_series.ino | 30 ----------------------- tasmota/xsns_58_dht12.ino | 30 ----------------------- tasmota/xsns_63_aht1x.ino | 45 ---------------------------------- tasmota/xsns_65_hdc1080.ino | 31 ----------------------- 21 files changed, 84 insertions(+), 350 deletions(-) diff --git a/tasmota/i18n.h b/tasmota/i18n.h index 26e2df784..12f3164c6 100644 --- a/tasmota/i18n.h +++ b/tasmota/i18n.h @@ -632,8 +632,6 @@ const char S_JSON_DRIVER_INDEX_NVALUE[] PROGMEM = "{\"" D_CMND_DRIVE const char S_JSON_DRIVER_INDEX_SVALUE[] PROGMEM = "{\"" D_CMND_DRIVER "%d\":\"%s\"}"; const char JSON_SNS_TEMP[] PROGMEM = ",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s}"; -//const char JSON_SNS_TEMPHUM[] PROGMEM = ",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_HUMIDITY "\":%s}"; -const char JSON_SNS_TEMPHUMDEW[] PROGMEM = ",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_HUMIDITY "\":%s,\"" D_JSON_DEWPOINT "\":%s}"; const char JSON_SNS_ILLUMINANCE[] PROGMEM = ",\"%s\":{\"" D_JSON_ILLUMINANCE "\":%d}"; const char JSON_SNS_MOISTURE[] PROGMEM = ",\"%s\":{\"" D_JSON_MOISTURE "\":%d}"; diff --git a/tasmota/support.ino b/tasmota/support.ino index 6ad941d31..37bdb942a 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -621,7 +621,7 @@ float ConvertHumidity(float h) global_update = uptime; global_humidity = h; - + result = result + (0.1 * Settings.hum_comp); return result; @@ -1040,6 +1040,18 @@ int ResponseAppendTime(void) return ResponseAppendTimeFormat(Settings.flag2.time_format); } +int ResponseAppendTHD(float f_temperature, float f_humidity) +{ + char temperature[FLOATSZ]; + dtostrfd(f_temperature, Settings.flag2.temperature_resolution, temperature); + char humidity[FLOATSZ]; + dtostrfd(f_humidity, Settings.flag2.humidity_resolution, humidity); + char dewpoint[FLOATSZ]; + dtostrfd(CalcTempHumToDew(f_temperature, f_humidity), Settings.flag2.temperature_resolution, dewpoint); + + return ResponseAppend_P(PSTR("\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_HUMIDITY "\":%s,\"" D_JSON_DEWPOINT "\":%s"), temperature, humidity, dewpoint); +} + int ResponseJsonEnd(void) { return ResponseAppend_P(PSTR("}")); diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index 4e8a3fa54..d8ca2668c 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -669,19 +669,13 @@ void MqttPublishTeleState(void) void TempHumDewShow(bool json, bool pass_on, const char *types, float f_temperature, float f_humidity) { - char temperature[33]; - dtostrfd(f_temperature, Settings.flag2.temperature_resolution, temperature); - char humidity[33]; - dtostrfd(f_humidity, Settings.flag2.humidity_resolution, humidity); - float f_dewpoint = CalcTempHumToDew(f_temperature, f_humidity); - char dewpoint[33]; - dtostrfd(f_dewpoint, Settings.flag2.temperature_resolution, dewpoint); - if (json) { - ResponseAppend_P(JSON_SNS_TEMPHUMDEW, types, temperature, humidity, dewpoint); + ResponseAppend_P(PSTR(",\"%s\":{"), types); + ResponseAppendTHD(f_temperature, f_humidity); + ResponseJsonEnd(); #ifdef USE_DOMOTICZ if (pass_on) { - DomoticzTempHumSensor(temperature, humidity); + DomoticzTempHumPressureSensor(f_temperature, f_humidity); } #endif // USE_DOMOTICZ #ifdef USE_KNX @@ -692,9 +686,7 @@ void TempHumDewShow(bool json, bool pass_on, const char *types, float f_temperat #endif // USE_KNX #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_TEMP, types, temperature, TempUnit()); - WSContentSend_PD(HTTP_SNS_HUM, types, humidity); - WSContentSend_PD(HTTP_SNS_DEW, types, dewpoint, TempUnit()); + WSContentSend_THD(types, f_temperature, f_humidity); #endif // USE_WEBSERVER } } diff --git a/tasmota/tasmota_post.h b/tasmota/tasmota_post.h index 1abd371ff..745fd165b 100644 --- a/tasmota/tasmota_post.h +++ b/tasmota/tasmota_post.h @@ -38,6 +38,7 @@ extern "C" { void KNX_CB_Action(message_t const &msg, void *arg); //#endif // USE_KNX +void DomoticzTempHumPressureSensor(float temp, float hum, float baro = -1); char* ToHex_P(const unsigned char * in, size_t insz, char * out, size_t outsz, char inbetween = '\0'); extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack, uint32_t stack_end); diff --git a/tasmota/xdrv_01_webserver.ino b/tasmota/xdrv_01_webserver.ino index 08ac49574..7f55a01fd 100644 --- a/tasmota/xdrv_01_webserver.ino +++ b/tasmota/xdrv_01_webserver.ino @@ -922,6 +922,17 @@ void WSContentSpaceButton(uint32_t title_index) WSContentButton(title_index); } +void WSContentSend_THD(const char *types, float f_temperature, float f_humidity) +{ + char parameter[FLOATSZ]; + dtostrfd(f_temperature, Settings.flag2.temperature_resolution, parameter); + WSContentSend_PD(HTTP_SNS_TEMP, types, parameter, TempUnit()); + dtostrfd(f_humidity, Settings.flag2.humidity_resolution, parameter); + WSContentSend_PD(HTTP_SNS_HUM, types, parameter); + dtostrfd(CalcTempHumToDew(f_temperature, f_humidity), Settings.flag2.temperature_resolution, parameter); + WSContentSend_PD(HTTP_SNS_DEW, types, parameter, TempUnit()); +} + void WSContentEnd(void) { WSContentFlush(); // Flush chunk buffer diff --git a/tasmota/xdrv_07_domoticz.ino b/tasmota/xdrv_07_domoticz.ino index 90563eeed..1fddf5890 100644 --- a/tasmota/xdrv_07_domoticz.ino +++ b/tasmota/xdrv_07_domoticz.ino @@ -390,9 +390,8 @@ bool DomoticzSendKey(uint8_t key, uint8_t device, uint8_t state, uint8_t svalflg * \*********************************************************************************************/ -uint8_t DomoticzHumidityState(char *hum) +uint8_t DomoticzHumidityState(float h) { - uint8_t h = atoi(hum); return (!h) ? 0 : (h < 40) ? 2 : (h > 70) ? 3 : 1; } @@ -428,18 +427,25 @@ void DomoticzSensor(uint8_t idx, uint32_t value) DomoticzSensor(idx, data); } -void DomoticzTempHumSensor(char *temp, char *hum) +//void DomoticzTempHumPressureSensor(float temp, float hum, float baro = -1); +void DomoticzTempHumPressureSensor(float temp, float hum, float baro) { - char data[16]; - snprintf_P(data, sizeof(data), PSTR("%s;%s;%d"), temp, hum, DomoticzHumidityState(hum)); - DomoticzSensor(DZ_TEMP_HUM, data); -} + char temperature[FLOATSZ]; + dtostrfd(temp, 2, temperature); + char humidity[FLOATSZ]; + dtostrfd(hum, 2, humidity); -void DomoticzTempHumPressureSensor(char *temp, char *hum, char *baro) -{ char data[32]; - snprintf_P(data, sizeof(data), PSTR("%s;%s;%d;%s;5"), temp, hum, DomoticzHumidityState(hum), baro); - DomoticzSensor(DZ_TEMP_HUM_BARO, data); + if (baro > -1) { + char pressure[FLOATSZ]; + dtostrfd(baro, 2, pressure); + + snprintf_P(data, sizeof(data), PSTR("%s;%s;%d;%s;5"), temperature, humidity, DomoticzHumidityState(hum), pressure); + DomoticzSensor(DZ_TEMP_HUM_BARO, data); + } else { + snprintf_P(data, sizeof(data), PSTR("%s;%s;%d"), temperature, humidity, DomoticzHumidityState(hum)); + DomoticzSensor(DZ_TEMP_HUM, data); + } } void DomoticzSensorPowerEnergy(int power, char *energy) diff --git a/tasmota/xsns_04_snfsc.ino b/tasmota/xsns_04_snfsc.ino index 463882942..7652f8483 100644 --- a/tasmota/xsns_04_snfsc.ino +++ b/tasmota/xsns_04_snfsc.ino @@ -115,17 +115,13 @@ void SonoffScShow(bool json) float t = ConvertTemp(sc_value[1]); float h = ConvertHumidity(sc_value[0]); - char temperature[33]; - dtostrfd(t, Settings.flag2.temperature_resolution, temperature); - char humidity[33]; - dtostrfd(h, Settings.flag2.humidity_resolution, humidity); - if (json) { - ResponseAppend_P(PSTR(",\"SonoffSC\":{\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_HUMIDITY "\":%s,\"" D_JSON_LIGHT "\":%d,\"" D_JSON_NOISE "\":%d,\"" D_JSON_AIRQUALITY "\":%d}"), - temperature, humidity, sc_value[2], sc_value[3], sc_value[4]); + ResponseAppend_P(PSTR(",\"SonoffSC\":{")); + ResponseAppendTHD(t, h); + ResponseAppend_P(PSTR(",\"" D_JSON_LIGHT "\":%d,\"" D_JSON_NOISE "\":%d,\"" D_JSON_AIRQUALITY "\":%d}"), sc_value[2], sc_value[3], sc_value[4]); #ifdef USE_DOMOTICZ if (0 == tele_period) { - DomoticzTempHumSensor(temperature, humidity); + DomoticzTempHumPressureSensor(t, h); DomoticzSensor(DZ_ILLUMINANCE, sc_value[2]); DomoticzSensor(DZ_COUNT, sc_value[3]); DomoticzSensor(DZ_AIRQUALITY, 500 + ((100 - sc_value[4]) * 20)); @@ -141,8 +137,7 @@ void SonoffScShow(bool json) #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_TEMP, "", temperature, TempUnit()); - WSContentSend_PD(HTTP_SNS_HUM, "", humidity); + WSContentSend_THD("", t, h); WSContentSend_PD(HTTP_SNS_SCPLUS, sc_value[2], sc_value[3], sc_value[4]); #endif // USE_WEBSERVER } diff --git a/tasmota/xsns_06_dht.ino b/tasmota/xsns_06_dht.ino index e8488a96f..2edc4abfa 100644 --- a/tasmota/xsns_06_dht.ino +++ b/tasmota/xsns_06_dht.ino @@ -240,37 +240,7 @@ void DhtEverySecond(void) } } } -/* -void DhtShow(bool json) -{ - for (uint32_t i = 0; i < dht_sensors; i++) { - char temperature[33]; - dtostrfd(Dht[i].t, Settings.flag2.temperature_resolution, temperature); - char humidity[33]; - dtostrfd(Dht[i].h, Settings.flag2.humidity_resolution, humidity); - if (json) { - ResponseAppend_P(JSON_SNS_TEMPHUM, Dht[i].stype, temperature, humidity); -#ifdef USE_DOMOTICZ - if ((0 == tele_period) && (0 == i)) { - DomoticzTempHumSensor(temperature, humidity); - } -#endif // USE_DOMOTICZ -#ifdef USE_KNX - if ((0 == tele_period) && (0 == i)) { - KnxSensor(KNX_TEMPERATURE, Dht[i].t); - KnxSensor(KNX_HUMIDITY, Dht[i].h); - } -#endif // USE_KNX -#ifdef USE_WEBSERVER - } else { - WSContentSend_PD(HTTP_SNS_TEMP, Dht[i].stype, temperature, TempUnit()); - WSContentSend_PD(HTTP_SNS_HUM, Dht[i].stype, humidity); -#endif // USE_WEBSERVER - } - } -} -*/ void DhtShow(bool json) { for (uint32_t i = 0; i < dht_sensors; i++) { diff --git a/tasmota/xsns_07_sht1x.ino b/tasmota/xsns_07_sht1x.ino index e4b1796cb..3193f71ed 100644 --- a/tasmota/xsns_07_sht1x.ino +++ b/tasmota/xsns_07_sht1x.ino @@ -179,37 +179,7 @@ void ShtEverySecond(void) } } } -/* -void ShtShow(bool json) -{ - if (sht_valid) { - char temperature[33]; - dtostrfd(sht_temperature, Settings.flag2.temperature_resolution, temperature); - char humidity[33]; - dtostrfd(sht_humidity, Settings.flag2.humidity_resolution, humidity); - if (json) { - ResponseAppend_P(JSON_SNS_TEMPHUM, sht_types, temperature, humidity); -#ifdef USE_DOMOTICZ - if (0 == tele_period) { - DomoticzTempHumSensor(temperature, humidity); - } -#endif // USE_DOMOTICZ -#ifdef USE_KNX - if (0 == tele_period) { - KnxSensor(KNX_TEMPERATURE, sht_temperature); - KnxSensor(KNX_HUMIDITY, sht_humidity); - } -#endif // USE_KNX -#ifdef USE_WEBSERVER - } else { - WSContentSend_PD(HTTP_SNS_TEMP, sht_types, temperature, TempUnit()); - WSContentSend_PD(HTTP_SNS_HUM, sht_types, humidity); -#endif // USE_WEBSERVER - } - } -} -*/ void ShtShow(bool json) { if (sht_valid) { diff --git a/tasmota/xsns_08_htu21.ino b/tasmota/xsns_08_htu21.ino index 2cfaa0a59..14bfcaa50 100644 --- a/tasmota/xsns_08_htu21.ino +++ b/tasmota/xsns_08_htu21.ino @@ -237,37 +237,7 @@ void HtuEverySecond(void) } } } -/* -void HtuShow(bool json) -{ - if (htu_valid) { - char temperature[33]; - dtostrfd(htu_temperature, Settings.flag2.temperature_resolution, temperature); - char humidity[33]; - dtostrfd(htu_humidity, Settings.flag2.humidity_resolution, humidity); - if (json) { - ResponseAppend_P(JSON_SNS_TEMPHUM, htu_types, temperature, humidity); -#ifdef USE_DOMOTICZ - if (0 == tele_period) { - DomoticzTempHumSensor(temperature, humidity); - } -#endif // USE_DOMOTICZ -#ifdef USE_KNX - if (0 == tele_period) { - KnxSensor(KNX_TEMPERATURE, htu_temperature); - KnxSensor(KNX_HUMIDITY, htu_humidity); - } -#endif // USE_KNX -#ifdef USE_WEBSERVER - } else { - WSContentSend_PD(HTTP_SNS_TEMP, htu_types, temperature, TempUnit()); - WSContentSend_PD(HTTP_SNS_HUM, htu_types, humidity); -#endif // USE_WEBSERVER - } - } -} -*/ void HtuShow(bool json) { if (htu_valid) { diff --git a/tasmota/xsns_09_bmp.ino b/tasmota/xsns_09_bmp.ino index 220608160..7af6dc0b7 100644 --- a/tasmota/xsns_09_bmp.ino +++ b/tasmota/xsns_09_bmp.ino @@ -572,7 +572,7 @@ void BmpShow(bool json) #ifdef USE_DOMOTICZ if ((0 == tele_period) && (0 == bmp_idx)) { // We want the same first sensor to report to Domoticz in case a read is missed - DomoticzTempHumPressureSensor(temperature, humidity, pressure); + DomoticzTempHumPressureSensor(bmp_temperature, bmp_sensors[bmp_idx].bmp_humidity, bmp_pressure); #ifdef USE_BME680 if (bmp_sensors[bmp_idx].bmp_model >= 3) { DomoticzSensor(DZ_AIRQUALITY, (uint32_t)bmp_sensors[bmp_idx].bmp_gas_resistance); } #endif // USE_BME680 diff --git a/tasmota/xsns_14_sht3x.ino b/tasmota/xsns_14_sht3x.ino index 65bd1a4cf..4037f298a 100644 --- a/tasmota/xsns_14_sht3x.ino +++ b/tasmota/xsns_14_sht3x.ino @@ -91,45 +91,7 @@ void Sht3xDetect(void) } } } -/* -void Sht3xShow(bool json) -{ - for (uint32_t i = 0; i < sht3x_count; i++) { - float t; - float h; - if (Sht3xRead(t, h, sht3x_sensors[i].address)) { - char temperature[33]; - dtostrfd(t, Settings.flag2.temperature_resolution, temperature); - char humidity[33]; - dtostrfd(h, Settings.flag2.humidity_resolution, humidity); - char types[11]; - snprintf_P(types, sizeof(types), PSTR("%s%c0x%02X"), sht3x_sensors[i].types, IndexSeparator(), sht3x_sensors[i].address); // "SHT3X-0xXX" - if (json) { - ResponseAppend_P(JSON_SNS_TEMPHUM, types, temperature, humidity); -#ifdef USE_DOMOTICZ - if ((0 == tele_period) && (0 == i)) { // We want the same first sensor to report to Domoticz in case a read is missed - DomoticzTempHumSensor(temperature, humidity); - } -#endif // USE_DOMOTICZ - -#ifdef USE_KNX - if (0 == tele_period) { - KnxSensor(KNX_TEMPERATURE, t); - KnxSensor(KNX_HUMIDITY, h); - } -#endif // USE_KNX - -#ifdef USE_WEBSERVER - } else { - WSContentSend_PD(HTTP_SNS_TEMP, types, temperature, TempUnit()); - WSContentSend_PD(HTTP_SNS_HUM, types, humidity); -#endif // USE_WEBSERVER - } - } - } -} -*/ void Sht3xShow(bool json) { for (uint32_t i = 0; i < sht3x_count; i++) { diff --git a/tasmota/xsns_17_senseair.ino b/tasmota/xsns_17_senseair.ino index 27706a69f..dee516dff 100644 --- a/tasmota/xsns_17_senseair.ino +++ b/tasmota/xsns_17_senseair.ino @@ -142,27 +142,25 @@ void SenseairInit(void) void SenseairShow(bool json) { - char temperature[33]; - dtostrfd(senseair_temperature, Settings.flag2.temperature_resolution, temperature); - char humidity[33]; - dtostrfd(senseair_humidity, Settings.flag2.temperature_resolution, humidity); GetTextIndexed(senseair_types, sizeof(senseair_types), senseair_type -1, kSenseairTypes); if (json) { ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_CO2 "\":%d"), senseair_types, senseair_co2); if (senseair_type != 2) { - ResponseAppend_P(PSTR(",\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_HUMIDITY "\":%s"), temperature, humidity); + ResponseAppend_P(PSTR(",")); + ResponseAppendTHD(senseair_temperature, senseair_humidity); } ResponseJsonEnd(); #ifdef USE_DOMOTICZ - if (0 == tele_period) DomoticzSensor(DZ_AIRQUALITY, senseair_co2); + if (0 == tele_period) { + DomoticzSensor(DZ_AIRQUALITY, senseair_co2); + } #endif // USE_DOMOTICZ #ifdef USE_WEBSERVER } else { WSContentSend_PD(HTTP_SNS_CO2, senseair_types, senseair_co2); if (senseair_type != 2) { - WSContentSend_PD(HTTP_SNS_TEMP, senseair_types, temperature, TempUnit()); - WSContentSend_PD(HTTP_SNS_HUM, senseair_types, humidity); + WSContentSend_THD(senseair_types, senseair_temperature, senseair_humidity); } #endif // USE_WEBSERVER } diff --git a/tasmota/xsns_37_rfsensor.ino b/tasmota/xsns_37_rfsensor.ino index f07371f29..d58e06b66 100644 --- a/tasmota/xsns_37_rfsensor.ino +++ b/tasmota/xsns_37_rfsensor.ino @@ -311,17 +311,15 @@ void RfSnsTheoV2Show(bool json) } else { float temp = ConvertTemp((float)rfsns_theo_v2_t2[i].temp / 100); float humi = ConvertHumidity((float)rfsns_theo_v2_t2[i].hum / 100); - char temperature[33]; - dtostrfd(temp, Settings.flag2.temperature_resolution, temperature); - char humidity[33]; - dtostrfd(humi, Settings.flag2.humidity_resolution, humidity); if (json) { - ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_HUMIDITY "\":%s,\"" D_JSON_VOLTAGE "\":%s}"), - sensor, temperature, humidity, voltage); + ResponseAppend_P(PSTR(",\"%s\":{"), sensor); + ResponseAppendTHD(temp, humi); + ResponseAppend_P(PSTR(",\"" D_JSON_VOLTAGE "\":%s}"), voltage); + if ((0 == tele_period) && !sensor_once) { #ifdef USE_DOMOTICZ - DomoticzTempHumSensor(temperature, humidity); // + DomoticzTempHumPressureSensor(temp, humi); // #endif // USE_DOMOTICZ #ifdef USE_KNX KnxSensor(KNX_TEMPERATURE, temp); @@ -331,8 +329,7 @@ void RfSnsTheoV2Show(bool json) } #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_TEMP, sensor, temperature, TempUnit()); - WSContentSend_PD(HTTP_SNS_HUM, sensor, humidity); + WSContentSend_THD(sensor, temp, humi); #endif // USE_WEBSERVER } } @@ -556,11 +553,8 @@ void RfSnsAlectoV2Show(bool json) } } else { float temp = ConvertTemp(rfsns_alecto_v2->temp); - char temperature[33]; - dtostrfd(temp, Settings.flag2.temperature_resolution, temperature); float humi = ConvertHumidity((float)rfsns_alecto_v2->humi); - char humidity[33]; - dtostrfd(humi, Settings.flag2.humidity_resolution, humidity); + char rain[33]; dtostrfd(rfsns_alecto_v2->rain, 2, rain); char wind[33]; @@ -575,8 +569,10 @@ void RfSnsAlectoV2Show(bool json) } if (json) { - ResponseAppend_P(PSTR(",\"" D_ALECTOV2 "\":{\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_HUMIDITY "\":%s,\"Rain\":%s,\"Wind\":%s,\"Gust\":%s%s}"), - temperature, humidity, rain, wind, gust, (rfsns_alecto_v2->type) ? direction : ""); + ResponseAppend_P(PSTR(",\"" D_ALECTOV2 "\":{")); + ResponseAppendTHD(temp, humi); + ResponseAppend_P(PSTR(",\"Rain\":%s,\"Wind\":%s,\"Gust\":%s%s}"), rain, wind, gust, (rfsns_alecto_v2->type) ? direction : ""); + if (0 == tele_period) { #ifdef USE_DOMOTICZ // Use a rules to send data to Domoticz where also a local BMP280 is connected: @@ -587,8 +583,7 @@ void RfSnsAlectoV2Show(bool json) } #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_TEMP, D_ALECTOV2, temperature, TempUnit()); - WSContentSend_PD(HTTP_SNS_HUM, D_ALECTOV2, humidity); + WSContentSend_THD(D_ALECTOV2, temp, humi); WSContentSend_PD(HTTP_SNS_ALECTOV2, rain, wind, gust); if (rfsns_alecto_v2->type) { WSContentSend_PD(HTTP_SNS_ALECTOV2_WDIR, wdir); diff --git a/tasmota/xsns_38_az7798.ino b/tasmota/xsns_38_az7798.ino index 05afc7763..18705dce5 100644 --- a/tasmota/xsns_38_az7798.ino +++ b/tasmota/xsns_38_az7798.ino @@ -276,21 +276,17 @@ void AzInit(void) void AzShow(bool json) { - char temperature[33]; - dtostrfd(az_temperature, Settings.flag2.temperature_resolution, temperature); - char humidity[33]; - dtostrfd(az_humidity, Settings.flag2.humidity_resolution, humidity); - if (json) { - ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_CO2 "\":%d,\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_HUMIDITY "\":%s}"), ktype, az_co2, temperature, humidity); + ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_CO2 "\":%d,"), ktype, az_co2); + ResponseAppendTHD(az_temperature, az_humidity); + ResponseJsonEnd(); #ifdef USE_DOMOTICZ if (0 == tele_period) DomoticzSensor(DZ_AIRQUALITY, az_co2); #endif // USE_DOMOTICZ #ifdef USE_WEBSERVER } else { WSContentSend_PD(HTTP_SNS_CO2, ktype, az_co2); - WSContentSend_PD(HTTP_SNS_TEMP, ktype, temperature, TempUnit()); - WSContentSend_PD(HTTP_SNS_HUM, ktype, humidity); + WSContentSend_THD(ktype, az_temperature, az_humidity); #endif // USE_WEBSERVER } } diff --git a/tasmota/xsns_42_scd30.ino b/tasmota/xsns_42_scd30.ino index 267427c57..4a10fa8f0 100644 --- a/tasmota/xsns_42_scd30.ino +++ b/tasmota/xsns_42_scd30.ino @@ -362,28 +362,24 @@ void Scd30Show(bool json) { if (scd30IsDataValid) { - char humidity[10]; - dtostrfd(ConvertHumidity(scd30_Humid), Settings.flag2.humidity_resolution, humidity); - char temperature[10]; - dtostrfd(ConvertTemp(scd30_Temp), Settings.flag2.temperature_resolution, temperature); + float t = ConvertTemp(scd30_Temp); + float h = ConvertHumidity(scd30_Humid); if (json) { - //ResponseAppend_P(PSTR(",\"SCD30\":{\"" D_JSON_CO2 "\":%d,\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_HUMIDITY "\":%s}"), scd30_CO2, temperature, humidity); - ResponseAppend_P(PSTR(",\"SCD30\":{\"" D_JSON_CO2 "\":%d,\"" D_JSON_ECO2 "\":%d,\"" D_JSON_TEMPERATURE "\":%s,\"" D_JSON_HUMIDITY "\":%s}"), - scd30_CO2, scd30_CO2EAvg, temperature, humidity); + ResponseAppend_P(PSTR(",\"SCD30\":{\"" D_JSON_CO2 "\":%d,\"" D_JSON_ECO2 "\":%d,"), scd30_CO2, scd30_CO2EAvg); + ResponseAppendTHD(t, h); + ResponseJsonEnd(); #ifdef USE_DOMOTICZ - if (0 == tele_period) - { + if (0 == tele_period) { DomoticzSensor(DZ_AIRQUALITY, scd30_CO2); - DomoticzTempHumSensor(temperature, humidity); + DomoticzTempHumPressureSensor(t, h); } #endif // USE_DOMOTICZ #ifdef USE_WEBSERVER } else { WSContentSend_PD(HTTP_SNS_CO2EAVG, "SCD30", scd30_CO2EAvg); WSContentSend_PD(HTTP_SNS_CO2, "SCD30", scd30_CO2); - WSContentSend_PD(HTTP_SNS_TEMP, "SCD30", temperature, TempUnit()); - WSContentSend_PD(HTTP_SNS_HUM, "SCD30", humidity); + WSContentSend_THD("SCD30", t, h); #endif // USE_WEBSERVER } } diff --git a/tasmota/xsns_48_chirp.ino b/tasmota/xsns_48_chirp.ino index 3cd3afe6f..9606b419c 100644 --- a/tasmota/xsns_48_chirp.ino +++ b/tasmota/xsns_48_chirp.ino @@ -441,9 +441,7 @@ void ChirpShow(bool json) } #ifdef USE_DOMOTICZ if (0 == tele_period) { - char str_moisture[33]; - dtostrfd(chirp_sensor[i].moisture, 0, str_moisture); - DomoticzTempHumSensor(str_temperature, str_moisture); + DomoticzTempHumPressureSensor(t_temperature, chirp_sensor[i].moisture); DomoticzSensor(DZ_ILLUMINANCE,chirp_sensor[i].light); // this is not LUX!! } #endif // USE_DOMOTICZ diff --git a/tasmota/xsns_55_hih_series.ino b/tasmota/xsns_55_hih_series.ino index aef74dcf1..c108cce07 100644 --- a/tasmota/xsns_55_hih_series.ino +++ b/tasmota/xsns_55_hih_series.ino @@ -92,37 +92,7 @@ void Hih6EverySecond(void) } } } -/* -void Hih6Show(bool json) -{ - if (Hih6.valid) { - char temperature[33]; - dtostrfd(Hih6.temperature, Settings.flag2.temperature_resolution, temperature); - char humidity[33]; - dtostrfd(Hih6.humidity, Settings.flag2.humidity_resolution, humidity); - if (json) { - ResponseAppend_P(JSON_SNS_TEMPHUM, Hih6.types, temperature, humidity); -#ifdef USE_DOMOTICZ - if (0 == tele_period) { - DomoticzTempHumSensor(temperature, humidity); - } -#endif // USE_DOMOTICZ -#ifdef USE_KNX - if (0 == tele_period) { - KnxSensor(KNX_TEMPERATURE, Hih6.temperature); - KnxSensor(KNX_HUMIDITY, Hih6.humidity); - } -#endif // USE_KNX -#ifdef USE_WEBSERVER - } else { - WSContentSend_PD(HTTP_SNS_TEMP, Hih6.types, temperature, TempUnit()); - WSContentSend_PD(HTTP_SNS_HUM, Hih6.types, humidity); -#endif // USE_WEBSERVER - } - } -} -*/ void Hih6Show(bool json) { if (Hih6.valid) { diff --git a/tasmota/xsns_58_dht12.ino b/tasmota/xsns_58_dht12.ino index 8e34e14d5..55c78a486 100644 --- a/tasmota/xsns_58_dht12.ino +++ b/tasmota/xsns_58_dht12.ino @@ -86,37 +86,7 @@ void Dht12EverySecond(void) } } } -/* -void Dht12Show(bool json) -{ - if (Dht12.valid) { - char temperature[33]; - dtostrfd(Dht12.temperature, Settings.flag2.temperature_resolution, temperature); - char humidity[33]; - dtostrfd(Dht12.humidity, Settings.flag2.humidity_resolution, humidity); - if (json) { - ResponseAppend_P(JSON_SNS_TEMPHUM, Dht12.name, temperature, humidity); -#ifdef USE_DOMOTICZ - if ((0 == tele_period)) { - DomoticzTempHumSensor(temperature, humidity); - } -#endif // USE_DOMOTICZ -#ifdef USE_KNX - if (0 == tele_period) { - KnxSensor(KNX_TEMPERATURE, Dht12.temperature); - KnxSensor(KNX_HUMIDITY, Dht12.humidity); - } -#endif // USE_KNX -#ifdef USE_WEBSERVER - } else { - WSContentSend_PD(HTTP_SNS_TEMP, Dht12.name, temperature, TempUnit()); - WSContentSend_PD(HTTP_SNS_HUM, Dht12.name, humidity); -#endif // USE_WEBSERVER - } - } -} -*/ void Dht12Show(bool json) { if (Dht12.valid) { diff --git a/tasmota/xsns_63_aht1x.ino b/tasmota/xsns_63_aht1x.ino index d99457a44..97b16ff05 100644 --- a/tasmota/xsns_63_aht1x.ino +++ b/tasmota/xsns_63_aht1x.ino @@ -156,52 +156,7 @@ void AHT1XDetect(void) } } } -/* -void AHT1XShow(bool json) -{ - for (uint8_t i = 0; i < aht1x_count; i++) - { - float tem = ConvertTemp(aht1x_sensors[i].temperature); - float hum = ConvertHumidity(aht1x_sensors[i].humidity); - float dew = CalcTemHumToDew(aht1x_sensors[i].humidity, aht1x_sensors[i].temperature); - char types[11]; // AHT1X-0x38 - snprintf_P(types, sizeof(types), PSTR("%s%c0x%02X"), aht1x_sensors[i].types, IndexSeparator(), aht1x_sensors[i].address); // "X-0xXX" - char temperature[33]; - dtostrfd(tem, Settings.flag2.temperature_resolution, temperature); - char humidity[33]; - dtostrfd(hum, Settings.flag2.humidity_resolution, humidity); - char dewpoint[33]; - dtostrfd(dew, Settings.flag2.temperature_resolution, dewpoint); - - if (json) { - //ResponseAppend_P(JSON_SNS_TEMPHUM, types, temperature, humidity); - ResponseAppend_P(JSON_SNS_TEMPHUMDEW, types, temperature, humidity, dewpoint); - #ifdef USE_DOMOTICZ - if ((0 == tele_period) && (0 == i)); // <-- fails - { - DomoticzTempHumSensor(temperature, humidity); - } - #endif // USE_DOMOTICZ - #ifdef USE_KNX - if (0 == tele_period) - { - KnxSensor(KNX_TEMPERATURE, tem); - KnxSensor(KNX_HUMIDITY, hum); - } - #endif // USE_KNX - #ifdef USE_WEBSERVER - } - else - { - WSContentSend_PD(HTTP_SNS_TEMP, types, temperature, TempUnit()); - WSContentSend_PD(HTTP_SNS_HUM, types, humidity); - WSContentSend_PD(HTTP_SNS_DEW, types, dewpoint,TempUnit()); - #endif // USE_WEBSERVER - } - } -} -*/ void AHT1XShow(bool json) { for (uint32_t i = 0; i < aht1x_count; i++) { diff --git a/tasmota/xsns_65_hdc1080.ino b/tasmota/xsns_65_hdc1080.ino index bcba65ec5..86e82e7df 100644 --- a/tasmota/xsns_65_hdc1080.ino +++ b/tasmota/xsns_65_hdc1080.ino @@ -272,37 +272,6 @@ void HdcEverySecond(void) { * the MQTT messages, and so on. * */ -/* -void HdcShow(bool json) { - if (hdc_valid) { - char temperature[33]; - - dtostrfd(hdc_temperature, Settings.flag2.temperature_resolution, temperature); - char humidity[33]; - dtostrfd(hdc_humidity, Settings.flag2.humidity_resolution, humidity); - - if (json) { - ResponseAppend_P(JSON_SNS_TEMPHUM, hdc_type_name, temperature, humidity); -#ifdef USE_DOMOTICZ - if (0 == tele_period) { - DomoticzTempHumSensor(temperature, humidity); - } -#endif // USE_DOMOTICZ -#ifdef USE_KNX - if (0 == tele_period) { - KnxSensor(KNX_TEMPERATURE, hdc_temperature); - KnxSensor(KNX_HUMIDITY, hdc_humidity); - } -#endif // USE_KNX -#ifdef USE_WEBSERVER - } else { - WSContentSend_PD(HTTP_SNS_TEMP, hdc_type_name, temperature, TempUnit()); - WSContentSend_PD(HTTP_SNS_HUM, hdc_type_name, humidity); -#endif // USE_WEBSERVER - } - } -} -*/ void HdcShow(bool json) { if (hdc_valid) { TempHumDewShow(json, (0 == tele_period), hdc_type_name, hdc_temperature, hdc_humidity);