6static const char *
const TAG{
"absolute_humidity.sensor"};
31 LOG_SENSOR(
"",
"Absolute Humidity",
this);
35 ESP_LOGCONFIG(TAG,
"Saturation Vapor Pressure Equation: Buck");
38 ESP_LOGCONFIG(TAG,
"Saturation Vapor Pressure Equation: Tetens");
41 ESP_LOGCONFIG(TAG,
"Saturation Vapor Pressure Equation: Wobus");
44 ESP_LOGE(TAG,
"Invalid saturation vapor pressure equation selection!");
50 " Temperature: '%s'\n"
51 " Relative Humidity: '%s'",
60 const bool no_temperature{std::isnan(this->
temperature_)};
61 const bool no_humidity{std::isnan(this->
humidity_)};
62 if (no_temperature || no_humidity) {
64 ESP_LOGW(TAG,
"No valid state from temperature sensor!");
67 ESP_LOGW(TAG,
"No valid state from humidity sensor!");
76 const float temperature_k{temperature_c + 273.15f};
93 this->
status_set_error(LOG_STR(
"Invalid saturation vapor pressure equation selection!"));
98 const float absolute_humidity{
vapor_density(es, hr, temperature_k)};
100 ESP_LOGD(TAG,
"Saturation vapor pressure %f kPa, absolute humidity %f g/m³", es, absolute_humidity);
111 if (temperature_c >= 0.0f) {
122 return a * expf((b - (temperature_c / c)) * (temperature_c / (d + temperature_c)));
128 if (temperature_c >= 0.0f) {
135 return 0.61078f * expf((a * temperature_c) / (temperature_c + b));
154 constexpr float c0{+0.99999683e+00f};
155 constexpr float c1{-0.90826951e-02f};
156 constexpr float c2{+0.78736169e-04f};
157 constexpr float c3{-0.61117958e-06f};
158 constexpr float c4{+0.43884187e-08f};
159 constexpr float c5{-0.29883885e-10f};
160 constexpr float c6{+0.21874425e-12f};
161 constexpr float c7{-0.17892321e-14f};
162 constexpr float c8{+0.11112018e-16f};
163 constexpr float c9{-0.30994571e-19f};
164 const float p{c0 + t * (c1 + t * (c2 + t * (c3 + t * (c4 + t * (c5 + t * (c6 + t * (c7 + t * (c8 + t * (c9)))))))))};
165 return 0.61078f / powf(p, 8.0f);
176 const float ea{hr * es * 1000.0f};
177 const float mw{18.01528f};
178 const float r{8.31446261815324f};
179 return (ea * mw) / (r * ta);
void status_set_warning()
void enable_loop()
Enable this component's loop.
void disable_loop()
Disable this component's loop.
void status_clear_warning()
const StringRef & get_name() const
constexpr const char * c_str() const
sensor::Sensor * humidity_sensor_
static float es_buck(float temperature_c)
Buck equation for saturation vapor pressure in kPa.
static float es_tetens(float temperature_c)
Tetens equation for saturation vapor pressure in kPa.
static float vapor_density(float es, float hr, float ta)
Calculate vapor density (absolute humidity) in g/m³.
static float es_wobus(float temperature_c)
Wobus equation for saturation vapor pressure in kPa.
void dump_config() override
sensor::Sensor * temperature_sensor_
SaturationVaporPressureEquation equation_
void add_on_state_callback(F &&callback)
Add a callback that will be called every time a filtered value arrives.
void publish_state(float state)
Publish a new state to the front-end.
float get_state() const
Getter-syntax for .state.
float state
This member variable stores the last state that has passed through all filters.