Websockets in rules to change item states instead of polling

Is it possible to integrate a websocket client into rules in order to change item states?

Until now I try to solve it with polling, like this:

rule "Get Sensors"
	Time cron "*/1 * * * * ?"
	var response = sendHttpGetRequest('')
	var String str_button
	str_button  = transform('JSONPATH', '$.XYZbutton.state.buttonevent',  response)

	[... some checks ...]


But the server also offers websockets, which I would like to use.

Does anyone have a good idea how to do it best? I have not found a corresponding binding.

Kai wrote something about the use of a websocket client library (such as from Jetty). But I do not understand how this would be integrated into rules.

Thanks for your support!

It wouldn’t.

There is not going to be anything you can do from Rules with websockets. That is something that is going to be implemented and handled in a binding and linked to Items and the Rule will trigger based on updates to that Item.

I don’t think there is a generic websocket binding and am not all that certain whether it is possible or even makes sense to have a generic websocket binding, not having worked with them before.

In the meantime, what you can do is subscribe to the websocket in a script running outside OH and that script can publish the push updates to OH through OH’s REST API, through MQTT, etc.

Okay thank you for your quick reply. :+1:

I think then I will continue to poll every second. Thus the whole logic remains within OH.

But a binding for web sockets similar to the TCP / IP binding or the HTTP binding would be very nice. :slight_smile: