MQTT Subscription help?

Hey all,

So i currently have a door switch I update via curl and the REST API. I was looking to change that over to MQTT updates for “Switch1”. Does anyone have any samples i can use?

client is 10.1.100.200 using mosquito
server is openhab 10.1.100.23.

Doing some digging it looks like i can do something along the lines in bash like,

mosquitto_pub -d -t Switch1 -m "1"
or
mosquitto_pub -d -t Switch1 -m “2”…

thanks!!

The wiki has lots of info on getting up and running with MQTT. I’m not 100% sure what you are looking for. OH MQTT Wiki

Get the addon, setup the broker in the openhab.cfg and add some items. The commands you list are good for testing or monitoring MQTT activity outside of OH.

Adapted from my setup:

in openhab.cfg:

mqtt:broker.url=tcp://localhost:1883
mqtt:broker.clientId=openhab

in items:

Switch SW_mqtt1  "MQTT Switch"  {mqtt=">[broker:/home/room/switch1:command:on:1],>[broker:/home/room/switch1:command:off:0],<[broker:/home/room/switch1/state:state:default"}
Number NUM_mqtt1  "MQTT Temp"   {mqtt="<[broker:/home/room/temp/state:state:default"}
Contact Contact_mqtt  "MQTT contact"  {mqtt="<[broker:/home/room/motion/state:state:default"}

This will get you an on/off switch that also responds to an MQTT message updating state, a number for something like a temp, humidity, light sensor etc., and a contact for a security item such as motion or other.

The naming convention is up to you for the items, the broker or the topic you pub/sub to.

1 Like

awesome, thanks!!

1 Like