6static const uint8_t MCP9808_REG_AMBIENT_TEMP = 0x05;
7static const uint8_t MCP9808_REG_MANUF_ID = 0x06;
8static const uint8_t MCP9808_REG_DEVICE_ID = 0x07;
10static const uint16_t MCP9808_MANUF_ID = 0x0054;
11static const uint16_t MCP9808_DEV_ID = 0x0400;
13static const uint8_t MCP9808_AMBIENT_CLEAR_FLAGS = 0x1F;
14static const uint8_t MCP9808_AMBIENT_CLEAR_SIGN = 0x0F;
15static const uint8_t MCP9808_AMBIENT_TEMP_NEGATIVE = 0x10;
25 if (manu != MCP9808_MANUF_ID) {
26 ESP_LOGE(TAG,
"Incorrect manufacturer ID (%X) for '%s'", manu, LOG_STR_ARG(this->
get_log_name()));
31 if (!this->
read_byte_16(MCP9808_REG_DEVICE_ID, &dev_id)) {
35 if (dev_id != MCP9808_DEV_ID) {
36 ESP_LOGE(TAG,
"Incorrect device ID (%X) for '%s'", dev_id, LOG_STR_ARG(this->
get_log_name()));
42 ESP_LOGCONFIG(TAG,
"%s:", LOG_STR_ARG(this->
get_log_name()));
44 LOG_UPDATE_INTERVAL(
this);
45 LOG_SENSOR(
" ",
"Temperature",
this);
53 if (raw_temp == 0xFFFF) {
59 uint8_t msb = (uint8_t) ((
raw_temp & 0xff00) >> 8);
62 msb = msb & MCP9808_AMBIENT_CLEAR_FLAGS;
64 if ((msb & MCP9808_AMBIENT_TEMP_NEGATIVE) == MCP9808_AMBIENT_TEMP_NEGATIVE) {
65 msb = msb & MCP9808_AMBIENT_CLEAR_SIGN;
66 temp = (256 - ((uint16_t) (msb) * 16 + lsb / 16.0f)) * -1;
68 temp = (uint16_t) (msb) * 16 + lsb / 16.0f;
74 ESP_LOGD(TAG,
"%s: Got temperature=%.4f°C", LOG_STR_ARG(this->
get_log_name()), temp);
void mark_failed()
Mark this component as failed.
void status_set_warning()
bool status_comm_result(bool ok)
Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
bool read_byte_16(uint8_t a_register, uint16_t *data)
void dump_config() override
void publish_state(float state)
Publish a new state to the front-end.
ESPHOME_LOG_TAG(TAG, "mcp9808")