(C) Copyright 2021-22 Magnus Persson
\ No newline at end of file
diff --git a/src/pushtarget.cpp b/src/pushtarget.cpp
index 7a8c838..e992719 100644
--- a/src/pushtarget.cpp
+++ b/src/pushtarget.cpp
@@ -416,9 +416,9 @@ void PushTarget::sendHttpGet(TemplatingEngine& engine, bool isSecure) {
//
// Send data to mqtt target
//
-void PushTarget::sendMqtt(TemplatingEngine& engine, bool isSecure) {
+void PushTarget::sendMqtt(TemplatingEngine& engine, bool isSecure, bool skipHomeAssistantRegistration) {
#if !defined(PUSH_DISABLE_LOGGING)
- Log.notice(F("PUSH: Sending values to mqtt." CR));
+ Log.notice(F("PUSH: Sending values to mqtt. Skip HA registration %s" CR), skipHomeAssistantRegistration ? "yes" : "no");
#endif
_lastCode = 0;
_lastSuccess = false;
@@ -483,15 +483,20 @@ void PushTarget::sendMqtt(TemplatingEngine& engine, bool isSecure) {
Log.verbose(F("PUSH: topic '%s', value '%s'." CR), topic.c_str(),
value.c_str());
#endif
- if (mqtt.publish(topic, value)) {
- _lastSuccess = true;
- Log.notice(F("PUSH: MQTT publish successful on %s" CR), topic.c_str());
- _lastCode = 0;
+
+ if (skipHomeAssistantRegistration && topic.startsWith("homeassistant/sensor/")) {
+ Log.notice(F("PUSH: Ignoring Home Assistant registration topic %s" CR), topic.c_str());
} else {
- _lastCode = mqtt.lastError();
- ErrorFileLog errLog;
- errLog.addEntry("PUSH: MQTT push on " + topic +
- " failed error=" + String(mqtt.lastError()));
+ if (mqtt.publish(topic, value)) {
+ _lastSuccess = true;
+ Log.notice(F("PUSH: MQTT publish successful on %s" CR), topic.c_str());
+ _lastCode = 0;
+ } else {
+ _lastCode = mqtt.lastError();
+ ErrorFileLog errLog;
+ errLog.addEntry("PUSH: MQTT push on " + topic +
+ " failed error=" + String(mqtt.lastError()));
+ }
}
index = next + 1;
diff --git a/src/pushtarget.hpp b/src/pushtarget.hpp
index 02b2485..3e56163 100644
--- a/src/pushtarget.hpp
+++ b/src/pushtarget.hpp
@@ -61,7 +61,7 @@ class PushTarget {
sendHttpGet(engine, isSecure);
}
void sendInfluxDb2(TemplatingEngine& engine, bool isSecure);
- void sendMqtt(TemplatingEngine& engine, bool isSecure);
+ void sendMqtt(TemplatingEngine& engine, bool isSecure, bool skipHomeAssistantRegistration = true);
int getLastCode() { return _lastCode; }
bool getLastSuccess() { return _lastSuccess; }
};
diff --git a/src/webserver.cpp b/src/webserver.cpp
index 8dca1a5..46a3fc5 100644
--- a/src/webserver.cpp
+++ b/src/webserver.cpp
@@ -947,7 +947,7 @@ void WebServerHandler::webHandleTestPush() {
push.sendInfluxDb2(engine, myConfig.isInfluxSSL());
enabled = true;
} else if (!type.compareTo(PARAM_FORMAT_MQTT) && myConfig.isMqttActive()) {
- push.sendMqtt(engine, myConfig.isMqttSSL());
+ push.sendMqtt(engine, myConfig.isMqttSSL(), false);
enabled = true;
}
diff --git a/src_docs/source/releases.rst b/src_docs/source/releases.rst
index 30978b3..0c01dd0 100644
--- a/src_docs/source/releases.rst
+++ b/src_docs/source/releases.rst
@@ -17,6 +17,7 @@ Documentation
User interface
++++++++++++++
+* (beta3) Changed behavior for Home Assistant Device registration, this is only done when format template is saved, during normal operation only data values are posted on MQTT.
* (beta2) Calibration temperature (for temp adjustment) can now be set under advanced settings.
* (beta2) Changes length of device name from 12 to 63 chars. 63 is the max limit according to mdns.
* Under format options its now possible to select brewfather ispindle format to avoid mixing endpoints.