diff --git a/src/core/analogsensor.cpp b/src/core/analogsensor.cpp index 6c604d083..5a9e5ee06 100644 --- a/src/core/analogsensor.cpp +++ b/src/core/analogsensor.cpp @@ -729,7 +729,7 @@ void AnalogSensor::publish_values(const bool force) { } // 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 + "}}"; } diff --git a/src/core/mqtt.cpp b/src/core/mqtt.cpp index 1e2fba714..2f0966e8d 100644 --- a/src/core/mqtt.cpp +++ b/src/core/mqtt.cpp @@ -1019,7 +1019,7 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev std::string topic_str(topic); doc["def_ent_id"] = Helpers::toLower(topic_str.substr(0, topic_str.find("/"))) + "." + Helpers::toLower(uniq_id); - char sample_val[30] = "'None'"; // sample, correct(!) entity value, used only to prevent warning/error in HA if real value is not published yet + // char sample_val[30] = "'None'"; // sample, correct(!) entity value, used only to prevent warning/error in HA if real value is not published yet // we add the command topic parameter for commands if (has_cmd) { @@ -1136,10 +1136,11 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev doc["val_tpl"] = val_tpl; } else if (uom == DeviceValueUOM::UPTIME) { // uptime - doc["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else 'None' }}"; + doc["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else 'None'}}"; } else { // default - doc["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else " + sample_val + "}}"; + // doc["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else " + sample_val + "}}"; + doc["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else 'None'}}"; } add_ha_avty_section(doc.as(), stat_t, val_cond); // adds availability section } else { diff --git a/src/core/shower.cpp b/src/core/shower.cpp index 9c6552c32..b12a961d9 100644 --- a/src/core/shower.cpp +++ b/src/core/shower.cpp @@ -229,7 +229,7 @@ void Shower::create_ha_discovery() { // don't bother with value template conditions if using Domoticz which doesn't fully support MQTT Discovery if (Mqtt::discovery_type() == Mqtt::discoveryType::HOMEASSISTANT) { - doc["val_tpl"] = "{{value_json.duration if value_json.duration is defined else 0}}"; + doc["val_tpl"] = "{{value_json.duration if value_json.duration is defined else 'None'}}"; } else { doc["val_tpl"] = "{{value_json.duration}}"; } diff --git a/src/core/temperaturesensor.cpp b/src/core/temperaturesensor.cpp index 437aac353..868567318 100644 --- a/src/core/temperaturesensor.cpp +++ b/src/core/temperaturesensor.cpp @@ -543,7 +543,7 @@ void TemperatureSensor::publish_values(const bool force) { // for the value template, there's a problem still with Domoticz probably due to the special characters. // See https://github.com/emsesp/EMS-ESP32/issues/1360 if (Mqtt::discovery_type() == Mqtt::discoveryType::HOMEASSISTANT) { - config["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else -55}}"; + config["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else 'None'}}"; } else { config["val_tpl"] = (std::string) "{{" + val_obj + "}}"; // omit value conditional Jinja2 template code } diff --git a/src/web/WebCustomEntityService.cpp b/src/web/WebCustomEntityService.cpp index de3c03dcf..4f9512fcb 100644 --- a/src/web/WebCustomEntityService.cpp +++ b/src/web/WebCustomEntityService.cpp @@ -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 + "}}"; } diff --git a/src/web/WebSchedulerService.cpp b/src/web/WebSchedulerService.cpp index 230d3250b..f7dcc1e85 100644 --- a/src/web/WebSchedulerService.cpp +++ b/src/web/WebSchedulerService.cpp @@ -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 }