5#if defined(USE_ESP32_VARIANT_ESP32)
10#elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || \
11 defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32H2) || \
12 defined(USE_ESP32_VARIANT_ESP32C2) || defined(USE_ESP32_VARIANT_ESP32P4)
13#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
14#include "driver/temp_sensor.h"
16#include "driver/temperature_sensor.h"
30namespace internal_temperature {
32static const char *
const TAG =
"internal_temperature";
34#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) && \
35 (defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S2) || \
36 defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32H2) || defined(USE_ESP32_VARIANT_ESP32C2) || \
37 defined(USE_ESP32_VARIANT_ESP32P4))
38static temperature_sensor_handle_t tsensNew = NULL;
46#if defined(USE_ESP32_VARIANT_ESP32)
48 ESP_LOGV(TAG,
"Raw temperature value: %d",
raw);
50 success = (
raw != 128);
51#elif defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || \
52 defined(USE_ESP32_VARIANT_ESP32S2) || defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32H2) || \
53 defined(USE_ESP32_VARIANT_ESP32C2) || defined(USE_ESP32_VARIANT_ESP32P4)
54#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
55 temp_sensor_config_t tsens = TSENS_CONFIG_DEFAULT();
56 temp_sensor_set_config(tsens);
58#if defined(USE_ESP32_VARIANT_ESP32S3) && (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4, 4, 3))
60 "ESP32-S3 internal temperature sensor requires ESP IDF V4.4.3 or higher. See https://github.com/esphome/issues/issues/4271"
62 esp_err_t result = temp_sensor_read_celsius(&
temperature);
64 success = (result == ESP_OK);
66 esp_err_t result = temperature_sensor_get_celsius(tsensNew, &
temperature);
67 success = (result == ESP_OK);
69 ESP_LOGE(TAG,
"Failed to get temperature: %d", result);
81 success = (result == 0);
82#if defined(USE_LIBRETINY_VARIANT_BK7231N)
84#elif defined(USE_LIBRETINY_VARIANT_BK7231T)
93 ESP_LOGD(TAG,
"Ignoring invalid temperature (success=%d, value=%.1f)", success,
temperature);
102#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)) && \
103 (defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32C6) || defined(USE_ESP32_VARIANT_ESP32S2) || \
104 defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32H2) || defined(USE_ESP32_VARIANT_ESP32C2) || \
105 defined(USE_ESP32_VARIANT_ESP32P4))
106 ESP_LOGCONFIG(TAG,
"Setting up temperature sensor...");
108 temperature_sensor_config_t tsens_config = TEMPERATURE_SENSOR_CONFIG_DEFAULT(-10, 80);
110 esp_err_t result = temperature_sensor_install(&tsens_config, &tsensNew);
111 if (result != ESP_OK) {
112 ESP_LOGE(TAG,
"Failed to install temperature sensor: %d", result);
117 result = temperature_sensor_enable(tsensNew);
118 if (result != ESP_OK) {
119 ESP_LOGE(TAG,
"Failed to enable temperature sensor: %d", result);
virtual void mark_failed()
Mark this component as failed.
void dump_config() override
void publish_state(float state)
Publish a new state to the front-end.
bool has_state() const
Return whether this sensor has gotten a full state (that passed through all filters) yet.
uint8_t temprature_sens_read()
uint32_t temp_single_get_current_temperature(uint32_t *temp_value)
Providing packet encoding functions for exchanging data with a remote host.