I am disheartened to see a tutorial fro 2022 that still references OH 1.x bindings which were end of life over four years ago.
That tutorial will not work in any version of OH after 2.5.12 and even in 2.5.12 it will only work with the 1.x MQTT binding, not the newer and maintained binding.
In OH 3 and OH 4 you will need to (at a high level):
install the MQTT binding
create an MQTT Broker Thing
create a Generic MQTT Thing
create switch Channel on the Thing for each switch setting the command topic as appropriate
link the Item to a Switch Item
Alternatively, since this appears to only send commands to the switches and do not receive anything back
install the MQTT binding
create an MQTT Broker Thing
create Switch Item
create a Rule triggered when the Item receives a command; in the rule use the publishMQTT Action to publish the message on the topic.
Installing the MQTT binding and creating the Things are covered in the Getting Started Tutorial.
I will try to dig deeper into this topic and get it into my head.
Most of the steps you explained I already have successfully done:
I am stuck at:
What I need to learn is the syntax and the exact commands to send. This is where I need a little push into the right direction. I will try to read more about this and hope I get this sorted in my little old brain.
At the end this is just a starter Project and I would like to follow up with a 433MHz Weatherstation where I also need to receive some data. But that for later. First some babysteps.
This is part of a MQTT .things file that I use. It may give you an idea of the syntax to create the thing. This thing is one of the Sonoff S31 power switches that I use for Christmas tree lights. Your channels and topics will need to match the requirements for your device.
Bridge mqtt:broker:MqttBroker [
host="10.0.0.100,
port="1883",
secure=false,
username="OptionalMqttUserid", password="OptionalMqttPassword",
clientID="OpenHab"]
{
Thing topic ChristmasTreeThingId "ChristmasTree" {
Channels:
Type switch : power "Power" [stateTopic="ChristmasTree/stat/POWER", commandTopic="ChristmasTree/cmnd/POWER"]
Type string : sleepmode "Sleep Mode" [stateTopic="ChristmasTree/tele/STATE",transformationPattern="JSONPATH:$.SleepMode"]
Type number : sleep "sleep" [stateTopic="ChristmasTree/tele/STATE",transformationPattern="JSONPATH:$.Sleep"]
Type number : loadavg "Load Average" [stateTopic="ChristmasTree/tele/STATE",transformationPattern="JSONPATH:$.LoadAvg"]
Type number : wifiap "WiFi" [stateTopic="ChristmasTree/tele/STATE",transformationPattern="JSONPATH:$.Wifi.AP"]
Type string : wifissid "SSID" [stateTopic="ChristmasTree/tele/STATE",transformationPattern="JSONPATH:$.Wifi.SSId"]
Type string : wifibssid "BSSID" [stateTopic="ChristmasTree/tele/STATE",transformationPattern="JSONPATH:$.Wifi.BSSId"]
Type number : wifichannel "Channel" [stateTopic="ChristmasTree/tele/STATE",transformationPattern="JSONPATH:$.Wifi.Channel"]
Type number : wifirssi "RSSI" [stateTopic="ChristmasTree/tele/STATE",transformationPattern="JSONPATH:$.Wifi.RSSI"]
}
}
This associated Items file is
Switch ChristmasTree "ChristmasTree [%s]" {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:power"}
String ChristmasTreeSleepMode "ChristmasTree Sleep Mode [%s]" {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:sleepmode"}
Number ChristmasTreeSleep "ChristmasTree Sleep [%d]" {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:sleep"}
Number ChristmasTreeLoadAvg "ChristmasTree Load Average [%d]" {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:loadavg"}
Number ChristmasTreeWifiAP "ChristmasTree AP [%d]" {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:wifiap"}
String ChristmasTreeWifiSSID "ChristmasTree SSID [%s]" {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:wifissid"}
String ChristmasTreeWifiBSSID "ChristmasTree BSSID [%s]" {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:wifibssid"}
Number ChristmasTreeWifiChannel "ChristmasTree Channel [%d]" {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:wifichannel"}
Number ChristmasTreeWifiRssi "ChristmasTree RSSI [%d]" {channel="mqtt:topic:MqttBroker:ChristmasTreeThingId:wifirssi"}
Adding Things - Advanced | openHAB shows all the steps for all of these through the UI. I don’t do .things files so if that’s your thing hopefully you can find some examples on the forum or some other help. I consider it a waste of time to fight syntax errors when I can be fighting home automation errors instead.