I only said to change user
client
and topic
. You need to leave full topic
as default, otherwise my other examples won’t work.
And yes, everything is case sensitive.
Edit:
My apologies, you should change the value of client
, not user
. Below are the settings you could use for your two devices, 4chPro2-1 and 4chPro2-2.
Device setup
Device 1: 4chPro2-1
Alter only Host
, Client
and Topic
. The screenshot below is what you should end up with.
Device 2: 4chPro2-2
Alter only Host
, Client
and Topic
. The screenshot below is what you should end up with.
MQTT Check
Now, using mqtt.fx publish the word ON
to the following topic. This should switch on the first relay on the first device:
cmnd/4chPro2-1/POWER1
I don’t use mqtt.fx, but do use MQTT Explorer. In MQTT Explorer, I would:
- Type the topic into the Topic field:
cmnd/4chPro2-1/POWER1
- Set type to
raw
- Write
ON
into the message field
- Click
PUBLISH
For the second relay on the first device, publish the word ON
to:
cmnd/4chPro2-1/POWER2
For the first relay on the second device, publish the word ON
to:
cmnd/4chPro2-2/POWER1
And so on. To turn those relays off, publish the word OFF
to each topic.
Once you have confirmed that you are able to control your device through mqtt.fx, you can move on to configuring openHAB. Do not move onto the next stage until the above works.
openHAB setup
These examples show how to configure using files: things files, items files and sitemap files. You can configure the thing through paperUI, but it’s much easier just to copy/paste into a file, than to share screenshots! The below also assumes you haven’t set anything up in openHAB yet - if you have, there may be strange results if you use the below.
mosquitto.things
Save a file called mosquitto.things into your openHAB things folder with the following inside. If you have not setup a username or password, leave the below as it is - otherwise, add your username and password between the " "
:
Bridge mqtt:broker:MosquittoMqttBroker "Mosquitto MQTT Broker" [
host="192.168.1.92",
secure=false,
port=1883,
clientID="OpenHAB2",
username="",
password=""
]
openHAB now has a connection to your Mosquitto broker!
devices.things
Save a file called devices.things into your openHAB things folder with the following inside:
Thing mqtt:topic:4chPro2-1 "Device 1" (mqtt:broker:MosquittoMqttBroker) {
Channels:
Type switch:relay1 "Relay 1" [
stateTopic="stat/4chPro2-1/POWER1",
commandTopic="cmnd/4chPro2-1/POWER1",
on="ON",
off="OFF"
]
Type switch:relay2 "Relay 2" [
stateTopic="stat/4chPro2-1/POWER2",
commandTopic="cmnd/4chPro2-1/POWER2",
on="ON",
off="OFF"
]
Type switch:relay3 "Relay 3" [
stateTopic="stat/4chPro2-1/POWER3",
commandTopic="cmnd/4chPro2-1/POWER3",
on="ON",
off="OFF"
]
Type switch:relay4 "Relay 4" [
stateTopic="stat/4chPro2-1/POWER4",
commandTopic="cmnd/4chPro2-1/POWER4",
on="ON",
off="OFF"
]
Thing mqtt:topic:4chPro2-2 "Device 2" (mqtt:broker:MosquittoMqttBroker) {
Channels:
Type switch:relay1 "Relay 1" [
stateTopic="stat/4chPro2-2/POWER1",
commandTopic="cmnd/4chPro2-2/POWER1",
on="ON",
off="OFF"
]
Type switch:relay2 "Relay 2" [
stateTopic="stat/4chPro2-2/POWER2",
commandTopic="cmnd/4chPro2-2/POWER2",
on="ON",
off="OFF"
]
Type switch:relay3 "Relay 3" [
stateTopic="stat/4chPro2-2/POWER3",
commandTopic="cmnd/4chPro2-2/POWER3",
on="ON",
off="OFF"
]
Type switch:relay4 "Relay 4" [
stateTopic="stat/4chPro2-2/POWER4",
commandTopic="cmnd/4chPro2-2/POWER4",
on="ON",
off="OFF"
]
openHAB can now communicate with the device through the MQTT broker.
devices.items
Save a file called devices.items into your openHAB items folder with the following inside:
Switch sDevice1Relay1 "Device 1 Relay 1" { channel="mqtt:topic:4chPro2-1:relay1" }
Switch sDevice1Relay2 "Device 1 Relay 2" { channel="mqtt:topic:4chPro2-1:relay2" }
Switch sDevice1Relay3 "Device 1 Relay 3" { channel="mqtt:topic:4chPro2-1:relay3" }
Switch sDevice1Relay4 "Device 1 Relay 4" { channel="mqtt:topic:4chPro2-1:relay4" }
Switch sDevice2Relay1 "Device 2 Relay 1" { channel="mqtt:topic:4chPro2-2:relay1" }
Switch sDevice2Relay2 "Device 2 Relay 2" { channel="mqtt:topic:4chPro2-2:relay2" }
Switch sDevice2Relay3 "Device 2 Relay 3" { channel="mqtt:topic:4chPro2-2:relay3" }
Switch sDevice2Relay4 "Device 2 Relay 4" { channel="mqtt:topic:4chPro2-2:relay4" }
openHAB has now got some items connected to your things channels. We can now manipulate these items using the sitemap or rules.
sitemap
In your sitemap file, add the following:
Switch item=sDevice1Relay1 label="Device 1 Relay 1 [%s]"
Switch item=sDevice1Relay2 label="Device 1 Relay 2 [%s]"
Switch item=sDevice1Relay3 label="Device 1 Relay 3 [%s]"
Switch item=sDevice1Relay4 label="Device 1 Relay 4 [%s]"
Switch item=sDevice2Relay1 label="Device 2 Relay 1 [%s]"
Switch item=sDevice2Relay2 label="Device 2 Relay 2 [%s]"
Switch item=sDevice2Relay3 label="Device 2 Relay 3 [%s]"
Switch item=sDevice2Relay4 label="Device 2 Relay 4 [%s]"
Your sitemap should now show you 8 switches, which you should be able to toggle on and off!