In DSL I want to loop through all things and get some properties (like all things being OFFLINE)
I know how to do it with items:
var strThing = ScriptServiceUtil.getItemRegistry.getItems()
I tried a few days to find an equivalent command for things like these:
but these do not work.
Could anybody please guide me in the right direction?
Please keep in mind, I do not need a comand to get properties of a specific thing. I need a command which returns ALL things.
I don’t think there is any equivalent.
You can get the list of Things through the REST API in JSON format and then search through that list to find the Thing(s) the Item is linked to. I’m not so certain that will be any better that your current approach. The call would be something like:
val allThings = sendHttpGetRequest("https://openhabserver:8080/rest/things")
Install and play around with the REST API docs for details and to see the JSON you get back. You might be able to use a JSONPATH string to go straight to the Things you wa…
yes, forgot to mention this in my original post that I have this in mind as plan b.
And thank you for your reply.
Let’s see if some developers see any way to achieve this.
Maybe I see it too much simplified but I was hoping to do a class
here and use one of these commands:
Still learning. Please forgive any nonsense question.
An example of the method you are looking for is used here:
publishMQTT not working as advertised in OH3 - #11 by rlkoshak . I am not sure if that helps.
unfortunately not. this is about getting thing status of a pre-defined thing (UID).
I need a function which returns ALL things
I have actually done this in the java rule engine jrule, as an experiment. I can readd the code if you are interested.
Write OpenHAB Rules using Java
This automation package aims to enable Java development of OpenHAB Rules. The addon will allow the user to create custom OpenHAB rules
in one or several .java-files. The Java Rules will need defined triggers in order for the engine to know how and when to execute them. The triggers
are very similar to the triggers in Rules DSL but expressed using java annotations. In order to execute rules based on items defined in OpenHAB either in .items-files or the G…
I read your other thread. I think switching to java will exceed my little experience in xtend.
However, if there is some help available (example codes) I definitely would like to have a look at that.
Access to things like the Thing Registry and Item Registry is more involved than just importing a class. The Item registry gets injected into the rule when it runs. These need to be populated and linked to the actual data that openHAB is using.
So you need to get access to the ItemRegistry or ThingRegistry through
org.openhab.core.model.scriptScriptServiceUtil. However, the ThingRegistry doesn’t provide a getThings() method.
The only way to get at all the Things is to query the REST API and parse the JSON that gets returned.
Hey Rich, thanks a lot for making this clear to me. A different or complementary approach I am pursuing is to get an event if the status of things changes.
I know that can be done by rule but the solution Yannick came up with is by for leaner.
May I ask you to have a look at this thread.
That is such wonderful solution but I am stuck.