arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
21.84k stars 4.75k forks source link

Retrieve Heat Index from DHT22 (AM2301(2)) Sensor #4771

Closed gbrogna closed 5 years ago

gbrogna commented 5 years ago

I reviewed the WIKI and searched considerably and I found no reference to retrieving the Heat Index from a DHT22 sensor. I am wondering if there is an away or can it be added?

I retrieve the heat index using a regular Arduino sketch

float t = dht.readTemperature(true);
dtostrf(t, 4, 2, msg);
client.publish("Thermostat/Master/Temperature", msg);
Serial.print("Temperature: ");
Serial.println(msg);

float h = dht.readHumidity();
dtostrf(h, 4, 2, msg);
client.publish("Thermostat/Master/Humidity", msg);
Serial.print("Humidity: ");
Serial.println(msg);

float hif = dht.computeHeatIndex(t, h);
dtostrf(hif, 4, 2, msg);
client.publish("Thermostat/Master/HeatIndex", msg);
Serial.print("Heat Index: ");
Serial.println(msg);

Thank you in advance and I hope I did not miss anything

Jason2866 commented 5 years ago

Heat Index is calculated through the Adafruit library in your example. It is not a sensor value This library in not used in Tasmota You can calculate in your Home Automation System.

hi = 0.5 * (temperature + 61.0 + ((temperature - 68.0) * 1.2) + (percentHumidity * 0.094));

if (hi > 79) {
    hi = -42.379 +
             2.04901523 * temperature +
            10.14333127 * percentHumidity +
            -0.22475541 * temperature*percentHumidity +
            -0.00683783 * pow(temperature, 2) +
            -0.05481717 * pow(percentHumidity, 2) +
             0.00122874 * pow(temperature, 2) * percentHumidity +
             0.00085282 * temperature*pow(percentHumidity, 2) +
            -0.00000199 * pow(temperature, 2) * pow(percentHumidity, 2);

    if((percentHumidity < 13) && (temperature >= 80.0) && (temperature <= 112.0))
      hi -= ((13.0 - percentHumidity) * 0.25) * sqrt((17.0 - abs(temperature - 95.0)) * 0.05882);

    else if((percentHumidity > 85.0) && (temperature >= 80.0) && (temperature <= 87.0))
      hi += ((percentHumidity - 85.0) * 0.1) * ((87.0 - temperature) * 0.2);
  }
gbrogna commented 5 years ago

Thank you.

jeroenst commented 6 months ago

The Dew point value is also not a sensor value but it is calculated and displayed by Tasmota. I would also like to have the heat index value available in Tasmota beside the dew point value.

So a vote for this functionality from me.

boozeman commented 6 months ago

Hi,

Seems like heat Index do not include any information of the unit of measurement, so It works nicely in Tasmota screen, but Home Assistant do not know what measurement type is so the history looks like this: image

Seems like it does not know the TempUnit: "C/F" on mqtt message json?

barbudor commented 6 months ago

This is by design, only units that can be changed are explit Other units are assumed

sfromis commented 6 months ago

In general, it is up to HA to "know" what unit applies to each value, but when there is a sensor with "Temperature", the default temperature unit of Tasmota, C/F, should already be included in the sensor payload. In HA, this is not linked to HeatIndex, as hatasmota has a table of what sensor names are which unit, and possibly HeatIndex should be processed the same way as DewPoint.

One question may be if the heat index calculation above is in C or F, or works for both. The many "magic numbers" suggests that the formula may be for Fahrenheit. If this speculation is correct, it would be needed to make sure that Tasmota can calculate HeatIndex for both types of temperature units, before it would work well to have hatasmota "know" that the TempUnit field in the JSON applies.

arendst commented 6 months ago

Don't worry. HeatIndex, just like Dewpoint adjusts to Fahrenheit AND celsius as other temperature results.

The above code is just part of the final Tasmota implementation.

jeroenst commented 6 months ago

Thank you for implementing this feature!

sfromis commented 6 months ago

Then, next step could be to fix hatasmota to include this.

Or maybe open the old can of worms about Tasmota being able to report units with the various sensor values, instead of the subscriber needing to know all those units by itself.

boozeman commented 6 months ago

One more pic for the situation here: image

When I looked at the matter more closely and with rested eyes, I noticed that the decimal separator is a dot and not a comma as we here in northern Europe tend to use. There is probably a reason to make some changes to the code so that users don't have to make manual MQTT sensors that take into account the unit of measure and the decimal separator?

And Thanks for the brilliant work!

sfromis commented 6 months ago

Here's what I'm seeing in Tasmota: image Unit is included, and a space in the name instead of the key. I suppose that your screenshot is not from Tasmota, thus next step is not up to what happens in Tasmota, but maybe hatasmota which I already hinted at a couple of times.

sfromis commented 6 months ago

I was surprised to not see the heat index for BME280, with it appearing for other sensors. image

sfromis commented 6 months ago

Also see https://github.com/arendst/Tasmota/discussions/19666 for more generalized support for including units in the payloads, instead of the subscriber having to "know" this implicitly.

arendst commented 6 months ago

Ha. I noticed yesterday the BMP/E code indeed doesn't use the generic TempHum functions. I guess because not all BMP's support humidity but looking briefly at the code I couldn't understand how the humidity was handled.

Will investigate today (again).

arendst commented 6 months ago

Fixed

image

boozeman commented 6 months ago

Here's what I'm seeing in Tasmota:

Yeah, It is on HA > Devices > Tasmota > Greenhouse1.
image Readings are allright on Tasmota web gui.

I don't see any weird stuff on mqtt json either. Tasmota Discovey is active

{ "Time": "2024-02-19T20:42:05", "Switch1": "ON", "Switch2": "ON", "BME280": { "Temperature": 11.7, "Humidity": 38.7, "DewPoint": -1.9, "Pressure": 1006.5, "SeaPressure": 1018.3 }, "SHT3X": { "Temperature": 9.7, "Humidity": 45.9, "DewPoint": -1.4, "HeatIndex": 8 }, "HX711": { "Weight": 0.5, "WeightRaw": 3276, "AbsRaw": 58975 }, "PressureUnit": "hPa", "TempUnit": "C" }

I am trying to understand here why all other measured values work like a charm directly on HA with Tasmota discovery but if I want to get HeatIndex as a temperature, I have to make manual mqtt_sensor on it.

It is no big deal. I am just curious :)

sfromis commented 6 months ago

Again, it is because hatasmota (the Tasmota Integration feature of HA) has a table to select which JSON field names (like Humidity) has what unit of measurement, as those are nowhere in the JSON. Hence it does not "know" what HeatIndex is about.

Noschvie commented 5 months ago

Shall the HeatIndex be added for the SCD40 / 41 sensor too?


{
   "Time":"2024-02-22T07:08:49",
   "SCD40":{
      "CarbonDioxide":409,
      "eCO2":409,
      "Temperature":25.1,
      "Humidity":42.3,
      "DewPoint":11.4
   },
   "TempUnit":"C"
}
arendst commented 5 months ago

It should have been there. If not I’ll fix it asap. It should be everywhere where dewpoint is too.

Note: it’s only there if enabled at compile time. Default disabled on esp8266 as too much code space.

sfromis commented 5 months ago

It is already there with SCD40, as long as you do a build to include the feature. #define USE_HEAT_INDEX

image

Noschvie commented 5 months ago

Ok. This compile option wasn't noted in this issue so far.