I have a number of DHT22 sensors on some NodeMCU’s around my house. I calibrated them and then fixed the offset in Home Assistant using a value_template. It works well however whenever the NodeMCU goes unavailable for some reason the value_template offset gets calculated wrong. Normally, it just adds the offset to the sensor value and everything is great, but when it is unavailable the value_template just reports the offset itself.
Has anyone experienced this, is this how it is supposed to function or am I doing something wrong?
As an alternative you could move the offset to the ESPHome device itself and remove the template sensor. Sounds as if you are looking for the offset filter.
I can only assume that your value template was written in a way that the temperature sensor’s value is interpreted as zero when the device becomes unavailable, so effectively the template’s value becomes 0 + offset = offset.
To circumvent this behaviour you could change your value template and surround the offset calculation with a check if the sensor is currently available; if not, output something else.
However, I think calculating the offset on the device is the cleanest solution.
I’m running into a similar situation in that the output from the DHT sensor isn’t accurate. I think the ultimate fix is is to go with a more accurate sensor but lacking that I like the idea of using the filter in ESPHome.
One question on that tho.
I use substitutions to create an individualized frmware file for each device based on a common file for the device type.
Do you know if ESPHome can accept substitutions of the filter values?
I like the “calibrate_linear” filter for a better calibration of the output and I’m pretty sure I wouldn’t end up with the filter values being identical for each device. I’m not really sure how I could logically enter those values into a substitution.
@finity how do you calibrate your DHT sensors? I don’t know how accurate mine are because I don’t really know how to get a golden source and make a good test setup.
What I ended up doing is getting all of the sensors I have (6) and put them right next to each other and then take the average value and calibrate each sensor to that. I don’t know if this is the “right” value or not, but it is the best I can think of.
@exxamalte You are probably right. I think I just copied an example of this I found on the forums. What would you suggest? If the value was made null or something if the sensor is unavailable, would that fix the problem?
I’m going to keep the offset on the device like you say, but I just want to try to understand this a bit better if possible.
As I said, I’d recommend to calculate the offset on the ESP.
BTW: Last year I dumped all my DHT22 sensors, mainly because humidity was unreliable, and replaced them all with BME280 sensors. These are slightly more expensive, but much more reliable and give you temperature, humidity and air pressure.
See below for how I ultimately corrected mine in the ESPHome config. The correction occurs in the “lambda” filter which changes the measurement from Celsius to Fahrenheit and then adds 0.1 degree offset.
Probably the “offset” filter is the correct one to use. I didn’t know if the offset would be added before or after the lambda calculation, is the only reason I didn’t use it.
Anyone now how to pu a minimun value f the sensor? I have a current sensor and when is 0 it appears as -0.01A and I would like to put 0.00A as min value (min_value: 0.00 doesn´t seem to work). Thank you
Maybe someaone could help aswell since it is the callibration topic. So I have the PH sensor which is calibrated initially with the calibrate_linear in ESPHOME. How can I calibrate the sensor afterwards using some HA commands to change the calibrate linear values and update the ESPHOME node?