mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
dallassensor HA-Format also with ID
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user