Add chip temperature sensor and RGB LED control, verified live in HA

Quick end-to-end data-flow proof using only what's on the ESP32-C6-
DevKitC-1 itself (no sensors on the bare devkit -- confirmed via
research: BOOT button, WS2812 LED, no external sensors):

- drivers::chip_temperature_* wraps ESP-IDF's built-in
  temperature_sensor driver (SoC die temperature).
- drivers::rgb_led_* wraps the onboard WS2812 (GPIO8) via the
  espressif/led_strip managed component (another external registry
  dependency, like mdns/mqtt).
- profiles::ChipTemperatureSensor is the first real implementation of
  the Sensor interface designed earlier, converting the driver's float
  reading to the fixed-point convention once at the boundary.
- transport/mqtt.cpp publishes chip temperature as an HA "temperature"
  sensor every 30s, and exposes the LED as an HA "light" entity
  (rgb_command_topic) -- the first use of MQTT subscribe in this
  project, not just publish.

Added a ChipTemperature SensorChannel (distinct from
AmbientTemperature -- different meaning/range) to sensor.h.

Verified live: both the chip temperature reading and LED color control
work from Home Assistant against the real device.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Ronny Eia
2026-07-10 19:27:00 +02:00
parent 1bdc19b695
commit 4af0f1b248
16 changed files with 395 additions and 5 deletions

View File

@@ -1,3 +1,5 @@
idf_component_register(
REQUIRES sensors
SRCS "src/chip_temperature_sensor.cpp"
INCLUDE_DIRS "include"
REQUIRES sensors drivers
)

View File

@@ -1,3 +1,7 @@
# profiles
Exposes reusable sensor/actuator capabilities (reed switch, hall sensor, push button, pulse counter, analog input, DS18B20, BME280, leak sensor, PIR, generic I2C device) to the Lua runtime, backed by `sensors`. `REQUIRES sensors`.
Concrete `Sensor` implementations live here (not in `sensors`, which owns the shared interface/types), and reach down to `drivers` directly for the actual hardware access -- `sensors` is the shared contract, not a mandatory pass-through. `REQUIRES drivers` too.
- `ChipTemperatureSensor` (`include/chip_temperature_sensor.h`) -- the first real `Sensor` implementation, wrapping `drivers::chip_temperature_*` (the ESP32-C6's internal die temperature). Added to get real data flowing end-to-end (drivers -> profiles -> transport/MQTT) before more sensor types exist.

View File

@@ -0,0 +1,28 @@
#pragma once
#include "sensor.h"
namespace kvida {
// First real implementation of the Sensor interface (see
// components/sensors/include/sensor.h) -- wraps the ESP32-C6's internal
// die temperature sensor (kvida::drivers::chip_temperature_*).
class ChipTemperatureSensor : public Sensor {
public:
const char *id() const override { return "chip_temperature"; }
void begin() override;
bool supports(SensorChannel channel) const override
{
return channel == SensorChannel::ChipTemperature;
}
bool fetch() override;
bool get(SensorChannel channel, SensorValue &out) override;
private:
bool fetched_ = false;
SensorValue last_{};
};
} // namespace kvida

View File

@@ -0,0 +1,36 @@
#include "chip_temperature_sensor.h"
#include "chip_temperature.h"
namespace kvida {
void ChipTemperatureSensor::begin()
{
drivers::chip_temperature_init();
}
bool ChipTemperatureSensor::fetch()
{
float celsius = drivers::chip_temperature_read_celsius();
// Convert to the fixed-point convention (val1 + val2 * 1e-6) once, at
// the boundary where the underlying driver hands us a float --
// ESP32-C6 has no hardware FPU, see sensor.h.
auto val1 = static_cast<int32_t>(celsius);
auto val2 = static_cast<int32_t>((celsius - static_cast<float>(val1)) * 1000000.0f);
last_ = SensorValue{val1, val2, "C", 0};
fetched_ = true;
return true;
}
bool ChipTemperatureSensor::get(SensorChannel channel, SensorValue &out)
{
if (!fetched_ || channel != SensorChannel::ChipTemperature) {
return false;
}
out = last_;
return true;
}
} // namespace kvida