This commit is contained in:
proddy
2025-04-22 16:07:22 +02:00
parent 71726530c0
commit c6b0099581
6 changed files with 42 additions and 20 deletions

View File

@@ -594,7 +594,12 @@ void AnalogSensor::publish_values(const bool force) {
if (sensor.type() == AnalogType::DIGITAL_IN || sensor.type() == AnalogType::DIGITAL_OUT) {
Helpers::render_boolean(sample_val, false);
}
config["val_tpl"] = (std::string) "{{" + val_obj + " if " + val_cond + " else " + sample_val + "}}";
// 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 + "}}";
} else {
config["val_tpl"] = (std::string) "{{" + val_obj + "}}";
}
char uniq_s[70];
if (Mqtt::entity_format() == Mqtt::entityFormat::MULTI_SHORT) {

View File

@@ -222,8 +222,15 @@ void Shower::set_shower_state(bool state, bool force) {
snprintf(stat_t, sizeof(stat_t), "%s/shower_data", Mqtt::base().c_str());
doc["stat_t"] = stat_t;
doc["name"] = "Shower Duration";
doc["val_tpl"] = "{{value_json.duration if value_json.duration is defined else 0}}";
doc["name"] = "Shower Duration";
// 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}}";
} else {
doc["val_tpl"] = "{{value_json.duration}}";
}
doc["unit_of_meas"] = "s";
doc["stat_cla"] = "measurement";
doc["dev_cla"] = "duration";