[SOLVED] Enabling and disabling Things from for example Basic UI

Hello,

I use OH 2.4 on Raspi.

Simple question, but i find not answer :frowning_face:
I would like to make a switch that enables and disables one Thing.
We have this function in Paper UI


but how do i implement it in sitemap?

Thanks a lot!

Sitemaps only work with Items. There is nothing built in that would let you do that.

Similarly Rules mostly work with Items. There are a couple of things that can be done with Things from Rules but disabling is not one of them.

So the only way you may be able to do this is to create an Item that triggers a Rule that issues a command to the OH REST API. I can’t tell you what endpoint provides this but you can install the REST API Docs and explore those until you find it.

1 Like

It will be also ok to make it with rules. I have found the method that i need in RestApi Docs.
There is CURL request.

curl -X PUT --header "Content-Type: application/json" --header "Accept: application/json" -d "{}" "http://openhabianpi:8080/rest/things/network%3Apingdevice%3A15e46ce9/enable"

But only one way to implement RestApi in rules that i have found is this Curl and executeCommandLine with bash script.

Is there realy no direct way to use rest api from rules?

PS
As i underdtand right, in Paprr UI it works throught the http link when i click on it. It would be simpler solution, but i can not get this http link from source code.
Anyone know how to get it?

Thanks!

You understand incorrectly. PaperUI creates an HTTP PUT request with the same content as shown on the curl command.

1 Like

I got it.
But it there a real bug of Rest API?

I try to enable it, but it disables!
And i find no way no way to ebable with RestAPI ?

Here is the solution how to turn ON/OFF Thing via rules with help of RestAPI

sendHttpPutRequest("http://openhabianpi:8080/rest/things/network:pingdevice:15e46ce9/enable", "application/json", 'true')

where this network:pingdevice:15e46ce9 is thing ID taken for example from here

1 Like

I’ve trying to do the same. But unfortunately your solution doesn’t work for me. :frowning:

With curl and the REST API I can disable Things, but enabling isn’t working. Then I tried it with your sendHttpPutRequest solution, but here neither disable, nor enable is working.

When I’m changing the URL and looking at the webserver logs, a PUT request is incoming. So it looks like the sendHttpPutRequest command is working. But why the REST API is ignoring it? From Paper UI I can enable and disable Things without any problems.

Any ideas?

You have to send TRUE here

sendHttpPutRequest(“http://openhabianpi:8080/rest/things/network:pingdevice:15e46ce9/enable”, “application/json”, ‘true’)

1 Like

Ha! I found a solution. Seems like my openHAB2 needs other parameters. :smiley:

Disable Thing:

sendHttpPutRequest("http://<ip>:8080/rest/things/<thinguid>/enable", "application/json", 'enabled')

Enable Thing:

sendHttpPutRequest("http://<ip>:8080/rest/things/<thinguid>/enable", "application/json", 'true') 

Thanks for your help! :slight_smile:

3 Likes

Yes!
You can post false, enabled or anything you want to DISABLE thning.
But to ebanle you need to poost True :sunglasses:

1 Like

Hi folks,

when I disable a binding, I lose the link between item and thing in PaperUI. Maybe doing it manually via file should do the trick?

edit: it seems so!

Andrea

Hello All,

Seems this solution doesn’t work on OH3.
I am running OH3 and tried the solution but with no luck - nothing happened to thing…

Use of REST API changes for OH3

Is there a way to do this in OH3 or is it no longer possible thanks to authentication requirements? I wish this could be built into the rule logic. Occasionally some web services tend to go unresponsive (ie ecobee) and it would be nice to automate the disable/re-enable process that gets things going again

You can do this from rules, same as before.

1 Like