Guys,
Can we get a thing by it’s UID or Name?
I’ve looked on the forum and the closest I can get is this, posted in another thread:
import org.openhab.core.thing
import org.openhab.core.automation.thingsupport
rule "test switch"
when Item Test_Switch changed
then
t = Things.getThing("hue:bridge-api2:xxx-xxx-xxx");
logInfo("test",t.getLabel());
end
I am getting this validation error:
Script execution of rule with UID 'test-3' failed: 'getThing' is not a member of 'java.lang.Class<org.openhab.core.model.script.actions.Things>
Am I missing a library here?
Checking the docs I see that Things has no member named GetThing.
Is this even possible?
RulesDSL (the script language you are using if you are writing rules with the rule...when...then... structure, makes getting to the various registries a multi-step process. You also need ScriptServiceUtil which will then get you an instance of a thing registry. The get method of ThingRegistery also requires a ThingUID, which you will have to construct from a string. So you’ll need two imports, something like this:
Just copied and pasted your code, I get this error:
04:26:22.202 [ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with UID 'test-3' failed: The name 'ScriptServiceUtil' cannot be resolved to an item or type;
Additionally, how else can I do rules via script files?
I am literally willing to rewrite all my rules just to not have to use this awful scripting language. It’s like 10 lines of code = 10 hours of google. Every time.
Sorry about that, I haven’t used DSL in forever, it looks like I copied over some o my very oldest rules and didn’t change out the java path. The org.eclipse.smarthome stuff is long gone. The proper paths should be with org.openhab.core such as org.openhab.core.model.script.ScriptServiceUtil.
RulesDSL is, at this point, the least powerful of the scripting languages so if you’re trying to do anything at all complex it can get pretty tough (if not actually impossible), absolutely.
The good news is that you have several very good options. At this point the Blockly editor if very full featured. JSScripting (you will need the add-on installed if it is not) and JRuby (also add-on needed) can be done in files or in the UI and have extensive helper libraries for making things like this task easier. For example, the JSScripting docs are here:
Script execution of rule with UID 'test-1' failed: An error occurred during the script execution: Couldn't invoke 'assignValueTo' for feature JvmVoid: (eProxyURI: test.rules#|::0.2.0.2.0.0::0::/1) in test
Couldn’t find any ‘JSS Scripting’ add on, I tried installing the openhab-js, no difference that I can see. Although I didn’t have the same options in my setup that the guide was referring to (disable cache, for example).
So are you saying there is a language I can use that still goes in a rules file?
Not sure what you are doing, but click on the Automation tab when you are looking for Add-ons.
You will need to follow the instructions - you cannot use .rules files anymore. The extension and path is different or better switch to GUI based scripts. It is all documented in the docs.