9static constexpr uint32_t CONVERSION_TIMEOUT_ID = 0;
11static const uint8_t DALLAS_MODEL_DS18S20 = 0x10;
12static const uint8_t DALLAS_MODEL_DS18B20 = 0x28;
13static const uint8_t DALLAS_COMMAND_START_CONVERSION = 0x44;
14static const uint8_t DALLAS_COMMAND_READ_SCRATCH_PAD = 0xBE;
15static const uint8_t DALLAS_COMMAND_WRITE_SCRATCH_PAD = 0x4E;
16static const uint8_t DALLAS_COMMAND_COPY_SCRATCH_PAD = 0x48;
32 ESP_LOGCONFIG(TAG,
"Dallas Temperature Sensor:");
34 ESP_LOGW(TAG,
" Unable to select an address");
37 LOG_ONE_WIRE_DEVICE(
this);
38 ESP_LOGCONFIG(TAG,
" Resolution: %u bits", this->
resolution_);
39 LOG_UPDATE_INTERVAL(
this);
57 ESP_LOGD(TAG,
"'%s': Got Temperature=%f°C", LOG_STR_ARG(this->
get_log_name()), tempc);
63 bool success = this->
send_command_(DALLAS_COMMAND_READ_SCRATCH_PAD);
69 ESP_LOGW(TAG,
"'%s' - reading scratch pad failed bus reset", LOG_STR_ARG(this->
get_log_name()));
83 if ((this->
address_ & 0xff) == DALLAS_MODEL_DS18S20) {
85 ESP_LOGW(TAG,
"DS18S20 doesn't support setting resolution");
122 const bool chksum_validity = (crc == this->
scratch_pad_[8]);
124#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_DEBUG
126 if (ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_VERY_VERBOSE || !chksum_validity)
129 ESP_LOGVV(TAG,
"Scratch pad: %s (%02X)", hex_buf, crc);
130 if (!chksum_validity) {
132 ESP_LOGD(TAG,
"Scratch pad: %s (%02X)", hex_buf, crc);
134 return chksum_validity;
139 if ((this->
address_ & 0xff) == DALLAS_MODEL_DS18S20) {
161 if ((this->
address_ & 0xff) == DALLAS_MODEL_DS18B20) {
162 if ((temp == 85 * 16) && (this->
scratch_pad_[6] == 0xc)) {
163 ESP_LOGD(TAG,
"dropping reading caused by sensor reset");
void status_set_warning()
void set_timeout(const char *name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a const char* name.
void status_clear_warning()
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
uint16_t millis_to_wait_for_conversion_() const
Get the number of milliseconds we have to wait for the conversion phase.
bool check_scratch_pad_()
void dump_config() override
virtual void write8(uint8_t val)=0
Write a word to the bus. LSB first.
virtual uint8_t read8()=0
Read an 8 bit word from the bus.
OneWireBus * bus_
pointer to OneWireBus instance
bool send_command_(uint8_t cmd)
send command on the bus
bool check_address_or_index_()
find an address if necessary should be called from setup
void publish_state(float state)
Publish a new state to the front-end.
ESPHOME_LOG_TAG(TAG, "dallas.temp.sensor")
char * format_hex_pretty_to(char *buffer, size_t buffer_size, const uint8_t *data, size_t length, char separator)
Format byte array as uppercase hex to buffer (base implementation).
constexpr T encode_value_le(const uint8_t *bytes)
Encode a value from its constituent bytes (from least to most significant) in an array with length si...
constexpr size_t format_hex_pretty_size(size_t byte_count)
Calculate buffer size needed for format_hex_pretty_to with separator: "XX:XX:...:XX\0".
uint8_t crc8(const uint8_t *data, uint8_t len, uint8_t crc, uint8_t poly, bool msb_first)
Calculate a CRC-8 checksum of data with size len.