There’s much information here on MQTT in general, and in rules in general, but somehow I can’t find the magic topic that answers my question.
I’m new to OpenHAB, and new to MQTT. I installed OpenHAB on a Debian machine using the APT repositories.
The following add-ons are installed (among others, but these seem to be applicable to my question):
ui-paper - 2.5.2
misc-mqttbroker - 2.5.2 (not using it for anything at the moment)
misc-ruleengine - 2.5.2
binding-mqtt - 2.5.2
What I want to do:
I want to read a field from a Victron controller, similar to what’s done in this topic. Peculiarity of the Victron controller: it publishes its serial number the whole time, but not other data, unless you publish something to it. Hence the cron job in the topic I linked that publishes an empty field to the controller every 30 s.
What I have done:
I have created a victron_mqtt_broker thing (no channels).
I have created a generic victron thing (one channel, reading some AC value).
^^This works. If I publish an empty value to an MQTT topic on the controller, my generic victron thing receives the value I’m looking for.
What I have tried:
I have tried to create a ccgx.rules file similar to the one I linked. This doesn’t seem to do anything.
I have tried creating a rule via the PaperUI’s rule interface. The cron part works. The MQTT part is confusing - the only option I get is what broker to use, but not what topic to send to or what command to send to that topic.
I have created a channel for the generic victron thing linked to an MQTT command topic. I then linked my rule to that topic, sending something (blank or random text) to that topic. This triggers per the cron job, but doesn’t actually publish anything.
Any suggestions? There’s an abundance of information on here on all the topics I’m interested in, but it seems to me as though some of the MQTT related topics are for older versions of either OH or MQTT, and I find it pretty hard to find what’s relevant for my current install.
Generalism; PaperUI rules graphical editor - it’s a bit pants at the moment.
The vast majority of rules you currently find is this forum are created with a text editor and saved in files. There’s more than one rules system, or language.
You’ve missed the significance of Items in openHAB. Rules and UI generally operate on Items- idealized simple model devices. Channels are the data pathways linking Items to more real-world specific Things.
To publish MQTT, you would usually set up a Thing and channel(s) with topic details etc., link that to an Item, and send commands to the Item (from rule or UI) that eventually become MQTT payloads.
I’ll migrate from misc-mqttbroker - 2.5.2 to mosquitto, that’s pretty easy.
@rossko57 - what is better practise: to create one thing for the controller device, with multiple channels, or to create multiple things to the same controller device? My second attempt at creating a rule was to add a channel to the Thing with only an MQTT Command Topic in it. I didn’t get it to work, but if the Rule prefer to have a Thing between itself and the MQTT publish command, then I was sort of on the right track.
You need to create a broker Thing, for the pathway from openHAB to the actual broker.
Then there’s two completely different ways to publish messages.
From a rule, you can use an action to send, via that broker Thing, to any arbitrary topic you like.
That’s of limited value because it’s one-way only, outbound.
The more conventional way is to define a further Thing, which corresponds to some device or service.
You’d likely define several channels for that Thing, each may be set to different topics, for sending or subscribing (recieving).
You link each channel to Items, which reflect incoming subscribed states. And you can send commands to Items from UI or rules, which get sent out as topic payloads as/when defined.