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

Tags: #<Tag:0x00007f51da5b8668> #<Tag:0x00007f51da5b8500> #<Tag:0x00007f51da5b8370>

(Michael) #1


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!

How to use rest api too disable thing
(Rich Koshak) #2

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.

(Michael) #3

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?

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?


(Rich Koshak) #4

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

(Michael) #5

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 ?

(Michael) #6

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

Reload Thing within Rule
(techlov3r) #7

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?

(Michael) #8

You have to send TRUE here

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

(techlov3r) #10

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:

(Michael) #11

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