Skip to content

Commit 60ac6aa

Browse files
committed
remove template logic for Domoticz -#2156
1 parent 5a37517 commit 60ac6aa

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/mqtt.cpp

+13-4
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
983983
add_ha_classes = false;
984984
break;
985985
default:
986-
// plain old sensor, and make it read-only
986+
// plain old sensor
987987
break;
988988
}
989989
} else {
@@ -1117,10 +1117,19 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
11171117
strlcpy(sample_val, "false", sizeof(sample_val)); // default is "false"
11181118
}
11191119

1120-
doc["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else " + sample_val + "}}";
1120+
// don't bother with value template conditions if using Domoticz which doesn't fully support MQTT Discovery
1121+
if (discovery_type() == discoveryType::HOMEASSISTANT) {
1122+
doc["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else " + sample_val + "}}";
11211123

1122-
// add the dev json object to the end, not for commands
1123-
add_ha_sections_to_doc(nullptr, stat_t, doc, false, val_cond); // no name, since the "dev" has already been adde
1124+
// adds availability, dev, ids to the config section to HA Discovery config
1125+
// except for commands
1126+
add_ha_sections_to_doc(nullptr, stat_t, doc, false, val_cond); // no name, since the "dev" has already been added
1127+
} else {
1128+
// Domoticz doesn't support value templates, so we just use the value directly
1129+
// Also omit the uom and other state classes
1130+
doc["val_tpl"] = (std::string) "{{" + val_obj + "}}";
1131+
add_ha_classes = false; // don't add the classes
1132+
}
11241133
}
11251134

11261135
// Add the state class, device class and sometimes the icon.

0 commit comments

Comments
 (0)