I would like to disable/ enable things from a rule
This is the command I use
sendHttpPutRequest(“http://192.168.123.10:8080/rest/things/ipcamera:onvif:OnvifCamera/enable”, “text/plain”, ‘false’)
And this is the error I am getting in OH log file
2022-02-23 14:18:00.935 [ERROR] [enhab.core.model.script.actions.HTTP] - Fatal transport error: java.util.concurrent.ExecutionException: org.eclipse.jetty.client.HttpResponseException: HTTP protocol violation: Authentication challenge without WWW-Authenticate header
Using API explorer enable/disable the thing works fine.
As usual I expect the problem to be in front of the computer. What am I doing wrong?
Thanks a lot. I tried now with ECMAScript 5.1 but get the following Error.
TypeError: ThingManager.setEnabled is not a function in at line number 7
This is my code
var FrameworkUtil = Java.type(“org.osgi.framework.FrameworkUtil”);
var _bundle = FrameworkUtil.getBundle(scriptExtension.class);
var bundle_context = _bundle.getBundleContext();
var ThingManager = bundle_context.getServiceReference(“org.openhab.core.thing.ThingManager”);
var ThingUID = Java.type(‘org.openhab.core.thing.ThingUID’);
Then I don’t know what could be wrong. That’s how it’s supposed to work but I haven’t used ECMAScript 5.1 in quite some time. It’s way easier in ECMAScript 2021 and since 5.1 is definitely going to go away at some point it’s probably not the best use of one’s time.
Thank you so much for your help. I am a kind of newby to ECMA scripts.
Do you perhaps have a short sample how it should be done in ECMAScript 2021?
I only get items and so on but when I start with things. I do not get any completion suggestions
Well, it’s not really usual to mess with Things from rules, which is why the API isn’t really there and straight forward. What are you really trying to accomplish? Typically you would be working with Items, not Things.
With the JS Scripting add-on installed it should be something like
var thingMgr = osgi.getService('org.openhab.core.thing.ThingManager');
var ThingUID = Java.type('org.openhab.core.thing.ThingUID');
thingMgr.setEnabled(new ThingUID('thing:uid:string'), false);
That works. Thank you so much.
after reboot my Homematic takes too long to come up. So I need to disable and enable it again after a couple of seconds.
Hallo.
Habe das selbe Problem wie Du. Kannst Du mir sagen welche Dateien ich anlegen muss usw. um das Thing robonect.things, bzw den String"robonect:mower:automower" über einen Schalter Disable und danach wieder Enablen kann?
Danke.
Gruß Tobi
This doesn’t work for me: 14:47:19.359 [ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with UID 'test-1' failed: The name 'osgi' cannot be resolved to an item or type; line 32, column 20, length 4 in test