diff --git a/src/dallassensor.cpp b/src/dallassensor.cpp index 10577f5c8..80f1c0348 100644 --- a/src/dallassensor.cpp +++ b/src/dallassensor.cpp @@ -326,7 +326,8 @@ void DallasSensor::publish_values(const bool force) { uint8_t sensor_no = 1; // dallas format is overriden when using Home Assistant - uint8_t dallas_format = Mqtt::ha_enabled() ? Mqtt::Dallas_Format::NUMBER : Mqtt::dallas_format(); + // uint8_t dallas_format = Mqtt::ha_enabled() ? Mqtt::Dallas_Format::NUMBER : Mqtt::dallas_format(); + uint8_t dallas_format = Mqtt::dallas_format(); for (const auto & sensor : sensors_) { char sensorID[10]; // sensor{1-n} @@ -359,11 +360,19 @@ void DallasSensor::publish_values(const bool force) { config["unit_of_meas"] = FJSON("°C"); char str[50]; - snprintf_P(str, sizeof(str), PSTR("{{value_json.sensor%d.temp}}"), sensor_no); + if (dallas_format == Mqtt::Dallas_Format::SENSORID) { + snprintf_P(str, sizeof(str), PSTR("{{value_json.%s}}"), sensor.to_string().c_str()); + } else { + snprintf_P(str, sizeof(str), PSTR("{{value_json.sensor%d.temp}}"), sensor_no); + } config["val_tpl"] = str; // name as sensor number not the long unique ID - snprintf_P(str, sizeof(str), PSTR("Dallas Sensor %d"), sensor_no); + if (dallas_format == Mqtt::Dallas_Format::SENSORID) { + snprintf_P(str, sizeof(str), PSTR("Dallas Sensor %s"), sensor.to_string().c_str()); + } else { + snprintf_P(str, sizeof(str), PSTR("Dallas Sensor %d"), sensor_no); + } config["name"] = str; snprintf_P(str, sizeof(str), PSTR("dallas_%s"), sensor.to_string().c_str());