Another option is to use the REST API to get events in real time.
The /rest/events
respects the server-sent events standard which is simple enough and there are libraries implementing it in virtually every language.
You can also use curl http://ip:8080/rest/events
to see how it works, you’ll get something like:
event: message
data: {"topic":"openhab/items/LocalSun_Azimuth/statechanged","payload":"{\"type\":\"Quantity\",\"value\":\"346.7888569661049 °\",\"oldType\":\"Quantity\",\"oldValue\":\"345.2162184374848 °\"}","type":"ItemStateChangedEvent"}
whenever something happens, and you can filter events by topic, for instance
http://ip:8080/rest/events?topics=smarthome/items/*
to get all items-related events.or
http://ip:8080/rest/events?topics=smarthome/items/*/statechanged
to get all state changes.
(note: the first part of the topic has recently been changed from smarthome
to openhab
)