MQTT topic hierarchy suggestion.
Posted: Thursday 09 July 2020 0:50
I am the developer of an MQTT integration into Hubitat (HE) and some other devices. I have been asked to assist a user trying to link Domoticz with Hubitat in a bidirectional real time implementation.
What I believe happens is that Domoticx publishes messages in a couple of selectable formats but always publishes all devices under one umbrella topic with the particular device identified by an idx key value within the json payload. What this results in as a consumer of such payloads is that I have to subscribe to this topic which updates for every Domoticz device and I have to examine and extract the json payloads and within that the idx key value to determine if I am even interested in 'this' device. This is totally inpractical as it consumes resources when I may not be even interested in the device update.
What I think should be considered is to include the idx within one of the topic hierarchies such that many different topics now become generated by Domoticz but a consumer can just choose to subscribe to specific ones of interest.
For example an existing topic might be
and I'm suggesting something along the lines of
the idx json value becomes redundant but does no harm
Now instead of a listener subscribing to domoticz/out/mqtt/mqttdevices/# I can subscribe to
domoticz/out/mqtt/mqttdevices/32 and I will only receive updates for that specific device.
I can create multiple individual subscriptions for the devices I am interested in and now not get flooded by irrelevant messages
This will be backwards compatible with your domticz/in/.. handling as you can just subscribe to
or
or even I a remote user just publishes to
as it is implemented currently.
Kevin
What I believe happens is that Domoticx publishes messages in a couple of selectable formats but always publishes all devices under one umbrella topic with the particular device identified by an idx key value within the json payload. What this results in as a consumer of such payloads is that I have to subscribe to this topic which updates for every Domoticz device and I have to examine and extract the json payloads and within that the idx key value to determine if I am even interested in 'this' device. This is totally inpractical as it consumes resources when I may not be even interested in the device update.
What I think should be considered is to include the idx within one of the topic hierarchies such that many different topics now become generated by Domoticz but a consumer can just choose to subscribe to specific ones of interest.
For example an existing topic might be
Code: Select all
domoticz/out/mqtt/mqttdevices = { json..., "idx"; 32, ...json }
Code: Select all
domoticz/out/mqtt/mqttdevices/32 = { json..., "idx"; 32, ...json }
Now instead of a listener subscribing to domoticz/out/mqtt/mqttdevices/# I can subscribe to
domoticz/out/mqtt/mqttdevices/32 and I will only receive updates for that specific device.
I can create multiple individual subscriptions for the devices I am interested in and now not get flooded by irrelevant messages
This will be backwards compatible with your domticz/in/.. handling as you can just subscribe to
Code: Select all
domoticz/in/*
Code: Select all
domoticz/in/#
Code: Select all
domoticz/in
Kevin