How to subscribe to a topic from MQTT and display the value in a Hubitat virtual device?

I have a simple mosquitto MQTT broker running on my LAN (no SSL, anonymous auth) with various values available and would like to subscribe to a couple of topic values to use and display in Hubitat virtual devices like temperature sensors or contact switches. No need to publish, just subscribe to the value and use it in rules.

It seems like this should be easy but I can't find the right package or driver.

I found the dev docs at MQTT Interface | Hubitat Documentation but this is for writing drivers.

Several packages appear in the forums over the years but there is a lot of deprecated stuff.

Looks nice but seems to be for publishing from Hubitat, not subscribing

I tried for a couple of hours to get the 4 year old beta 3d working but every time I click 'Add User App' to install my Apps tab stops responding and I have to reboot to get it back. Then the app is not there even though the log said it was installed before the reboot.

Can someone please point me in the right direction to do this?

You do have to write a hubitat driver or otherwise acquire one. Especially for subscribing to a topic. As drivers go, MQTT is pretty simple. What device type do you want to deal with?

1 Like

I have some temperatures and contact sensors published into MQTT, some from 1-wire devices and some from a modbus interface to my furnace.

All of the values are easily accessible in topics, I just need to connect to the mosquitto broker and subscribe the virtual device to to the topic to display the value or contact sensor state.

Here is the link to my repo of drivers. The mqtt-virtual-switch.groovy is the simplest - the others are pretty specific to the devices I wanted to connect so the use case may not be apparent - contact me off forum if you like.

2 Likes

You need version 3e of the MQTT app available on request by PM.
The issue you encountered is a known bug in 3d

From the ccoupe post above it sounds like there may be simpler solution available there though. Your needs are quite straightforward

Thanks so much for the replies, I'll look these over for my application.

@ccoupe your mqtt-listen-switch.groovy was the perfect starting point for me as my goal was a simple subscription to contact and temperature sensor topics.

I made a couple of modifications to accept temperatures, handle my contact topic values of 0|1 and needed to change the contact value attribute from "close" to "closed" on line 90.

Works great and very easy to configure - thanks!

Are you able to share you modified driver please? I am looking for a temperature sensor listener too.

Happy to - here it is, hope it works for your use case:
https://justpaste.it/26xh5

Yay! Thank you for sharing! Works great. I am so happy that I can finally use HomeAssistant to control settings on my Hubitat!

Misbah