This commit is contained in:
michael
2026-01-18 20:26:17 +01:00
parent f2f5ae7b8f
commit 6e1288dca0
7 changed files with 24 additions and 9 deletions

View File

@@ -56,7 +56,7 @@ void ClassFlowMQTT::SetInitialParameter(void)
mqtt_controll_config.validateServerCert = true;
mqtt_controll_config.clientname = network_config.hostname;
mqtt_controll_config.OldValue = "";
mqtt_controll_config.oldValue = "";
mqtt_controll_config.user = "";
mqtt_controll_config.password = "";
@@ -362,10 +362,12 @@ bool ClassFlowMQTT::doFlow(std::string time)
if (name_temp == "default")
{
// e.g. watermeter/default/
name_temp = mqtt_controll_config.maintopic + "/";
}
else
{
// e.g. watermeter/main/
name_temp = mqtt_controll_config.maintopic + "/" + name_temp + "/";
}
@@ -404,6 +406,7 @@ bool ClassFlowMQTT::doFlow(std::string time)
if (change_absolute_temp.length() > 0)
{
// e.g. _key = watermeter/main/changeabsolut, _content = change_absolute_temp, _qos = 1, retained_flag = mqtt_controll_config.retainFlag
success |= MQTTPublish(name_temp + "changeabsolut", change_absolute_temp, qos, mqtt_controll_config.retainFlag); // Legacy API
success |= MQTTPublish(name_temp + "rate_per_digitization_round", change_absolute_temp, qos, mqtt_controll_config.retainFlag);
}
@@ -423,7 +426,7 @@ bool ClassFlowMQTT::doFlow(std::string time)
}
}
mqtt_controll_config.OldValue = value_temp;
mqtt_controll_config.oldValue = value_temp;
if (!success)
{

View File

@@ -28,7 +28,7 @@ typedef struct
std::string topicTimeStamp;
std::string topicUptime;
std::string topicFreeMem;
std::string OldValue;
std::string oldValue;
std::string user;
std::string password;

View File

@@ -79,6 +79,15 @@ std::string ClassFlowPostProcessing::getJsonFromNumber(int i, std::string _linee
{
json += " \"rate\": \"\"," + _lineend;
}
if (NUMBERS[i]->ReturnChangeAbsolute.length() > 0)
{
json += " \"absrate\": \"" + NUMBERS[i]->ReturnChangeAbsolute + "\"," + _lineend;
}
else
{
json += " \"absrate\": \"\"," + _lineend;
}
json += " \"timestamp\": \"" + NUMBERS[i]->timeStamp + "\"" + _lineend;
json += " }" + _lineend;

View File

@@ -31,6 +31,7 @@ int MQTTReconnectCnt = 0;
void (*callbackOnConnected)(std::string, bool) = NULL;
// e.g. _key = watermeter/main/rate_per_digitization_round, _content = change_absolute_temp, _qos = 1, retained_flag = mqtt_controll_config.retainFlag
bool MQTTPublish(std::string _key, std::string _content, int qos, bool retained_flag)
{
if (!mqtt_controll_config.mqtt_enabled)

View File

@@ -92,10 +92,10 @@ bool sendHomeAssistantDiscoveryTopic(std::string group, std::string field, std::
/* See https://www.home-assistant.io/docs/mqtt/discovery/ */
std::string payload = string("{") + "\"~\": \"" + mqtt_controll_config.maintopic + "\"," +
"\"unique_id\": \"" + mqtt_controll_config.maintopic + "-" + configTopic + "\"," +
"\"name\": \"" + name + "\"," + "\"icon\": \"mdi:" + icon + "\"," +
"\"object_id\": \"" + mqtt_controll_config.maintopic + "_" + configTopic + "\"," + // Default entity ID; required for HA <= 2025.10
"\"default_entity_id\": \"" + component + "." + mqtt_controll_config.maintopic + "_" + configTopic + "\"," + // Default entity ID; required in HA >=2026.4
"\"name\": \"" + name + "\"," + "\"icon\": \"mdi:" + icon + "\",";
"\"unique_id\": \"" + mqtt_controll_config.maintopic + "-" + configTopic + "\",";
if (group != "")
{
@@ -224,7 +224,7 @@ bool MQTThomeassistantDiscovery(int qos)
/* Not announcing "rate" as it is better to use rate_per_time_unit resp. rate_per_digitization_round */
// allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "rate", "Rate (Unit/Minute)", "swap-vertical", "", "", "", "", qos); // Legacy, always Unit per Minute
allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "rate_per_time_unit", "Rate (" + mqtt_controll_config.rateUnit + ")", "swap-vertical", mqtt_controll_config.rateUnit, rate_device_class, "measurement", "", qos);
allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "rate_per_digitization_round", "Change since last Digitization round", "arrow-expand-vertical", mqtt_controll_config.valueUnit, "", "measurement", "", qos); // correctly the Unit is Unit/Interval!
allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "rate_per_digitization_round", "Change since last Digitization round", "arrow-expand-vertical", mqtt_controll_config.valueUnit, rate_device_class, "measurement", "", qos); // correctly the Unit is Unit/Interval!
allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "timestamp", "Timestamp", "clock-time-eight-outline", "", "timestamp", "", "diagnostic", qos);
allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "json", "JSON", "code-json", "", "", "", "diagnostic", qos);
allSendsSuccessed |= sendHomeAssistantDiscoveryTopic(group, "problem", "Problem", "alert-outline", "", "problem", "", "", qos); // Special binary sensor which is based on error topic

View File

@@ -130,6 +130,7 @@
}
.tooltip {
min-width:15px;
position: relative;
display: inline-block;
}
@@ -250,9 +251,9 @@
<div id="divall" style="display:none">
<table class="table">
<colgroup>
<col span="1" style="width:45%;">
<col span="1" style="width:45%;">
<col span="1" style="width:10%;">
<col span="1" style="width:50%;">
<col span="1" style="width:47%;">
<col span="1" style="width:3%;">
</colgroup>
<tr style="border-bottom: 2px solid lightgray;">

View File

@@ -51,6 +51,7 @@
}
.tooltip {
min-width:15px;
position: relative;
display: inline-block;
}