Hi, I have not been using Home Assistant for long and have been enjoying using esphome to make my own sensors. I have a BME680 sensor and have used the example at https://esphome.io/cookbook/bme280_environment.html to help me to learn the programming as I am new to yaml and c++.
The example calculates “absolute humidity” using the following equation:
so I have adapted the variable names a bit in my project, and I want to have the “dew point” calculated using the equation at https://planetcalc.com/248/.
I am having a problem because the compiler errors on the log function:
src/main.cpp:639:46: error: invalid operands of types 'esphome::template_::TemplateSensor*' and 'float' to binary 'operator+'
return ( (b *(dpinter + logf (rh->state)) )/( a - (dpinter + logf (rh->state)) ) );
I have been told I should include the math.h library but am not sure how.
Can some please tell me how to do this - I assume I have to download it from somewhere?
I can provide more info if needed, but have tried to keep the posting short.
This is very interesting and quite an eye opener for me. Did you by any chance try to convert the air pressure at your location to something like QNH? I have done it easily with an RPi but never got around to doing any mathematical functions like you have done because I didn’t know it could be done.
You can do most things with a lambda which is c++. Have a look at following which is not the answer but a flavour. I don’t bother, because I am at sea level. Well just above MHW!
Nott that relative pressure is (still) wrong on Esp’shome page for BME280.
BME280’s absolute pressure output has already temperature taken into account, so having it in relative pressure formula again is wrong. I wrote about that years ago and i’m really surprised that noone seems to notice or care…
When i used that formula my relative pressure changed quite a bit from (colf) morning, through (warm) day and into the (again colder) night, although absolute pressure was the same all along ( also compared with high quality device, and with local official weather station’s data)
I have mainly been interested in humidity stuff and have found that there is often considerable variation between different sensors. I am located 85m above sea level, am not a pilot, and only just googled QNH.
Thanks for the response. I have a BMP388 and am trying that. My elevation is 574 meters but it was a few hPa out so I used 600 meters for elevation. I will let it run for a few days and keep track of the QNH as we have an airport about 30 kms away that reports it. I had to fiddle with the figures in my Python code on the RPi so it looks similar to that.
I use this code for relative pressure - it’s a formula, taken from BME180 datasheet. On later datasheets it was for some reason removed (but it still works):
Thanks. I used your version (without temp) and used my altitude and it is only out less than a hPa (around 0.6 hPa and I am about 25 km from the airport). The other version was not so good and it was out by a few hPa.
Hi, these lambdas worked perfectly for me with my bme280. With the newest version and switching to bmw280_i2c I get the following compilation errors. What else needs to be changed to get the lambdas working again?
/config/esphome/ble-tracker.yaml: In lambda function:
/config/esphome/ble-tracker.yaml:140:65: error: 'class esphome::bme280_i2c::BME280I2CComponent' has no member named 'state'; did you mean 'update'?
(id(bme280_temperature).state + 243.5)) * id(bme280_humidity).state * mw) /
^~~~~
update
/config/esphome/ble-tracker.yaml: In lambda function:
/config/esphome/ble-tracker.yaml:149:43: error: 'class esphome::bme280_i2c::BME280I2CComponent' has no member named 'state'; did you mean 'update'?
return (243.5*(log(id(bme280_humidity).state/100)+((17.67*id(bme280_temperature).state)/
^~~~~
update
/config/esphome/ble-tracker.yaml:150:71: error: 'class esphome::bme280_i2c::BME280I2CComponent' has no member named 'state'; did you mean 'update'?
(243.5+id(bme280_temperature).state)))/(17.67-log(id(bme280_humidity).state/100)-
^~~~~
update