getToggleState() not working for GroupItem

Is it possible to check the state of a group item? I tried the following:

logInfo("Bewoners_Thuis", '"Alle_verlichting" staat nu '+Alle_verlichting.getToggleState())

I found getToggleState() in the documentation about item classes: https://openhab.github.io/openhab-js/items.Item.html#getToggleState.

But in the log, this warning appeared:

Script execution of rule with UID 'nietThuis-1' failed: 'getToggleState' is not a member of 'org.openhab.core.items.GroupItem'; line 21, column 65, length 33 in nietThuis

Is a GroupItem a different class? In the documentation (above) there seems to be no ‘chapter’ for it?

That’s JavaScript.
If the group is of type Switch, you can use

val myState = if(Alle_verlichting.state != ON) ON else OFF
logInfo("Bewoners_Thuis", "\"Alle_verlichting\" staat nu {}", myState)
1 Like

Aha. Thanks!

I should have used Java, I suppose? Is there an openHAB Java library (similar to https://openhab.github.io/openhab-js/)?

You can use whatever you want (and of course what is installed…)
Your code looks like DSL Rule script code (which is the native Script language in openHAB)

I suppose so, since I didn’t try to import any other languages :slight_smile:

Are there libraries for DSL or openHAB Java?

There is no reason to have a library for Java since a Java rule is interacting with the raw Java openHAB APIs. But I do think the JRule add-on does provide some things like annotations and such. I don’t know if it supports the full openHAB. API yet though.

The “DSL” in Rules DSL stands for “Domain Specific Language”. It’s a language written for and adopted to openHAB. It is it’s own library.

openhab-js exists to wrap and translate the raw Java openHAB API to make it work using JavaScript idioms and JavaScript Objects and Classes. You don’t need to do either for Rules DSL nor JRule.

Furthermore, Rules DSL doesn’t support libraries anyway.

I assume I misused the word ‘library’, apologies.

I meant documentation where one can see the methods each class supports, and what return they give. (Similar to the github link I cited above.)

Rules DSL: Rules | openHAB

I do not recommend Rules DSL for new rules development.

JRule: GitHub - seaside1/jrule: openHAB Java Rules Engine

Note that JRule is not an official OH binding (yet?).

jRuby: JRuby Scripting - Automation | openHAB

Blockly: Rules Blockly | openHAB

1 Like

Is that what’s found here: https://www.openhab.org/javadoc/latest/allclasses-index.html?

Thanks for your time by the way! :slight_smile:

Well, that’s pretty much all of openHAB. The raw Rules API stuff can be found documented at JSR223 Scripting | openHAB. But there really is little reason for you asn an ed user of OH to mess with anything at that low of a level.

Mmm, I was thinking of something like https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app for Google Script. As an end user, I use that to guide me when writing Google Scripts.

Without a ‘dictionary’ if you will, it’s hard to know which methods exist, and which don’t. E.g., which methods the class GroupItem has.

You may not like the format but all the same information is there.

jRuby and JS Scripting have the closest to what you are looking for. For JS Scripting in particular notice that there are links in the main docs to the JS equivalent of JavaDocs: items - Documentation

I’d be surprised if jRuby doesn’t have something similar.

1 Like

Thanks for your help. It’s a bit of a search in the beginning, so much appreciated. :slight_smile:

All the openhab api is accessible from jruby.

For JRuby library reference: Top Level Namespace — openHAB JRuby