@@ -983,7 +983,7 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
983
983
add_ha_classes = false ;
984
984
break ;
985
985
default :
986
- // plain old sensor, and make it read-only
986
+ // plain old sensor
987
987
break ;
988
988
}
989
989
} else {
@@ -1117,10 +1117,19 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
1117
1117
strlcpy (sample_val, " false" , sizeof (sample_val)); // default is "false"
1118
1118
}
1119
1119
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 + " }}" ;
1121
1123
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
+ }
1124
1133
}
1125
1134
1126
1135
// Add the state class, device class and sometimes the icon.
0 commit comments