The documentation on this isn’t clear at all (it really isn’t), but what i’m looking to do is log all the state changes and information coming out of OpenHAB to a remote MQTT broker (Mosquitto or HiveMQ). I want it to be a secondary connection (copy, or listener) and not local persistence, which should be different (Mongo or other NoSQL localised DB).
The remote cloud broker has other clients subscribing to it to record the messages to a centralised database, and is reacting to them to different ways which are not related to the specific OpenHAB device.
Let’s say i have 3 network devices (things) i want to ping every 60 seconds. I want the result of that ping to be sent as a JSON message to a remote Mosquitto instance on a VPS (i’m aware i’ll need a transformation potentially).
What i want is OpenHABian to keep its own persistence information, but for the remote MQTT Broker to receive 3 messages to 3 different topics (acting as both stateTopics and commandTopics), published to it by OpenHAB: Note the names need to be dynamic if possible.
room-name/network/device1/status --> state or command (R/W) as JSON payload
room-name/network/device2/status --> state or command (R/W) as JSON payload
room-name/network/device3/status --> state or command (R/W) as JSON payload
I also want ALL stateTopics and commandTopics sent to room-name/all.
I can seem to find a guide anywhere to this which doesn’t end in a maze of local/remote MQTT stuff. The goal is to create a stream of OpenHAB events monitored remotely, while allowing it to be configured as it wishes on a local level.
Is there a way to do this in PaperUI? All the examples with MQTT seem to involve config files.
Or you can set up and configure an Generic MQTT Channel for each Item individually and link them to all your Items using the follow profile. But that would be a whole lot more work.
I had a look through that article before but i got slightly lost in how it was applicable to my use case. I just saw you updated it so i’ll look again. Is it deprecated now in favour of the remote binding?
Could you quickly run through the procedure to set up the generic MQTT channel for each item? That in itself would be useful for testing.
There are certain use cases it can do that the remote binding cannot so it’s not deprecated by any means.
It’s standard MQTT stuff most of which is also covered in the EventBus tutorial. Create the Broker Thing. Create a Generic MQTT Thing. For each Item create and configure a Channel on the Generic MQTT Thing. Link the Channel to the Item using the Follow profile. If you stick to PaperUI it’s a whole lot of clicking the blue + icon and filling out forms, examples of which are in that tutorial.
OK, for anyone looking to do this and not deal with the insane amount of documentation parsing, this is the short version of how you get an item to publish its state to a remote MQTT broker. An elaboration on Rich’s notes.
Create a MQTT Broker thing (Inbox > Add > MQTT Broker). Fill in the remote details and give it a better name, like “Mosquitto Server”
Create a Generic MQTT Thing (Inbox > Add > MQTT Generic Thing). Select the remote MQTT Broker you created in 1) as the Bridge. Give it a better name like “MQTT Transmitter”. Save.
Figure out which Item you want to be sending and what type it is (Example: bulb color, Color).
In your Generic MQTT Thing, create a new channel, and pick its type (e.g. Color).
In the new window, give it an ID/name (e.g. bulb-1-color-update). Specify the topic on the remote server to publish updates to (stateTopic, /something/device-id/attributes/color) and its topic for commands (commandTopic). Also whether it should be retained, changed to JSON etc. Save.
Back in the Generic MQTT Thing screen where you created the channel, hit the “target” icon of the channel as normal, and create a link. The “type” from the first dropdown should be “Follow”, and the item you want to publish its data.
Change the item’s state, and in the MQTT broker the state of the item will be published into the queue, e.g. stateTopic-name = itemtype, or all-bulbs-color-update=126,210,5.
A. Create connection to a remote Mosquitto Server as a MQTT Broker.
B. Create a MQTT Transmitter/Bridge as a local Generic MQTT Thing. Make a new channel for the Item you want it to talk to which has the remote topic info and transformation in it.
C. Set the new channel on the Transmitter/Bridge you created to (listen to) Follow the Item.