Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
gbrogna opened this issue Dec 31, 2018 · 21 comments
Closed

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

gbrogna opened this issue Dec 31, 2018 · 21 comments
Labels
good tip Type - Very useful information troubleshooting Type - Troubleshooting

Comments

@gbrogna
Copy link

gbrogna commented Dec 31, 2018

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
Copy link
Collaborator

Jason2866 commented Dec 31, 2018

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
Copy link
Author

gbrogna commented Dec 31, 2018

Thank you.

@gbrogna gbrogna closed this as completed Dec 31, 2018
@ascillato2 ascillato2 added good tip Type - Very useful information troubleshooting Type - Troubleshooting labels Jan 2, 2019
@jeroenst
Copy link
Contributor

jeroenst commented Feb 7, 2024

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.

arendst added a commit that referenced this issue Feb 18, 2024
@boozeman
Copy link

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
Copy link
Contributor

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

@sfromis
Copy link
Contributor

sfromis commented Feb 18, 2024

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
Copy link
Owner

arendst commented Feb 18, 2024

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
Copy link
Contributor

Thank you for implementing this feature!

@sfromis
Copy link
Contributor

sfromis commented Feb 18, 2024

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
Copy link

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
Copy link
Contributor

sfromis commented Feb 19, 2024

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
Copy link
Contributor

sfromis commented Feb 19, 2024

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

@sfromis
Copy link
Contributor

sfromis commented Feb 19, 2024

Also see #19666 for more generalized support for including units in the payloads, instead of the subscriber having to "know" this implicitly.

@arendst
Copy link
Owner

arendst commented Feb 19, 2024

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 added a commit that referenced this issue Feb 19, 2024
@arendst
Copy link
Owner

arendst commented Feb 19, 2024

Fixed

image

@boozeman
Copy link

boozeman commented Feb 19, 2024

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
Copy link
Contributor

sfromis commented Feb 19, 2024

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
Copy link
Contributor

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
Copy link
Owner

arendst commented Feb 22, 2024

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
Copy link
Contributor

sfromis commented Feb 22, 2024

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

image

@Noschvie
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good tip Type - Very useful information troubleshooting Type - Troubleshooting
Projects
None yet
Development

No branches or pull requests

9 participants