From 4cd0a9d9b171221ab3fd14cd830fe58b92cf1861 Mon Sep 17 00:00:00 2001 From: gneluka Date: Fri, 25 Oct 2024 12:05:15 +0200 Subject: [PATCH 1/9] initial changes to add domoticz support --- .../jomjol_flowcontroll/ClassFlowMQTT.cpp | 14 ++++ .../jomjol_flowcontroll/ClassFlowMQTT.h | 4 +- .../components/jomjol_mqtt/interface_mqtt.cpp | 5 +- code/components/jomjol_mqtt/interface_mqtt.h | 2 +- code/components/jomjol_mqtt/server_mqtt.cpp | 8 ++- code/components/jomjol_mqtt/server_mqtt.h | 3 + .../parameter-pages/MQTT/DomoticzTopicIn.md | 6 ++ .../MQTT/NUMBER.DomoticzIDX.md | 4 ++ sd-card/html/edit_config_template.html | 70 +++++++++++++++++++ sd-card/html/readconfigparam.js | 2 + 10 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 param-docs/parameter-pages/MQTT/DomoticzTopicIn.md create mode 100644 param-docs/parameter-pages/MQTT/NUMBER.DomoticzIDX.md diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp index 797491f6e..8a85fb25c 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp @@ -51,6 +51,8 @@ void ClassFlowMQTT::SetInitialParameter(void) ListFlowControll = NULL; disabled = false; keepAlive = 25*60; + domoticzIdx = 0; + domoticzintopic = ""; } ClassFlowMQTT::ClassFlowMQTT() @@ -185,6 +187,17 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph) { maintopic = splitted[1]; } + + if (((toUpper(splitted[0]) == "DOMOTICZTOPICIN")) && (splitted.size() > 1)) + { + this->domoticzintopic = splitted[1]; + } + + if (((toUpper(splitted[0]) == "DOMOTICZIDX")) && (splitted.size() > 1)) + { + this->domoticzIdx = stoi(splitted[1]); + } + } /* Note: @@ -193,6 +206,7 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph) * To work around this, we delay the start and trigger it from ClassFlowControll::ReadParameter() */ mqttServer_setMainTopic(maintopic); + mqttServer_setDmoticzInTopic(domoticzintopic); return true; } diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.h b/code/components/jomjol_flowcontroll/ClassFlowMQTT.h index 7f89fbdf7..c62d8419e 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.h +++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.h @@ -23,8 +23,8 @@ class ClassFlowMQTT : bool SetRetainFlag; int keepAlive; // Seconds float roundInterval; // Minutes - - std::string maintopic; + int domoticzIdx; + std::string maintopic, domoticzintopic; void SetInitialParameter(void); public: diff --git a/code/components/jomjol_mqtt/interface_mqtt.cpp b/code/components/jomjol_mqtt/interface_mqtt.cpp index cb7a0ce44..ced320f21 100644 --- a/code/components/jomjol_mqtt/interface_mqtt.cpp +++ b/code/components/jomjol_mqtt/interface_mqtt.cpp @@ -34,7 +34,7 @@ bool mqtt_initialized = false; bool mqtt_connected = false; esp_mqtt_client_handle_t client = NULL; -std::string uri, client_id, lwt_topic, lwt_connected, lwt_disconnected, user, password, maintopic; +std::string uri, client_id, lwt_topic, lwt_connected, lwt_disconnected, user, password, maintopic, domoticz_in_topic; std::string caCert, clientCert, clientKey; int keepalive; bool SetRetainFlag; @@ -205,7 +205,7 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_ bool MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, - std::string _maintopic, std::string _lwt, std::string _lwt_connected, std::string _lwt_disconnected, + std::string _maintopic, std::string _domoticz_in_topic, std::string _lwt, std::string _lwt_connected, std::string _lwt_disconnected, std::string _cacertfilename, std::string _clientcertfilename, std::string _clientkeyfilename, int _keepalive, bool _SetRetainFlag, void *_callbackOnConnected) { if ((_mqttURI.length() == 0) || (_maintopic.length() == 0) || (_clientid.length() == 0)) @@ -222,6 +222,7 @@ bool MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _us keepalive = _keepalive; SetRetainFlag = _SetRetainFlag; maintopic = _maintopic; + domoticz_in_topic = _domoticz_in_topic; callbackOnConnected = ( void (*)(std::string, bool) )(_callbackOnConnected); if (_clientcertfilename.length() && _clientkeyfilename.length()){ diff --git a/code/components/jomjol_mqtt/interface_mqtt.h b/code/components/jomjol_mqtt/interface_mqtt.h index b2e736e45..79544736a 100644 --- a/code/components/jomjol_mqtt/interface_mqtt.h +++ b/code/components/jomjol_mqtt/interface_mqtt.h @@ -10,7 +10,7 @@ #include bool MQTT_Configure(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, - std::string _maintopic, std::string _lwt, std::string _lwt_connected, std::string _lwt_disconnected, + std::string _maintopic, std::string _domoticz_in_topic, std::string _lwt, std::string _lwt_connected, std::string _lwt_disconnected, std::string _cacertfilename, std::string _clientcertfilename, std::string _clientkeyfilename, int _keepalive, bool SetRetainFlag, void *callbackOnConnected); int MQTT_Init(); diff --git a/code/components/jomjol_mqtt/server_mqtt.cpp b/code/components/jomjol_mqtt/server_mqtt.cpp index 7c7591d0b..a4fb76e0f 100644 --- a/code/components/jomjol_mqtt/server_mqtt.cpp +++ b/code/components/jomjol_mqtt/server_mqtt.cpp @@ -32,10 +32,11 @@ std::string rateUnit = "Unit/Minute"; float roundInterval; // Minutes int keepAlive = 0; // Seconds bool retainFlag; -static std::string maintopic; +static std::string maintopic, domoticzintopic; bool sendingOf_DiscoveryAndStaticTopics_scheduled = true; // Set it to true to make sure it gets sent at least once after startup + void mqttServer_setParameter(std::vector* _NUMBERS, int _keepAlive, float _roundInterval) { NUMBERS = _NUMBERS; keepAlive = _keepAlive; @@ -355,4 +356,9 @@ std::string mqttServer_getMainTopic() { return maintopic; } +void mqttServer_setDmoticzInTopic( std::string _domoticzintopic) { + domoticzintopic = _domoticzintopic; +} + + #endif //ENABLE_MQTT diff --git a/code/components/jomjol_mqtt/server_mqtt.h b/code/components/jomjol_mqtt/server_mqtt.h index 41c359c98..2754b4049 100644 --- a/code/components/jomjol_mqtt/server_mqtt.h +++ b/code/components/jomjol_mqtt/server_mqtt.h @@ -12,6 +12,9 @@ void mqttServer_setParameter(std::vector* _NUMBERS, int interval, f void mqttServer_setMeterType(std::string meterType, std::string valueUnit, std::string timeUnit,std::string rateUnit); void setMqtt_Server_Retain(bool SetRetainFlag); void mqttServer_setMainTopic( std::string maintopic); +void mqttServer_setDmoticzInTopic( std::string domoticzintopic); + + std::string mqttServer_getMainTopic(); void register_server_mqtt_uri(httpd_handle_t server); diff --git a/param-docs/parameter-pages/MQTT/DomoticzTopicIn.md b/param-docs/parameter-pages/MQTT/DomoticzTopicIn.md new file mode 100644 index 000000000..d5add179d --- /dev/null +++ b/param-docs/parameter-pages/MQTT/DomoticzTopicIn.md @@ -0,0 +1,6 @@ +# Parameter `DomoticzTopicIn` +Default Value: `domoticz/in` + +MQTT IN topic for Domoticz integration, under which the counters are published. + +Counter Idx is required. \ No newline at end of file diff --git a/param-docs/parameter-pages/MQTT/NUMBER.DomoticzIDX.md b/param-docs/parameter-pages/MQTT/NUMBER.DomoticzIDX.md new file mode 100644 index 000000000..d4d49bf58 --- /dev/null +++ b/param-docs/parameter-pages/MQTT/NUMBER.DomoticzIDX.md @@ -0,0 +1,4 @@ +# Parameter `.DomoticzIDX` +Default Value: `` + +The Idx number for the counter device. Can be obtained from the Domoticz devices setup page. \ No newline at end of file diff --git a/sd-card/html/edit_config_template.html b/sd-card/html/edit_config_template.html index 684b4c547..1bb03c51b 100644 --- a/sd-card/html/edit_config_template.html +++ b/sd-card/html/edit_config_template.html @@ -1133,6 +1133,39 @@

$TOOLTIP_MQTT_RetainMessages + + Domoticz Integration: + + + + + + + + + + $TOOLTIP_MQTT_DomoticzTopicIn + + + + + Idx per number sequence: + + + + + + + + + + + + $TOOLTIP_MQTT_DomoticzIDX + + Homeassistant Discovery (using MQTT)
@@ -2120,6 +2153,10 @@

Date: Fri, 25 Oct 2024 12:17:02 +0200 Subject: [PATCH 2/9] error correction --- code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp index 8a85fb25c..7b02b85a7 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp @@ -224,7 +224,7 @@ bool ClassFlowMQTT::Start(float AutoInterval) mqttServer_setParameter(flowpostprocessing->GetNumbers(), keepAlive, roundInterval); - bool MQTTConfigCheck = MQTT_Configure(uri, clientname, user, password, maintopic, LWT_TOPIC, LWT_CONNECTED, + bool MQTTConfigCheck = MQTT_Configure(uri, clientname, user, password, maintopic, domoticzintopic, LWT_TOPIC, LWT_CONNECTED, LWT_DISCONNECTED, caCertFilename, clientCertFilename, clientKeyFilename, keepAlive, SetRetainFlag, (void *)&GotConnected); From 15dc858bbd659f62ec17f7a5c207d0762ebdd687 Mon Sep 17 00:00:00 2001 From: gneluka Date: Fri, 25 Oct 2024 13:15:25 +0200 Subject: [PATCH 3/9] further changes --- sd-card/config/config.ini | 2 ++ sd-card/html/edit_config_template.html | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/sd-card/config/config.ini b/sd-card/config/config.ini index c0a9f92cb..dad69b81a 100644 --- a/sd-card/config/config.ini +++ b/sd-card/config/config.ini @@ -89,6 +89,8 @@ HomeassistantDiscovery = false ;CACert = /config/certs/RootCA.pem ;ClientCert = /config/certs/client.pem.crt ;ClientKey = /config/certs/client.pem.key +;DomoticzTopicIn = domoticz/in +;main.DomoticzIDX = undefined ;[InfluxDB] ;Uri = undefined diff --git a/sd-card/html/edit_config_template.html b/sd-card/html/edit_config_template.html index 1bb03c51b..e7348e226 100644 --- a/sd-card/html/edit_config_template.html +++ b/sd-card/html/edit_config_template.html @@ -1134,10 +1134,10 @@

- Domoticz Integration: + Domoticz Integration: - + @@ -1147,23 +1147,23 @@

$TOOLTIP_MQTT_DomoticzTopicIn - - - Idx per number sequence: + + + Idx per number sequence: - + - $TOOLTIP_MQTT_DomoticzIDX + $TOOLTIP_MQTT_NUMBER.DomoticzIDX @@ -2364,7 +2364,7 @@

@@ -2115,6 +2115,7 @@

Date: Sat, 26 Oct 2024 15:58:51 +0200 Subject: [PATCH 5/9] Refactoring --- .../jomjol_flowcontroll/ClassFlowMQTT.cpp | 6 +- sd-card/html/edit_config_template.html | 112 +++++++++++------- 2 files changed, 74 insertions(+), 44 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp index 3037aaebf..6d176feec 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp @@ -284,11 +284,11 @@ bool ClassFlowMQTT::doFlow(string zwtime) else namenumber = maintopic + "/" + namenumber + "/"; + if ((domoticzintopic.length() > 0) && (result.length() > 0)) + success |= MQTTPublish(domoticzintopic, domoticzpayload, qos, SetRetainFlag); - if (result.length() > 0) { + if (result.length() > 0) success |= MQTTPublish(namenumber + "value", result, qos, SetRetainFlag); - success |= MQTTPublish(domoticzintopic, domoticzpayload, qos, SetRetainFlag); - } if (resulterror.length() > 0) success |= MQTTPublish(namenumber + "error", resulterror, qos, SetRetainFlag); diff --git a/sd-card/html/edit_config_template.html b/sd-card/html/edit_config_template.html index dcf66fa09..efde080c3 100644 --- a/sd-card/html/edit_config_template.html +++ b/sd-card/html/edit_config_template.html @@ -1133,39 +1133,6 @@

$TOOLTIP_MQTT_RetainMessages - - Domoticz Integration: - - - - - - - - - - $TOOLTIP_MQTT_DomoticzTopicIn - - - - - Idx per number sequence: - - - - - - - - - - - - $TOOLTIP_MQTT_NUMBER.DomoticzIDX - - Homeassistant Discovery (using MQTT)
@@ -1211,6 +1178,36 @@

$TOOLTIP_MQTT_MeterType + + + + + + + + + $TOOLTIP_MQTT_DomoticzTopicIn + + + + + Parameter per number sequence: + + + + + + + + + + + + $TOOLTIP_MQTT_NUMBER.DomoticzIDX + + @@ -2249,6 +2246,7 @@

Date: Sat, 26 Oct 2024 17:03:34 +0200 Subject: [PATCH 6/9] further refactoring --- sd-card/html/edit_config_template.html | 52 ++++++++------------------ 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/sd-card/html/edit_config_template.html b/sd-card/html/edit_config_template.html index efde080c3..7eaa77a7c 100644 --- a/sd-card/html/edit_config_template.html +++ b/sd-card/html/edit_config_template.html @@ -1133,6 +1133,17 @@

$TOOLTIP_MQTT_RetainMessages + + + + + + + + + $TOOLTIP_MQTT_DomoticzTopicIn + + Homeassistant Discovery (using MQTT)
@@ -1178,17 +1189,6 @@

$TOOLTIP_MQTT_MeterType - - - - - - - - - $TOOLTIP_MQTT_DomoticzTopicIn - - Parameter per number sequence: @@ -2112,7 +2112,6 @@

Date: Sun, 27 Oct 2024 01:30:13 +0200 Subject: [PATCH 7/9] further refactoring --- code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp | 1 - code/components/jomjol_flowcontroll/ClassFlowMQTT.h | 1 - 2 files changed, 2 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp index 6d176feec..c6989ca14 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp @@ -51,7 +51,6 @@ void ClassFlowMQTT::SetInitialParameter(void) ListFlowControll = NULL; disabled = false; keepAlive = 25*60; - domoticzIdx = 0; domoticzintopic = ""; } diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.h b/code/components/jomjol_flowcontroll/ClassFlowMQTT.h index 6cd5a278f..fcea5b634 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.h +++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.h @@ -23,7 +23,6 @@ class ClassFlowMQTT : bool SetRetainFlag; int keepAlive; // Seconds float roundInterval; // Minutes - int domoticzIdx; std::string maintopic, domoticzintopic; void SetInitialParameter(void); void handleIdx(string _decsep, string _value); From c94ffa2fcaa4d95f9931345519851fa2f8d6d4c3 Mon Sep 17 00:00:00 2001 From: gneluka <32097881+gneluka@users.noreply.github.com> Date: Mon, 28 Oct 2024 02:41:56 +0100 Subject: [PATCH 8/9] Update DomoticzTopicIn.md --- param-docs/parameter-pages/MQTT/DomoticzTopicIn.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/param-docs/parameter-pages/MQTT/DomoticzTopicIn.md b/param-docs/parameter-pages/MQTT/DomoticzTopicIn.md index d5add179d..cf0fc9acd 100644 --- a/param-docs/parameter-pages/MQTT/DomoticzTopicIn.md +++ b/param-docs/parameter-pages/MQTT/DomoticzTopicIn.md @@ -1,6 +1,6 @@ # Parameter `DomoticzTopicIn` Default Value: `domoticz/in` -MQTT IN topic for Domoticz integration, under which the counters are published. +Domoticz "in" topic as configured on "MQTT Client Gateway" setup page. Used to publish counter/s value/s. -Counter Idx is required. \ No newline at end of file +Parameter .DomoticzIDX is required. From cf3fe75a52fa33ae5df4f72a0a866f9eb1c32940 Mon Sep 17 00:00:00 2001 From: gneluka <32097881+gneluka@users.noreply.github.com> Date: Mon, 28 Oct 2024 02:42:37 +0100 Subject: [PATCH 9/9] Update NUMBER.DomoticzIDX.md --- param-docs/parameter-pages/MQTT/NUMBER.DomoticzIDX.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/param-docs/parameter-pages/MQTT/NUMBER.DomoticzIDX.md b/param-docs/parameter-pages/MQTT/NUMBER.DomoticzIDX.md index d4d49bf58..72214cf6c 100644 --- a/param-docs/parameter-pages/MQTT/NUMBER.DomoticzIDX.md +++ b/param-docs/parameter-pages/MQTT/NUMBER.DomoticzIDX.md @@ -1,4 +1,4 @@ # Parameter `.DomoticzIDX` -Default Value: `` +Default Value: `0` -The Idx number for the counter device. Can be obtained from the Domoticz devices setup page. \ No newline at end of file +The Idx number for the counter device. Can be obtained from the Domoticz devices setup page.