Integration Solutions using MQTT

That’s a bummer. Does the creator device show that it is connected and does it list both topics in the subscribed topics field? What happens when you tap the Refresh button?

Last night I went ahead and created all my zones, none worked. This morning, they all work. I’m beginning to think this is more of a flakey ST transition thing more than anything else. Used a device in a routine and it worked perfectly. Very happy at the moment. I’ll continue to check what each new day brings but all seems well. :grinning: I did notice that ActionTiles doesn’t recognize these devices but I’m assuming that’s an ActionTiles issue as we transition. Thanks everyone for your help.

Side note: I am so impressed with this app: easy install and deployment and very logically laid out. MQTT integration is not a top-10 smart home user request I’m sure so that fact that Todd pulled this off is absolutely amazing. This app, as well as the virtual edge driver will allow me to survive the ST transition. Thank you!

2 Likes

I’m looking at the code today and I think there are some changes I can make that could improve recovery from connection failures. Will be back with an update…

1 Like

I’ve pushed a update to the MQTT Devices driver. Given the reports of instability and disconnects by @raisingskell and @gst, I’ve tried to to beef up recovery from disconnects.

If the connection with the broker cannot be made at driver startup, or is later lost after successfully connecting, the driver will retry every 15 seconds to (re)establish the connection. Once established, all topics will be (re)subscribed. The status field in the creator device will tell you of any reconnections, and you can also look in the device History to see prior status changes.

Also, remember that you can tap the Refresh button at the bottom of the creator device Controls screen and this will force a disconnect/unsubscribe all/reconnect/re-subscribe all sequence.

New driver version: 2022-11-20T02:05:26.759176946

Please let me know of any further issues.

In my experience it disconnected randomly (unrelated to a reboot of the hub or due to inactivity) and almost immediately showed “reconnecting” and “connected” but until I clicked the refresh it wouldn’t recieve topic messages.

I changed to using post/get messages which has been much more reliable, so I won’t be able to verify if this update has fixed the problem.

hi mqtt is not working for me at all today in or out of smartthings , im getting this error
? Select a driver. 7
2022-11-20T14:36:48.472944812+00:00 TRACE MQTT Devices V1 Received event with handler capability
2022-11-20T14:36:48.478509562+00:00 INFO MQTT Devices V1 <Device: c48b3040-c2d3-447f-86c4-f19b1399ed50 (MQTT node red)> received command: {“args”:{},“capability”:“switch”,“command”:“on”,“component”:“main”,“positional_args”:{}}
2022-11-20T14:36:48.484075062+00:00 TRACE MQTT Devices V1 Found CapabilityCommandDispatcher handler in MQTT Devices
2022-11-20T14:36:48.487840603+00:00 INFO MQTT Devices V1 Switch triggered: on
2022-11-20T14:36:48.493526728+00:00 INFO MQTT Devices V1 <Device: c48b3040-c2d3-447f-86c4-f19b1399ed50 (MQTT node red)> emitting event: {“attribute_id”:“switch”,“capability_id”:“switch”,“component_id”:“main”,“state”:{“value”:“on”}}
2022-11-20T14:36:48.526810020+00:00 ERROR MQTT Devices V1 MQTT node red thread encountered error: [string “st/dispatcher.lua”]:233: Error encountered while processing event for <Device: c48b3040-c2d3-447f-86c4-f19b1399ed50 (MQTT node red)>:
arg1: table: 0x2662940
[string “cmdhandlers.lua”]:32: network connection is not opened
2022-11-20T14:37:09.246457204+00:00 TRACE MQTT Devices V1 Received event with handler capability
2022-11-20T14:37:09.320969013+00:00 INFO MQTT Devices V1 <Device: c48b3040-c2d3-447f-86c4-f19b1399ed50 (MQTT node red)> received command: {“args”:{},“capability”:“switch”,“command”:“off”,“component”:“main”,“positional_args”:{}}
2022-11-20T14:37:09.327614730+00:00 TRACE MQTT Devices V1 Found CapabilityCommandDispatcher handler in MQTT Devices
2022-11-20T14:37:09.330637343+00:00 INFO MQTT Devices V1 Switch triggered: off
2022-11-20T14:37:09.333944522+00:00 INFO MQTT Devices V1 <Device: c48b3040-c2d3-447f-86c4-f19b1399ed50 (MQTT node red)> emitting event: {“attribute_id”:“switch”,“capability_id”:“switch”,“component_id”:“main”,“state”:{“value”:“off”}}
2022-11-20T14:37:09.349364891+00:00 ERROR MQTT Devices V1 MQTT node red thread encountered error: [string “st/dispatcher.lua”]:233: Error encountered while processing event for <Device: c48b3040-c2d3-447f-86c4-f19b1399ed50 (MQTT node red)>:
arg1: table: 0x261eca0
[string “cmdhandlers.lua”]:32: network connection is not opened
listening for logs… done

nevermind just rebooted smartthings hub and its working fine .
martin

1 Like

OK, leave it to me to ask the dumb questions. :face_with_open_eyes_and_hand_over_mouth: I’m assuming I update the driver for each device? When I go to select a new driver there’s no MQTT Devices driver listed. I then went to the channel to uninstall and re-install MQTT Devices and I get an uninstall error “unexpected error Request failed with status code 504 (code undefined)”. How do I update the MQTT Devices driver?

You don’t have to do anything; the driver is automatically updated on your hub (for all devices) when I update it on the channel. Supposedly it can take up to 12 hours for updates to reach your hub, but it’s usually much faster.

You can check what driver version you have by tapping the three-vertical-dot menu icon in the upper right of your creator device Controls screen, and tapping ‘Driver’.

Had you tried tapping the Refresh button? If that’s not correcting things I’d like to figure out why not. You really shouldn’t have to be rebooting your hub.

Yes i tried refreshing , restating mqtt broker even removing mqtt device creator and re adding it .

OK, sorry for the hassle. I’ll see if I can recreate the problem or figure out what may be happening from your logs (thanks for providing).

1 Like

its no hastle at all ,
thanks
martin

does this work with lights too? or just switches motion sensors etc?

I can provide support for just about any device type that you need. A basic light is just a switch, so you could always create a switch device and change its icon to be a light :slight_smile:

1 Like

is anyone using this with home assistant? and if so how? has anyone installed a mosquitto broker or do you need a separate device? and then how do you see your devices from st in ha? does it work both ways? or is it just ha see states change of st devices?

i have managed to recreate it myself lol, i was making a backup of my pi sd card , after trying the new card and putting the old card back in the mqtt on smartthings is not working again.
? Select a driver. 7
2022-11-22T16:13:56.430896124+00:00 TRACE MQTT Devices V1 Received event with handler capability
2022-11-22T16:13:56.442244582+00:00 INFO MQTT Devices V1 <Device: 1a06768e-78d0-4029-982e-16135905efd6 (MQTT Device Creator V1)> received command: {“args”:{},“capability”:“partyvoice23922.refresh”,“command”:“push”,“component”:“main”,“positional_args”:{}}
2022-11-22T16:13:56.445644290+00:00 TRACE MQTT Devices V1 Found CapabilityCommandDispatcher handler in MQTT Devices
2022-11-22T16:13:56.448573415+00:00 INFO MQTT Devices V1 Refresh requested
2022-11-22T16:13:56.452546582+00:00 ERROR MQTT Devices V1 MQTT Device Creator V1 thread encountered error: [string “st/dispatcher.lua”]:233: Error encountered while processing event for <Device: 1a06768e-78d0-4029-982e-16135905efd6 (MQTT Device Creator V1)>:
arg1: table: 0x1f03b98
[string “cmdhandlers.lua”]:50: attempt to call a nil value (global ‘init_mqtt’)
listening for logs… done

C:\Users\monty>

Thanks. This one looks like a different issue from the one you posted earlier.

In this post, it looks like the driver was no longer connected to the broker and so when it was trying to publish messages, they were failing.

In this more recent log there is a driver error which I could have sworn I already fixed!

I checked the channel and it was still showing the previous driver version(!), so I’m thinking that somehow my last update didn’t get pushed out. I just submitted it again: Version 2022-11-20T02:05:26.759176946, so please confirm that you get it, and let me know if you continue to see any errors.

just updated the driver and no errors at all .
thank you
martin

Hi Robert - as no one has responded, let me offer a couple thoughts even though I’m not familiar with HA:

  1. I don’t know if Mosquitto comes with HA or is possibly an add-on. Regardless, installing the Mosquitto broker is very simple. You could probably install it on whatever you are running HA on (Raspberry Pi)? Or you could put it on a separate machine. You just need something that is going to be online all the time.

  2. If you have an IOT device that published MQTT messages, you could have both HA and SmartThings act on those messages simultaneously.

  3. If you set up an MQTT device in SmartThings using my driver, then those devices can publish MQTT messages whenever a command is issued (switch on/off, etc.). If you have a driver/plugin/or whatever they are called in HA, that can be configured to look for certain MQTT topics, then this is one way you could have HA “see” your SmartThings MQTT devices.

  4. Conversely, if you have HA devices that publish MQTT message to a certain topic, then you could configure a SmartThings MQTT device to also look for those messages and act on them.

The net is that as long as something is publishing MQTT messages, then you can generally configure an MQTT-enabled app to receive and act on those messages. MQTT messages are all sent using a “topic” which is basically a structured way to categorize messages. You just need to know what topic is being used for the messages you are interested in.

EDIT: There is one more scenario I’ll mention but it may involved more than you want to get into: I have a SmartApp that can run on a local machine that can publish MQTT messages for just about ANY SmartThings device. They don’t have to be specifically MQTT enabled. It works by subscribing to whatever device types you choose and whenever a state change happens it publishes an MQTT message on a particular topic. Again, if you have an HA function that can be configured to look for certain MQTT topics, then this is another way to integrate ANY SmartThings device. The downsides are that it involves more setup and it relies on the Cloud, so is not 100% local.

2 Likes