Hi @snell, thanks for the reply.
For webhooks like what this seems to provide, I have had good results with the Hubitat websocket interface for unsolicited traffic. I typically open the websocket connection in my initialize()
function and just leave it open for the lifetime of the driver. For example, it works well in my Bose SoundTouch driver.
I typically take a pretty dumb approach since the data in the webhook message often differs from the typical HTTP APIs. If you have an active websocket and Hubitat receives a message on the socket, it gets passed to parse()
. I do the bare minimum to make sure it's a webhook reply and not something else, and then I do data refreshes with the normal HTTP APIs. I see two benefits: I can space out the polled refresh interval; and I get snappier refreshes when something changes.
I cribbed the code that I linked to and was able to connect from Hubitat to the websocket server on my Unifi controller. The rest of my Unifi hardware got here today but is still in boxes, so I'll report back later on whether it actually behaves as expected.