val_tpl for undefined: 'None'

This commit is contained in:
MichaelDvP
2026-08-16 10:16:34 +02:00
parent 48c118fed7
commit 574c4e45d5
6 changed files with 9 additions and 8 deletions
+1 -1
View File
@@ -501,7 +501,7 @@ void WebCustomEntityService::publish(const bool force) {
snprintf(val_cond, sizeof(val_cond), "%s is defined", val_obj);
// don't bother with value template conditions if using Domoticz which doesn't fully support MQTT Discovery
if (Mqtt::discovery_type() == Mqtt::discoveryType::HOMEASSISTANT) {
config["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + "}}";
config["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else 'None'}}";
} else {
config["val_tpl"] = (std::string) "{{" + val_obj + "}}";
}
+1 -1
View File
@@ -275,7 +275,7 @@ void WebSchedulerService::publish(const bool force) {
char val_tpl[150];
if (Mqtt::discovery_type() == Mqtt::discoveryType::HOMEASSISTANT) {
snprintf(val_tpl, sizeof(val_tpl), "{{%s if %s}}", val_obj, val_cond);
snprintf(val_tpl, sizeof(val_tpl), "{{%s if %s else 'None'}}", val_obj, val_cond);
} else {
snprintf(val_tpl, sizeof(val_tpl), "{{%s}}", val_obj); // omit value conditional Jinja2 template code
}