After days of trial and error and reading, I have moved all my switches from MQTT 1.x to 2.x binding, OH 2.5.
Success
Most of my switches are easy ON/OFF types, nothing fancy going on.
I have things working, and MQTT 2.5 is working well, and MQTT Explorer observes all the events just fine.
ISSUE
My current MQTT 2.x items have multiple inbound, outbound messages to drive different user interfaces, and drive an I2C controlled switch board/relay controller.
Things seem to be constrained to using one Command
topic, and one State
topic.
MQTT Topics and message summary;
- /first two rows are dedidcated to driving OpenHab Item logic - these have been moved into Thing format OK and work well.
- /Switchboard drives I2C logic for operating relays
- /HMI drives touch screens for panel status updates, and receiving touch commands
Maybe I’ve built myself a birds nest of logic, but it has worked well and I’m very happy with it.
Current state of my MQTT 2.x ITEMS file - example
Switch KitchenLightSwitch1 “Kitchen 1” (gAllLights,gAllKitchenLights) [ “Lighting” ]
{channel = “mqtt:topic:pi4MqttBroker:KitchenLightSwitch1:light”,
autoupdate=“false” ,mqtt="
<[broker:myhome/kitchen/light/switch/row1/command:command:MAP(arduino.map)],]
<[broker:myhome/kitchen/light/switch/row1/command:command:MAP(arduino.map)],
>[broker:myhome/switchboard/switchboard1/command:command:ON:A,1,1],
>[broker:myhome/switchboard/switchboard1/command:command:OFF:A,1,0],
>[broker:myhome/HMI/page0/kitchen/light/switch/row1/state:state:ON:1],
>[broker:myhome/HMI/page0/kitchen/light/switch/row1/state:state:OFF:0],
My new MQTT 2.5 Thing configuration looks like this, and is working well… but only one Command, and one State.
Thing topic KitchenLightSwitch1 “Kitchen LightSwitch1 .thing” @ “Kitchen” {
Channels:
Type switch : light “Kitchen LightSwitch1 .thing” [ stateTopic=“myhome/kitchen/light/switch/row1/state”, commandTopic=“myhome/kitchen/light/switch/row1/command” ]
}
Question:
What is the proper design pattern to move my list of 1.x MQTT pub/sub logic to a “Thing
”?.. or maybe I dont.
Each Thing
seems constrained to one command, and one topic… i need a few more.
From reading, and seeing what other people drive MQTT logic with, I think I'm supposed to move the logic into
Rules, and fire off the needed MQTT messages using
Rules?
I need to manage the last 4 rows MQTT 1.x Pub Sub
messages to somwhere.
[broker:myhome/switchboard/switchboard1/command:command:ON:A,1,1],
[broker:myhome/switchboard/switchboard1/command:command:OFF:A,1,0],
[broker:myhome/HMI/page0/kitchen/light/switch/row1/state:state:ON:1],
[broker:myhome/HMI/page0/kitchen/light/switch/row1/state:state:OFF:0],
Is using Rules the best approach? Is Rules the best/correct design pattern?
Or maybe there is another Thing type I can use to get the same result?