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'",
61 const bool no_temperature{std::isnan(this->
temperature_)};
62 const bool no_humidity{std::isnan(this->
humidity_)};
63 if (no_temperature || no_humidity) {
65 ESP_LOGW(TAG,
"No valid state from temperature sensor!");
68 ESP_LOGW(TAG,
"No valid state from humidity sensor!");
77 const float temperature_k{temperature_c + 273.15f};
94 this->
status_set_error(LOG_STR(
"Invalid saturation vapor pressure equation selection!"));
99 const float absolute_humidity{
vapor_density(es, hr, temperature_k)};
101 ESP_LOGD(TAG,
"Saturation vapor pressure %f kPa, absolute humidity %f g/m³", es, absolute_humidity);
112 if (temperature_c >= 0.0f) {
123 return a * expf((b - (temperature_c / c)) * (temperature_c / (d + temperature_c)));
129 if (temperature_c >= 0.0f) {
136 return 0.61078f * expf((a * temperature_c) / (temperature_c + b));
155 constexpr float c0{+0.99999683e+00f};
156 constexpr float c1{-0.90826951e-02f};
157 constexpr float c2{+0.78736169e-04f};
158 constexpr float c3{-0.61117958e-06f};
159 constexpr float c4{+0.43884187e-08f};
160 constexpr float c5{-0.29883885e-10f};
161 constexpr float c6{+0.21874425e-12f};
162 constexpr float c7{-0.17892321e-14f};
163 constexpr float c8{+0.11112018e-16f};
164 constexpr float c9{-0.30994571e-19f};
165 const float p{c0 + t * (c1 + t * (c2 + t * (c3 + t * (c4 + t * (c5 + t * (c6 + t * (c7 + t * (c8 + t * (c9)))))))))};
166 return 0.61078f / powf(p, 8.0f);
177 const float ea{hr * es * 1000.0f};
178 const float mw{18.01528f};
179 const float r{8.31446261815324f};
180 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 LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
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.
ESPHOME_LOG_TAG(TAG, "absolute_humidity.sensor")