Skip to content

Commit

Permalink
Add Dew point to more sensors
Browse files Browse the repository at this point in the history
Add Dew point to more sensors and refactor JSON Temperature and Humidity message
  • Loading branch information
arendst committed Mar 17, 2020
1 parent b00baae commit 0a0afe3
Show file tree
Hide file tree
Showing 21 changed files with 88 additions and 354 deletions.
2 changes: 0 additions & 2 deletions tasmota/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
Expand Down
14 changes: 13 additions & 1 deletion tasmota/support.ino
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ float ConvertHumidity(float h)

global_update = uptime;
global_humidity = h;

result = result + (0.1 * Settings.hum_comp);

return result;
Expand Down Expand Up @@ -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("}"));
Expand Down
18 changes: 5 additions & 13 deletions tasmota/support_tasmota.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand Down
1 change: 1 addition & 0 deletions tasmota/tasmota_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions tasmota/xdrv_01_webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 17 additions & 11 deletions tasmota/xdrv_07_domoticz.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down
15 changes: 5 additions & 10 deletions tasmota/xsns_04_snfsc.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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
}
Expand Down
30 changes: 0 additions & 30 deletions tasmota/xsns_06_dht.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
32 changes: 1 addition & 31 deletions tasmota/xsns_07_sht1x.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
32 changes: 1 addition & 31 deletions tasmota/xsns_08_htu21.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tasmota/xsns_09_bmp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 0 additions & 38 deletions tasmota/xsns_14_sht3x.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
14 changes: 6 additions & 8 deletions tasmota/xsns_17_senseair.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit 0a0afe3

Please sign in to comment.