My setup:
I have installed openHAB on a Pi and everything is fine. Now I want to send itemstate updates via mqtt to a Broker. I have used the MQTT Persistence and after a short time it works well.
As topic I use the second parameter “topic=%2$s” where I safe the room and the sensortype in the item alias.
Example: <bath/motion> as item alias for the motion sensor in the bath and my topic for mqtt is ready.
Now my problem is that I want to send the “hostname” from my Pi at the first position in the topic.
Example: topic=“hostname”/“room”/“sensortype”.
Of course I can make it as String, but I want it dynamically as variable, so that openhab automatically set the hostname if I write something like “$HOSTNAME”.
Is that possible?
I think there are two ways to do this.
First I can write it in the item alias.
Or maybe there is an extra parameter (5$) for the hostname and I can write directly in the mqtt-persistence. OK, I know that doesn’t work in the moment, but maybe somebody can expand the mqtt binding for this wonderful feature.
Maybe someone has another better approach. I am very open for creative ideas.
I want to do this from mqtt messages I send it FROM openHAB to a Broker.
I will make a little example in an application case:
I have two appartments with openHAB home automation. There is a Pi with openHAB in each appartment. In addition, I still have a Broker where I will send the itemstates of every motion sensor from each apartment.
Now I would like to have the same configuration files on each Pi. So I can’t set the “hostname or IP” in the configuration files of the Pi.
If I am a Subscriber on the Broker now, I only see at the topics “roomName”/“sensortype” (corridor/motion for example) but not from whom the message comes. Unfortunately there is no parameter in the MQTT protocol for the Publisher. So I want it make directly in the topic like “hostnameOfThePi”/“roomName”/“sensortype”.
Is there a way for it?
I hope with the example it is more clearly what I mean.
But if something is still unclear, then ask quietly.
OK thanks, I get it.
I am afraid I can’t help you with that. I would think maybe a JSON carrying the required variable would be a last resort but that isn’t really a friendly way, nor exactly what you want