5 #if defined(USE_ESP32_VARIANT_ESP32) 10 #elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) 11 #include "driver/temp_sensor.h" 12 #endif // USE_ESP32_VARIANT 24 namespace internal_temperature {
26 static const char *
const TAG =
"internal_temperature";
32 #if defined(USE_ESP32_VARIANT_ESP32) 34 ESP_LOGV(TAG,
"Raw temperature value: %d", raw);
35 temperature = (raw - 32) / 1.8f;
36 success = (raw != 128);
37 #elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) 38 temp_sensor_config_t tsens = TSENS_CONFIG_DEFAULT();
39 temp_sensor_set_config(tsens);
41 #if defined(USE_ESP32_VARIANT_ESP32S3) && (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 4, 3)) 43 "ESP32-S3 internal temperature sensor requires ESP IDF V4.4.3 or higher. See https://github.com/esphome/issues/issues/4271" 45 esp_err_t result = temp_sensor_read_celsius(&temperature);
47 success = (result == ESP_OK);
48 #endif // USE_ESP32_VARIANT 51 temperature = analogReadTemp();
52 success = (temperature != 0.0f);
57 success = (result == 0);
58 #if defined(USE_LIBRETINY_VARIANT_BK7231N) 59 temperature = raw * -0.38f + 156.0f;
60 #elif defined(USE_LIBRETINY_VARIANT_BK7231T) 61 temperature = raw * 0.04f;
62 #else // USE_LIBRETINY_VARIANT 63 temperature = raw * 0.128f;
64 #endif // USE_LIBRETINY_VARIANT 66 if (success && std::isfinite(temperature)) {
69 ESP_LOGD(TAG,
"Ignoring invalid temperature (success=%d, value=%.1f)", success, temperature);
uint8_t temprature_sens_read()
void dump_config() override
void publish_state(float state)
Publish a new state to the front-end.
Implementation of SPI Controller mode.
bool has_state() const
Return whether this sensor has gotten a full state (that passed through all filters) yet...
uint32_t temp_single_get_current_temperature(uint32_t *temp_value)