Using MQTT for comm between Domoticz instances

For devices supporting the Auto Discovery feature. Like ZWaveJS2MQTT, Zigbee2MQTT.

Moderator: leecollings

FlyingDomotic
Posts: 385
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by FlyingDomotic »

DiaDomo wrote: Sunday 01 September 2024 8:21
2024-09-01 08:16:51.892 Error: MQTT Sync: File "/home/xxx/domoticz/plugins/MqttSync/plugin.py", line 668, in askForDeviceList
2024-09-01 08:16:51.892 Error: MQTT Sync: authorizationText += ":" + variables.domoticzPassword
2024-09-01 08:16:51.892 Error: MQTT Sync: TypeError: can only concatenate str (not "NoneType") to str

Can you advice?
This was a bug, fixed with last version of plugin.
DiaDomo wrote: Sunday 01 September 2024 9:36 When I add my domoticz username & password for the master in the URL, I get the following error in the domoticz log:

Code: Select all

2024-09-01 09:34:00.677 Error: MQTT Sync: name2idx::onMessage: Error 401 returned by HTTP
Error 401 is "Unauthorized", meaning (if you gave both username and password), that they're not the right ones. Could you check them?
DiaDomo
Posts: 37
Joined: Saturday 28 March 2020 13:55
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by DiaDomo »

1) I updated the plugin.
2) Removed user&password in the master URL (I think these are not necessary).
Errors in the log:

Code: Select all

2024-09-01 13:23:38.718 Error: MQTT Sync: Call to function 'onConnect' failed, exception details:
2024-09-01 13:23:38.734 Error: MQTT Sync: Traceback (most recent call last):
2024-09-01 13:23:38.734 Error: MQTT Sync: File "/home/xxx/domoticz/plugins/MqttSync/plugin.py", line 1097, in onConnect
2024-09-01 13:23:38.734 Error: MQTT Sync: onHttpConnected(Connection)
2024-09-01 13:23:38.734 Error: MQTT Sync: File "/home/xxx/domoticz/plugins/MqttSync/plugin.py", line 796, in onHttpConnected
2024-09-01 13:23:38.734 Error: MQTT Sync: askForDeviceList(Connection)
2024-09-01 13:23:38.734 Error: MQTT Sync: File "/home/xxx/domoticz/plugins/MqttSync/plugin.py", line 669, in askForDeviceList
2024-09-01 13:23:38.734 Error: MQTT Sync: authorization = base64.b64encode(authorizationText.encode('ascii')).decode("UTF_8")
2024-09-01 13:23:38.734 Error: MQTT Sync: AttributeError: 'NoneType' object has no attribute 'encode'
2024-09-01 13:23:45.884 Error: MQTT Sync: Call to function 'onConnect' failed, exception details:
2024-09-01 13:23:45.899 Error: MQTT Sync: Traceback (most recent call last):
2024-09-01 13:23:45.900 Error: MQTT Sync: File "/home/xxx/domoticz/plugins/MqttSync/plugin.py", line 1097, in onConnect
2024-09-01 13:23:45.900 Error: MQTT Sync: onHttpConnected(Connection)
2024-09-01 13:23:45.900 Error: MQTT Sync: File "/home/xxx/domoticz/plugins/MqttSync/plugin.py", line 796, in onHttpConnected
2024-09-01 13:23:45.900 Error: MQTT Sync: askForDeviceList(Connection)
2024-09-01 13:23:45.900 Error: MQTT Sync: File "/home/xxx/domoticz/plugins/MqttSync/plugin.py", line 669, in askForDeviceList
2024-09-01 13:23:45.900 Error: MQTT Sync: authorization = base64.b64encode(authorizationText.encode('ascii')).decode("UTF_8")
2024-09-01 13:23:45.900 Error: MQTT Sync: AttributeError: 'NoneType' object has no attribute 'encode'
3) Re-added the username & password in the master URL (format: http://<username>:<password>@IP:port)
Domoticz log error:

Code: Select all

2024-09-01 13:30:56.940 Error: MQTT Sync: name2idx::onMessage: Error 401 returned by HTTP
Is the format OK?
Raspberry PI 2 & 3 & 4 | RFlink | MySensors | ESP32 | Homebridge | Tasmota Sonoff | Zigbee2Mqtt | ADS-B
FlyingDomotic
Posts: 385
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by FlyingDomotic »

DiaDomo wrote: Sunday 01 September 2024 13:31 2024-09-01 13:23:38.734 Error: MQTT Sync: authorization = base64.b64encode(authorizationText.encode('ascii')).decode("UTF_8")
2024-09-01 13:23:38.734 Error: MQTT Sync: AttributeError: 'NoneType' object has no attribute 'encode'
Fixed in last version too. You should normally try without user/password.

Concerning 401 error, it means either that you don't gave user/password while needed, or user/password is not the right one.

User and password are extracted from Domoticz URL with general format http://username:password@ipAddressorName:port
DiaDomo
Posts: 37
Joined: Saturday 28 March 2020 13:55
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by DiaDomo »

Thx, it's running now after the plugin update! (no username / password required)
Raspberry PI 2 & 3 & 4 | RFlink | MySensors | ESP32 | Homebridge | Tasmota Sonoff | Zigbee2Mqtt | ADS-B
FlyingDomotic
Posts: 385
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by FlyingDomotic »

We're never protected against chance :D
willemd
Posts: 658
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by willemd »

FlyingDomotic wrote: Wednesday 28 August 2024 10:44 I just wrote a new Python plugin synchronizing a master (local) instance of Domoticz to a slave (remote) one at https://github.com/FlyingDomotic/domoti ... ync-plugin

You just have to get list of IDX (or names) of devices you want to synchronize on master, and that's it. Everything is automatically created on slave, and updates are propagated from master to slave when they occurs. You can even propagate changes from slave to master, if you allow device to do so.

Connections are established by master to slave, avoiding opening something incoming at home.

Paranoiacs can even create a dedicated user to protect against accidentally configuring a device as being synchronized.

In addition to one master speaking to one slave, you can also have one master connected to multiple slaves, one slave connected to multiple masters, multiple masters connected to multiple slaves. Cascades also supported.

This may be useful if Telegram disappears one day, after its creator being arrested in France, for example ;-)
Thanks, this is exactly what I was looking for. I want to connect my OpenThermGateway and some 1-wire temperature sensors to one Raspberry Pi and then sync those values to my main Domoticz installation.

Everytime you think you have to build something yourselve, just do a search and discover someone else has already done the work. That's great. Thanks.

Three questions:
1) I assume I still have to install the MQTT broker/server first before installing the plugin as per your description?
2) Does it matter on which Raspberry the broker is installed?
3) In your terminology for this plugin, the sending device is the master and the receiving device is the slave?
FlyingDomotic
Posts: 385
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by FlyingDomotic »

willemd wrote: Tuesday 08 July 2025 11:10 Three questions:
1) I assume I still have to install the MQTT broker/server first before installing the plugin as per your description?
2) Does it matter on which Raspberry the broker is installed?
3) In your terminology for this plugin, the sending device is the master and the receiving device is the slave?
1) MQTT broker should be installed and running when starting plug-in. Installation order is not important.

2) You should connect on MQTT broker(s) attached to each Domoticz instance you want to synchronize, whatever it/they should be. Usually, we use a local instance for each Domoticz instance, but this is not mandatory.

3) Master is defined in configuration file. Master instance is where device reference is taken, salve where this master device is copied to. However, devices for which you define "allowSlaveUpdate" to True will also update master when they change.
willemd
Posts: 658
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by willemd »

Just to share my experience here. It worked on the first try !!

What I did:
1) Install a new Raspberry Pi with Domoticz and two 1-wire temperature sensors. This one is the master, i.e. data provider.
2) Install Mosquitto broker on this system.
3) Install the plugin and add it into the Domoticz hardware list.
4) Create a configuration file (to be placed in the folder of the plugin : ~/domoticz/plugins/MqttSync ). To share a real life example it is shown below.
5) Install the plugin on the main domoticz system and add it to the hardware list. This is the slave, i.e. the data receiver.
6) Put the same configuration file in the folder of the plugin, so it will use the broker already installed on the master.

restart both system and voila.... two sensors were created on the main system and values were synchronised.

thanks again for your plugin.

Code: Select all

{
        "settings": {
                "configVersion": "V1.0.2",
                "masterName": "master",
                "masterMqttHost": "192.168.178.254",
                "masterMqttPort": "1883",
                "masterMqttUser": "",
                "masterMqttPassword": "",
                "masterDomoticzOutTopic": "domoticz/out",
                "masterDomoticzUrl": "http://192.168.178.254:8080",
                "slaveName": "slave",
                "slaveMqttHost": "192.168.178.254",
                "slaveMqttPort": "1883",
                "slaveMqttUser": "",
                "slaveMqttPassword": "",
                "slaveDomoticzUrl": "http://192.168.178.218:8080",
                "slaveDevicePrefix": "BoilerPi:"
        },
        "mapping": [
                {"idx": 1},
                {"idx": 2}
        ]
}
FlyingDomotic
Posts: 385
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by FlyingDomotic »

We're never protected against chance :D
willemd
Posts: 658
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by willemd »

I was cheering a bit too early...

It now seems that the synchronisation only occurs once.

If I restart the master, either with a reboot, or a domoticz restart, or a plugin restart (either disable/enable or update the logging) then the values are arriving at the slave without problems, but only once.

I see no error messages in the Domoticz log. I ran the plugin on the master with more logging (debug or extra verbose) and as far as I can interpret it is not sending further values after the intial once after startup. I checked the sensors themselves on master also, they are updated no problem, so it should send updates.

I also tried manually to subscribe to domoticz/out but don't see anything happening, not even the first time when the sync is succesfull. When I send a message to domoticz/out I see it in the manually subscribed terminal window. Addition: If I subscribe to mqttSync/master2slave/masterParameters/1 or mqttSync/master2slave/masterValues/1 then I see exactly one update being published, again only one.

Any idea?

This is what I see in the log after the initial update when I set logging to extra verbose.

Code: Select all

2025-07-10 20:05:26.018 mqtt sync: Pushing 'onHeartbeatCallback' on to queue
2025-07-10 20:05:26.068 mqtt sync: Processing 'onHeartbeatCallback' message
2025-07-10 20:05:26.069 mqtt sync: Calling message handler 'onHeartbeat' on 'module' type object.
2025-07-10 20:05:26.069 mqtt sync: onHeartbeat:
2025-07-10 20:05:26.069 mqtt sync: Pushing 'WriteDirective' on to queue
2025-07-10 20:05:26.069 mqtt sync: Pushing 'WriteDirective' on to queue
2025-07-10 20:05:26.069 mqtt sync: Processing 'WriteDirective' message
2025-07-10 20:05:26.070 mqtt sync: Sending 2 bytes of data
2025-07-10 20:05:26.070 mqtt sync: c0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. �
2025-07-10 20:05:26.070 mqtt sync: Processing 'WriteDirective' message
2025-07-10 20:05:26.070 mqtt sync: Sending 2 bytes of data
2025-07-10 20:05:26.070 mqtt sync: c0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. �
2025-07-10 20:05:26.071 mqtt sync: Pushing 'ReadEvent' on to queue
2025-07-10 20:05:26.071 mqtt sync: Pushing 'ReadEvent' on to queue
2025-07-10 20:05:26.121 mqtt sync: Processing 'ReadEvent' message
2025-07-10 20:05:26.121 mqtt sync: Received 2 bytes of data
2025-07-10 20:05:26.122 mqtt sync: d0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. Ю
2025-07-10 20:05:26.122 mqtt sync: Pushing 'onMessageCallback' on to queue
2025-07-10 20:05:26.122 mqtt sync: Processing 'ReadEvent' message
2025-07-10 20:05:26.122 mqtt sync: Received 2 bytes of data
2025-07-10 20:05:26.123 mqtt sync: d0 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. Ю
2025-07-10 20:05:26.123 mqtt sync: Pushing 'onMessageCallback' on to queue
2025-07-10 20:05:26.123 mqtt sync: Processing 'onMessageCallback' message
2025-07-10 20:05:26.124 mqtt sync: Calling message handler 'onMessage' on 'module' type object.
2025-07-10 20:05:26.124 mqtt sync: Processing 'onMessageCallback' message
2025-07-10 20:05:26.124 mqtt sync: Calling message handler 'onMessage' on 'module' type object.
And this is what I see during the very first sync.

Code: Select all

2025-07-10 20:08:44.912 mqtt sync: Slave::onConnect: Status 0, Description Success
2025-07-10 20:08:44.912 mqtt sync: onSlaveConnected:
2025-07-10 20:08:44.912 mqtt sync: MqttClient/Slave::SendId:
2025-07-10 20:08:44.912 mqtt sync: MqttClient/Slave::SendId: ID: Domoticz_domoticz-mqtt-sync_3_Slave_2025-07-10 20:08:43, lwtTopic: mqttSync/master2slave/lwt/slaveOnMaster, lwtData: {"state": "down", "version": "1.0.0"}
2025-07-10 20:08:44.912 mqtt sync: Pushing 'WriteDirective' on to queue
2025-07-10 20:08:44.912 mqtt sync: Processing 'WriteDirective' message
2025-07-10 20:08:44.912 mqtt sync: Sending 150 bytes of data
2025-07-10 20:08:44.912 mqtt sync: 10 93 01 00 04 4d 51 54 54 04 26 00 3c 00 37 44 6f 6d 6f 74 .Ӯ..MQTT.&.<.7Domot
2025-07-10 20:08:44.912 mqtt sync: 69 63 7a 5f 64 6f 6d 6f 74 69 63 7a 2d 6d 71 74 74 2d 73 79 icz_domoticz-mqtt-sy
2025-07-10 20:08:44.912 mqtt sync: 6e 63 5f 33 5f 53 6c 61 76 65 5f 32 30 32 35 2d 30 37 2d 31 nc_3_Slave_2025-07-1
2025-07-10 20:08:44.912 mqtt sync: 30 20 32 30 3a 30 38 3a 34 33 00 27 6d 71 74 74 53 79 6e 63 0.20:08:43.'mqttSync
2025-07-10 20:08:44.912 mqtt sync: 2f 6d 61 73 74 65 72 32 73 6c 61 76 65 2f 6c 77 74 2f 73 6c /master2slave/lwt/sl
2025-07-10 20:08:44.912 mqtt sync: 61 76 65 4f 6e 4d 61 73 74 65 72 00 25 7b 22 73 74 61 74 65 aveOnMaster.%{"state
2025-07-10 20:08:44.912 mqtt sync: 22 3a 20 22 64 6f 77 6e 22 2c 20 22 76 65 72 73 69 6f 6e 22 ":."down",."version"
2025-07-10 20:08:44.912 mqtt sync: 3a 20 22 31 2e 30 2e 30 22 7d .. .. .. .. .. .. .. .. .. .. :."1.0.0"}
2025-07-10 20:08:44.913 mqtt sync: Pushing 'ReadEvent' on to queue
2025-07-10 20:08:44.963 mqtt sync: Processing 'ReadEvent' message
2025-07-10 20:08:44.963 mqtt sync: Received 4 bytes of data
2025-07-10 20:08:44.963 mqtt sync: 20 02 00 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ....
2025-07-10 20:08:44.963 mqtt sync: Pushing 'onMessageCallback' on to queue
2025-07-10 20:08:44.963 mqtt sync: Processing 'onMessageCallback' message
2025-07-10 20:08:44.963 mqtt sync: Calling message handler 'onMessage' on 'module' type object.
2025-07-10 20:08:44.963 mqtt sync: Slave::onMessage: Connection established
2025-07-10 20:08:44.963 mqtt sync: Slave::onSlaveMqttConAck:
2025-07-10 20:08:44.963 mqtt sync: MqttClient/Slave::Publish: mqttSync/master2slave/lwt/slaveOnMaster ({"state": "up", "version": "1.0.0", "since": "2025-07-10 20:08:43"})
2025-07-10 20:08:44.963 mqtt sync: Pushing 'WriteDirective' on to queue
2025-07-10 20:08:44.963 mqtt sync: sendParametersAndValuesToSlave:
2025-07-10 20:08:44.963 mqtt sync: MqttClient/Slave::Publish: mqttSync/master2slave/masterParameters/1 ({"Name": "Temperature1", "Type": 80, "SubType": 5, "SwitchType": 0, "Sequence": "2025-07-10 20:08:43"})
2025-07-10 20:08:44.963 mqtt sync: Pushing 'WriteDirective' on to queue
2025-07-10 20:08:44.963 mqtt sync: MqttClient/Slave::Publish: mqttSync/master2slave/masterParameters/2 ({"Name": "Temperature2", "Type": 80, "SubType": 5, "SwitchType": 0, "Sequence": "2025-07-10 20:08:43"})
2025-07-10 20:08:44.963 mqtt sync: Pushing 'WriteDirective' on to queue
2025-07-10 20:08:44.964 mqtt sync: MqttClient/Slave::Publish: mqttSync/master2slave/masterValues/1 ({"allowSlaveUpdate": true, "nValue": 0, "sValue": "24.4", "LastUpdate": "2025-07-10 20:08:42", "Sequence": "2025-07-10 20:08:43"})
2025-07-10 20:08:44.964 mqtt sync: Pushing 'WriteDirective' on to queue
2025-07-10 20:08:44.964 mqtt sync: MqttClient/Slave::Publish: mqttSync/master2slave/masterValues/2 ({"allowSlaveUpdate": true, "nValue": 0, "sValue": "24.0", "LastUpdate": "2025-07-10 20:08:12", "Sequence": "2025-07-10 20:08:43"})
2025-07-10 20:08:44.964 mqtt sync: Pushing 'WriteDirective' on to queue
2025-07-10 20:08:44.964 mqtt sync: subscribeSlaveValuesFromMaster:
2025-07-10 20:08:44.964 mqtt sync: MqttClient/Slave::Subscribe: mqttSync/master2slave/slaveValues/#
2025-07-10 20:08:44.964 mqtt sync: Pushing 'WriteDirective' on to queue
2025-07-10 20:08:44.964 mqtt sync: Processing 'WriteDirective' message
2025-07-10 20:08:44.964 mqtt sync: Sending 110 bytes of data
2025-07-10 20:08:44.964 mqtt sync: 31 6c 00 27 6d 71 74 74 53 79 6e 63 2f 6d 61 73 74 65 72 32 1l.'mqttSync/master2
2025-07-10 20:08:44.964 mqtt sync: 73 6c 61 76 65 2f 6c 77 74 2f 73 6c 61 76 65 4f 6e 4d 61 73 slave/lwt/slaveOnMas
2025-07-10 20:08:44.964 mqtt sync: 74 65 72 7b 22 73 74 61 74 65 22 3a 20 22 75 70 22 2c 20 22 ter{"state":."up",."
2025-07-10 20:08:44.964 mqtt sync: 76 65 72 73 69 6f 6e 22 3a 20 22 31 2e 30 2e 30 22 2c 20 22 version":."1.0.0",."
2025-07-10 20:08:44.964 mqtt sync: 73 69 6e 63 65 22 3a 20 22 32 30 32 35 2d 30 37 2d 31 30 20 since":."2025-07-10.
2025-07-10 20:08:44.964 mqtt sync: 32 30 3a 30 38 3a 34 33 22 7d .. .. .. .. .. .. .. .. .. .. 20:08:43"}
2025-07-10 20:08:44.964 mqtt sync: Processing 'WriteDirective' message
2025-07-10 20:08:44.965 mqtt sync: Sending 147 bytes of data
2025-07-10 20:08:44.965 mqtt sync: 31 90 01 00 28 6d 71 74 74 53 79 6e 63 2f 6d 61 73 74 65 72 1Ю.(mqttSync/master
2025-07-10 20:08:44.965 mqtt sync: 32 73 6c 61 76 65 2f 6d 61 73 74 65 72 50 61 72 61 6d 65 74 2slave/masterParamet
2025-07-10 20:08:44.965 mqtt sync: 65 72 73 2f 31 7b 22 4e 61 6d 65 22 3a 20 22 54 65 6d 70 65 ers/1{"Name":."Tempe
2025-07-10 20:08:44.965 mqtt sync: 72 61 74 75 72 65 31 22 2c 20 22 54 79 70 65 22 3a 20 38 30 rature1",."Type":.80
2025-07-10 20:08:44.965 mqtt sync: 2c 20 22 53 75 62 54 79 70 65 22 3a 20 35 2c 20 22 53 77 69 ,."SubType":.5,."Swi
2025-07-10 20:08:44.965 mqtt sync: 74 63 68 54 79 70 65 22 3a 20 30 2c 20 22 53 65 71 75 65 6e tchType":.0,."Sequen
2025-07-10 20:08:44.965 mqtt sync: 63 65 22 3a 20 22 32 30 32 35 2d 30 37 2d 31 30 20 32 30 3a ce":."2025-07-10.20:
2025-07-10 20:08:44.965 mqtt sync: 30 38 3a 34 33 22 7d .. .. .. .. .. .. .. .. .. .. .. .. .. 08:43"}
2025-07-10 20:08:44.965 mqtt sync: Processing 'WriteDirective' message
2025-07-10 20:08:44.965 mqtt sync: Sending 147 bytes of data
2025-07-10 20:08:44.965 mqtt sync: 31 90 01 00 28 6d 71 74 74 53 79 6e 63 2f 6d 61 73 74 65 72 1Ю.(mqttSync/master
2025-07-10 20:08:44.965 mqtt sync: 32 73 6c 61 76 65 2f 6d 61 73 74 65 72 50 61 72 61 6d 65 74 2slave/masterParamet
2025-07-10 20:08:44.965 mqtt sync: 65 72 73 2f 32 7b 22 4e 61 6d 65 22 3a 20 22 54 65 6d 70 65 ers/2{"Name":."Tempe
2025-07-10 20:08:44.965 mqtt sync: 72 61 74 75 72 65 32 22 2c 20 22 54 79 70 65 22 3a 20 38 30 rature2",."Type":.80
2025-07-10 20:08:44.965 mqtt sync: 2c 20 22 53 75 62 54 79 70 65 22 3a 20 35 2c 20 22 53 77 69 ,."SubType":.5,."Swi
2025-07-10 20:08:44.965 mqtt sync: 74 63 68 54 79 70 65 22 3a 20 30 2c 20 22 53 65 71 75 65 6e tchType":.0,."Sequen
2025-07-10 20:08:44.965 mqtt sync: 63 65 22 3a 20 22 32 30 32 35 2d 30 37 2d 31 30 20 32 30 3a ce":."2025-07-10.20:
2025-07-10 20:08:44.965 mqtt sync: 30 38 3a 34 33 22 7d .. .. .. .. .. .. .. .. .. .. .. .. .. 08:43"}
2025-07-10 20:08:44.965 mqtt sync: Processing 'WriteDirective' message
2025-07-10 20:08:44.965 mqtt sync: Sending 170 bytes of data
2025-07-10 20:08:44.965 mqtt sync: 31 a7 01 00 24 6d 71 74 74 53 79 6e 63 2f 6d 61 73 74 65 72 1Ǯ.$mqttSync/master
2025-07-10 20:08:44.965 mqtt sync: 32 73 6c 61 76 65 2f 6d 61 73 74 65 72 56 61 6c 75 65 73 2f 2slave/masterValues/
2025-07-10 20:08:44.965 mqtt sync: 31 7b 22 61 6c 6c 6f 77 53 6c 61 76 65 55 70 64 61 74 65 22 1{"allowSlaveUpdate"
2025-07-10 20:08:44.965 mqtt sync: 3a 20 74 72 75 65 2c 20 22 6e 56 61 6c 75 65 22 3a 20 30 2c :.true,."nValue":.0,
2025-07-10 20:08:44.965 mqtt sync: 20 22 73 56 61 6c 75 65 22 3a 20 22 32 34 2e 34 22 2c 20 22 ."sValue":."24.4",."
2025-07-10 20:08:44.965 mqtt sync: 4c 61 73 74 55 70 64 61 74 65 22 3a 20 22 32 30 32 35 2d 30 LastUpdate":."2025-0
2025-07-10 20:08:44.965 mqtt sync: 37 2d 31 30 20 32 30 3a 30 38 3a 34 32 22 2c 20 22 53 65 71 7-10.20:08:42",."Seq
2025-07-10 20:08:44.965 mqtt sync: 75 65 6e 63 65 22 3a 20 22 32 30 32 35 2d 30 37 2d 31 30 20 uence":."2025-07-10.
2025-07-10 20:08:44.965 mqtt sync: 32 30 3a 30 38 3a 34 33 22 7d .. .. .. .. .. .. .. .. .. .. 20:08:43"}
2025-07-10 20:08:44.965 mqtt sync: Processing 'WriteDirective' message
2025-07-10 20:08:44.965 mqtt sync: Sending 170 bytes of data
2025-07-10 20:08:44.965 mqtt sync: 31 a7 01 00 24 6d 71 74 74 53 79 6e 63 2f 6d 61 73 74 65 72 1Ǯ.$mqttSync/master
2025-07-10 20:08:44.965 mqtt sync: 32 73 6c 61 76 65 2f 6d 61 73 74 65 72 56 61 6c 75 65 73 2f 2slave/masterValues/
2025-07-10 20:08:44.966 mqtt sync: 32 7b 22 61 6c 6c 6f 77 53 6c 61 76 65 55 70 64 61 74 65 22 2{"allowSlaveUpdate"
2025-07-10 20:08:44.966 mqtt sync: 3a 20 74 72 75 65 2c 20 22 6e 56 61 6c 75 65 22 3a 20 30 2c :.true,."nValue":.0,
2025-07-10 20:08:44.966 mqtt sync: 20 22 73 56 61 6c 75 65 22 3a 20 22 32 34 2e 30 22 2c 20 22 ."sValue":."24.0",."
2025-07-10 20:08:44.966 mqtt sync: 4c 61 73 74 55 70 64 61 74 65 22 3a 20 22 32 30 32 35 2d 30 LastUpdate":."2025-0
2025-07-10 20:08:44.966 mqtt sync: 37 2d 31 30 20 32 30 3a 30 38 3a 31 32 22 2c 20 22 53 65 71 7-10.20:08:12",."Seq
2025-07-10 20:08:44.966 mqtt sync: 75 65 6e 63 65 22 3a 20 22 32 30 32 35 2d 30 37 2d 31 30 20 uence":."2025-07-10.
2025-07-10 20:08:44.966 mqtt sync: 32 30 3a 30 38 3a 34 33 22 7d .. .. .. .. .. .. .. .. .. .. 20:08:43"}
2025-07-10 20:08:44.966 mqtt sync: Processing 'WriteDirective' message
2025-07-10 20:08:44.966 mqtt sync: Sending 42 bytes of data
2025-07-10 20:08:44.966 mqtt sync: 82 28 00 01 00 23 6d 71 74 74 53 79 6e 63 2f 6d 61 73 74 65 ¨...#mqttSync/maste
2025-07-10 20:08:44.966 mqtt sync: 72 32 73 6c 61 76 65 2f 73 6c 61 76 65 56 61 6c 75 65 73 2f r2slave/slaveValues/
2025-07-10 20:08:44.966 mqtt sync: 23 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. #.
2025-07-10 20:08:45.009 mqtt sync: Pushing 'ReadEvent' on to queue
2025-07-10 20:08:45.016 mqtt sync: Processing 'ReadEvent' message
2025-07-10 20:08:45.016 mqtt sync: Received 5 bytes of data
2025-07-10 20:08:45.016 mqtt sync: 90 03 00 01 00 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. Ю...
2025-07-10 20:08:45.016 mqtt sync: Pushing 'onMessageCallback' on to queue
2025-07-10 20:08:45.016 mqtt sync: Processing 'onMessageCallback' message
2025-07-10 20:08:45.016 mqtt sync: Calling message handler 'onMessage' on 'module' type object.
willemd
Posts: 658
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by willemd »

I tried to understand the code and the source of the problem.

I could not really determine what the trigger would be for the master to send an update of values. Would it be on the heartbeat or would it be on the update of a value of a device?

I am not sure whether the plugins registers anywhere which devices to monitor (devices list of the master plugin?). Anyway it does not seem to react to updates at all.

For the moment I added a line with call to function
sendParametersAndValuesToSlave()
in the onHeartbeat function on the master.
Then the values get updated every 15 seconds, no problem.
Last edited by willemd on Saturday 12 July 2025 21:18, edited 1 time in total.
FlyingDomotic
Posts: 385
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by FlyingDomotic »

Having a copy of your configuration file (with personal data replaced by xxx or ***) may help.

Before having it, can you check you correctly defined a mapping section, like in the example :

Code: Select all

{
	"settings": {
		"configVersion": "V1.0.0",
		"masterName": ....
	},
	"mapping": [
		{"idx": 2254, "allowSlaveUpdate": true},
		{"idx": 2255, "allowSlaveUpdate": false},
		{"name": "Thermostat", "allowSlaveUpdate": true}
	]
}
willemd
Posts: 658
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by willemd »

FlyingDomotic wrote: Saturday 12 July 2025 19:21 Having a copy of your configuration file (with personal data replaced by xxx or ***) may help.

it is in my earlier message here
viewtopic.php?p=327128#p327128

If my config file would be wrong then it would not work on startup either I think.

Additional thought: Could it be because SuppressTriggers is set to True? Or is that only True for slave devices?
FlyingDomotic
Posts: 385
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by FlyingDomotic »

Sorry not seeing it in previous...

It seems that nothing is sent on domoticz/out.

Did you install "MQTT Client Gateway with LAN interface" on both machines?
willemd
Posts: 658
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by willemd »

FlyingDomotic wrote: Saturday 12 July 2025 23:10 Sorry not seeing it in previous...

It seems that nothing is sent on domoticz/out.

Did you install "MQTT Client Gateway with LAN interface" on both machines?
No I did not install "MQTT Client Gateway with LAN interface" but I installed "MQTT sync with network interface".

I did an additional test changing my config file to set the slave domoticz installation to be the same as the master and I installed both a master and a slave "MQTT sync with network interface" on the same domoticz installation, so everything now on one machine.
The result is the same:
0) the existing devices are seen, the config file is read and the plugin starts perfectly.
1) the devices are created on the slave, no problem
2) the devices are updated once, no problem
3) no further updates after that, problem

I believe the root cause is the fact that the master does not own any devices and there it is not triggered by any changes on those devices.

When I look at the config dump in the log file then the master reports 0 devices, while the slave reports 5 devices (I have now 5 temperature sensors connected). The 5 devices of the slave are the 5 devices that are created by the MQTT sync plugin.

The 5 source devices of the master were already existing (as result of the 1-wire plugin) and are not on the device list of the Mqtt sync master therefore there is no trigger when these devices are updated.
FlyingDomotic
Posts: 385
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by FlyingDomotic »

Could you try to install (and setup properly) "MQTT Client Gateway with LAN interface"? On both machines. FYI, it manages 'domoticz/in" and "domoticz/out" topics, which are used by Mqtt Sync plugin.

It's generally installed on Domoticz, so I didn't mention it into Mqtt Sync README, but I should do it.
willemd
Posts: 658
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by willemd »

FlyingDomotic wrote: Sunday 13 July 2025 15:21 Could you try to install (and setup properly) "MQTT Client Gateway with LAN interface"? On both machines. FYI, it manages 'domoticz/in" and "domoticz/out" topics, which are used by Mqtt Sync plugin.

It's generally installed on Domoticz, so I didn't mention it into Mqtt Sync README, but I should do it.
Yes, that worked. Thanks.

So the initial values were transferred not by mqtt but via a different mechanism? How was it possible that those worked but the next ones did not?

Now I have a new problem that the temperatures sent and received by the plugin sometimes shows strange values like 2737000 or 2243958 (and always those numbers) instead of a normal values. The next 3 update then shows normal values again and then the strange value re-appears. I don't see those numbers on the master devices but I see them on the slave and I see them in the log of mqqt sync.

After further analysis I see in the log that those strange values are the values from the slave domoticz(!!!) instance with the same idx as the temperature sensor on the master. So for idx1 temperature sensors it picks up the value of device 1 of the slave (which is a P1 electricity meter) and for idx2 it picks up the value of idx2 of the slave (which is a gas mater). The next 3 times it correctly picks up the values of idx1 and idx2 of the master domoticz, but then the next one idx1 and idx2 of the slave. It seems that "MQTT Client Gateway with LAN interface" only needs to be activated on Master not on slave and "MQTT sync with network interface" on both ?

Here is part of domoticz.txt for the master device:

Code: Select all

2025-07-14 06:23:22.218  mqtt sync: onMasterReceived: Updating idx 2 with {'allowSlaveUpdate': False, 'nValue': 0, 'sValue': '2737000.0', 'LastUpdate': '2025-07-14 06:23:22', 'Sequence': '2025-07-14 06:10:46'}
2025-07-14 06:23:32.645  mqtt sync: onMasterReceived: Updating idx 2 with {'allowSlaveUpdate': False, 'nValue': 0, 'sValue': '24.0', 'LastUpdate': '2025-07-14 06:23:32', 'Sequence': '2025-07-14 06:10:46'}
2025-07-14 06:23:52.657  mqtt sync: onMasterReceived: Updating idx 2 with {'allowSlaveUpdate': False, 'nValue': 0, 'sValue': '23.9', 'LastUpdate': '2025-07-14 06:23:52', 'Sequence': '2025-07-14 06:10:46'}
2025-07-14 06:24:12.631  mqtt sync: onMasterReceived: Updating idx 2 with {'allowSlaveUpdate': False, 'nValue': 0, 'sValue': '23.9', 'LastUpdate': '2025-07-14 06:24:12', 'Sequence': '2025-07-14 06:10:46'}
2025-07-14 06:24:22.361  mqtt sync: onMasterReceived: Updating idx 2 with {'allowSlaveUpdate': False, 'nValue': 0, 'sValue': '2737000.0', 'LastUpdate': '2025-07-14 06:24:22', 'Sequence': '2025-07-14 06:10:46'}
2025-07-14 06:24:32.681  mqtt sync: onMasterReceived: Updating idx 2 with {'allowSlaveUpdate': False, 'nValue': 0, 'sValue': '23.9', 'LastUpdate': '2025-07-14 06:24:32', 'Sequence': '2025-07-14 06:10:46'}
2025-07-14 06:24:52.647  mqtt sync: onMasterReceived: Updating idx 2 with {'allowSlaveUpdate': False, 'nValue': 0, 'sValue': '23.9', 'LastUpdate': '2025-07-14 06:24:52', 'Sequence': '2025-07-14 06:10:46'}
2025-07-14 06:25:12.646  mqtt sync: onMasterReceived: Updating idx 2 with {'allowSlaveUpdate': False, 'nValue': 0, 'sValue': '23.9', 'LastUpdate': '2025-07-14 06:25:12', 'Sequence': '2025-07-14 06:10:46'}
2025-07-14 06:25:22.628  mqtt sync: onMasterReceived: Updating idx 2 with {'allowSlaveUpdate': False, 'nValue': 0, 'sValue': '2737000.0', 'LastUpdate': '2025-07-14 06:25:22', 'Sequence': '2025-07-14 06:10:46'}

FlyingDomotic
Posts: 385
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by FlyingDomotic »

willemd wrote: Monday 14 July 2025 6:24 So the initial values were transferred not by mqtt but via a different mechanism? How was it possible that those worked but the next ones did not?
Mechanism is not the same.

When creating device (on slave), we read (master) characteristics and current value from Domoticz's internal tables and send them to slave, which in turn creates device and set initial value.

Then, we're looking for device changes, scanning domoticz/out topic.
willemd wrote: Monday 14 July 2025 6:24 Now I have a new problem that the temperatures sent and received by the plugin sometimes shows strange values like 2737000 or 2243958 (and always those numbers) instead of a normal values. The next 3 update then shows normal values again and then the strange value re-appears. I don't see those numbers on the master devices but I see them on the slave and I see them in the log of mqqt sync.

After further analysis I see in the log that those strange values are the values from the slave domoticz(!!!) instance with the same idx as the temperature sensor on the master. So for idx1 temperature sensors it picks up the value of device 1 of the slave (which is a P1 electricity meter) and for idx2 it picks up the value of idx2 of the slave (which is a gas mater). The next 3 times it correctly picks up the values of idx1 and idx2 of the master domoticz, but then the next one idx1 and idx2 of the slave. It seems that "MQTT Client Gateway with LAN interface" only needs to be activated on Master not on slave and "MQTT sync with network interface" on both ?
I'll check. This would not be first time I wrote an undocumented and undesirable feature (understand a bug) ;-)
willemd
Posts: 658
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by willemd »

In the meantime I can confirm that if I switch off the "MQTT Client Gateway with LAN interface" on the slave, then the feeding of slave electricity and slave gas meter values onto the slave temperature devices stops, while the feeding of master temperature devices onto slave temperature devices continues. The "last seen" time on the device display only changes when the value actually changes, so not on every update.

So in the end I have:
"MQTT Client Gateway with LAN interface" on master only
"MQTT sync with network interface" both on master and slave

In my installation I can switch off "MQTT Client Gateway with LAN interface" on slave without problems since I don't have other MQTT feeds running. In installations where that would be a problem, probably the issue could be solved with removing the mapping in the config file on the slave?
User avatar
waltervl
Posts: 5883
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Using MQTT for comm between Domoticz instances

Post by waltervl »

Just a thought: when both master and slave have a "MQTT Client Gateway with LAN interface" the both are sending their device values to MQTT Topic Domoticz/out and in. As both environments have different devices they have different device IDs. In the MQTT message there is no indication of environment so MQTT (and the plugin) do not know from what environment the MQTT message is coming from. Perhaps this will give unexpected results when the Slave is sending a device update of device IDX x in Domoticz/out that is also on the sync mapping list for another type of device?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest