Skip to content

Commit

Permalink
remove field name from HA discovery for single-field messages
Browse files Browse the repository at this point in the history
  • Loading branch information
john30 committed Oct 26, 2024
1 parent 0dd3a80 commit 619f15d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* add option to discover device via mDNS
* add dedicated log level for device messages
* add option to extend MQTT variables from env/cmdline
* add date+datetime mapping and better device update check to Home Assistant MQTT discovery integration
* add date+datetime mapping, better device update check, and removed single-field-message field names to Home Assistant MQTT discovery integration

## Breaking Changes
* change default config path to https://ebus.github.io/ serving files generated from new TypeSpec message definition sources
Expand Down
3 changes: 2 additions & 1 deletion contrib/etc/ebusd/mqtt-hassio.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
# %field the field name and key for JSON objects (equals the field index if no name is defined or the names are not
# unique in the message).
# %fieldname the field name (and nothing else like in %field, might be empty though!)
# %fieldnamemult the field name unless there is a single field only (similar to %fieldname)
# %type the field type (one of "number", "list", "string", "date", "time", or "datetime").
# %basetype the base data type ID (e.g. "UCH").
# %comment the field comment (if any).
Expand Down Expand Up @@ -350,7 +351,7 @@ definition-topic ?= %haprefix/%type_topic/%{TOPIC}_%FIELD/config
# HA integration: this is the config topic payload for HA's MQTT discovery.
definition-payload = {
"unique_id":"%{TOPIC}_%FIELD",
"name":"%name %fieldname",
"name":"%name %fieldnamemult",
"device":%circuit_part,
"value_template":"{{value_json[\"%field\"].value}}",
"state_topic":"%topic"%field_payload
Expand Down
4 changes: 3 additions & 1 deletion src/ebusd/mqtthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,9 @@ void MqttHandler::run() {
StringReplacers values = msgValues; // need a copy here as the contents are manipulated
values.set("index", static_cast<signed>(index));
values.set("field", fieldName);
values.set("fieldname", field->getName(-1));
string fieldNameNonUnique = field->getName(-1);
values.set("fieldname", fieldNameNonUnique);
values.set("fieldnamemult", fieldCount == 1 ? "" : fieldNameNonUnique);
values.set("type", typeStr);
values.set("type_map", str);
values.set("basetype", dataType->getId());
Expand Down

0 comments on commit 619f15d

Please sign in to comment.