[SOLVED] HTTP GET Command to Control Device via REST API

Now there are the errors of the rules :slight_smile:

2020-01-24 13:45:15.957 [WARN ] [.core.internal.folder.FolderObserver] - Error while opening file during update: C:\openHAB\conf\rules\testcase.rules
2020-01-24 13:45:16.342 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'testcase.rules'
2020-01-24 13:45:16.342 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'testcase.rules' is either empty or cannot be parsed correctly!
2020-01-24 13:45:17.584 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'testcase.rules' has errors, therefore ignoring it: [1,6]: no viable alternative at input 'â'

Don´t know what openHAB means at the last line

It does not help when you only post the errors here.

Please post your home.sitemap, home2.sitemap and your testcase.rules here.

Thanks.

It means it doesn’t like the content of your rules file.
Given the funny character, you probably need to look into the character encoding your editor uses when it saves a file.

Encoding is ANSI

home2.sitemap

sitemap home2 label="test ui" {
Switch item=test label="test"
}

testcase.rules

rule “testcase”

when
	Item test received update ON
then
    var url = "http://172.21.10.182/devices/1010013"
    var contenttype = "application/json"
    var PUTrequest = '{"name": "GOTO_POS_CMD", "value": 20}'

    var output = sendHttpPutRequest(url, contenttype, PUTrequest)
    
 
end

Your next job then, is to find out what encoding it should be for openHAB to use it.

1 Like

It should be:

rule "testcase"
1 Like

In comination of those two fixes it works now :slight_smile:
openHAB use UTF 8

Thank you for all who helped me. This is the best community! :heart_eyes:

1 Like

What I have to put in instead of the value 20 to make it variable?

Well, your variable PUTrequest is just a string.
In rules, you can make strings by joining them together, amongst other things.

var newstring = oldstring + “abc” + myItem.state.toString

Have you fixed your sitemaps, as well?

Please read also this topic.

This will be your complete solution.

Btw, there are other commands for HomePilot, too:

http://HomePilotIP/devices/deviceID

PUT with content type :application/json

SWITCH:

{"name":"TURN_ON_CMD"} 
{"name":"TURN_OFF_CMD"} 

THERMOSTAT:

{"name":"TARGET_TEMPERATURE_CFG","value":16}

LIST OF DEVICES:

http://HomePilotIP/v4/devices

DEVICE STATE:

GET
http://HomePilotIP/devices/deviceID
.
.

EDIT: @markymark

For your rollershutter the following commands also should work:

PUT

{"name":"POS_UP_CMD"}
{"name":"POS_DOWN_CMD"}
{"name":"STOP_CMD"}
1 Like