[SOLVED] HttpGet rule with variables

Hope someone can help me out here.

I can successful control the unit with this Http request
http://192.168.100.145/send_ir_dke.html?power=1&mode=3&fan=2&temperature=18&vswing=6&hswing=5

What I want to do is the possibility to have

Power
Mode
Fan
Temperature
Vswing
Hswing

As variables I can change before sending the request.

Best Nanna

Do you want the result from this HTTP request or do you mainly care about just sending the request to cause something to happen?

If you care about the result, you will have to use the the sendHttpGetRequest Action and build up the URL in a Rule.

If you don’t care about the result, the following might work. I’ve never done this so it also might not in which case you will have to use a Rule and sendHttpGetRequest as well.

String MyItem { http=">[*:http://192.168.100.145/send_ir_dke.html?power=%2$s&mode=%3$s&fan=2&temperature=%4$s&vswing=%5$s&hswing=%6$s]" }

And you would trigger the call with

MyItem.sendCommand("1,2,3,4,5,6")

I really do not have much hope that this will work, but it would be cool if it did.

This is an IR transmitter controlling my Heatpump, so I won’t have any feedback from the unit.

I just need to the request to cause something to happen.

I want to have all 6 variables changeable and send to the Http Request :slight_smile:

Right, so you can try the binding example I presented above which uses the String.format notation to split out the six variables and insert them into the URL. You sendCommand the values of the six variables in order.

Or, if that won’t work, you need to have a Rule and build up the URL String and use sendHttpGetRequest.

Super Ill give it a try - Thanx :slight_smile:

When I try to declare the Item I get this below error


08:41:54.708 [ERROR] [del.item.internal.GenericItemProvider] - Binding configuration of type 'http' of item 'PanHP' could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: bindingConfig '*:http://192.168.100.145/send_ir_dke.html?power=%1$s&mode=%2$s&fan=%3$s&temperature=%4$s&vswing=%5$s&hswing=%6$s' doesn't contain a valid out-binding-configuration. A valid configuration is matched by the RegExp '(.*?):([A-Z]*):(.*)'

@Nanna_Agesen

I didn’t work… :frowning_face:

You will have to build that string in a rule and use the sendHttpRequest action

1 Like

I’ll try going the other way then :slight_smile:

Can you explain how I pass a variable from eg. a Number selection to the Url sendHttpRequest string?

How are your items defined?

My Items are defined as number, and I need to pass the selected number to the url string.

rule "http string"
when
    whatever trigger
then
    var String httpString = ""
    val String number1Str = item1.state.intValue.toString
    httpString = "http://192.168.100.145/send_ir_dke.html?power=" + number1Str
    val String number2Str = ...
    ...
    val String response = sendHttpGetRequest(httpString)
end

I’m just testing with variabel

rule "http string"
when
    Item Panasonic_RunSet changed
then
    var String httpString = ""
    val String number1Str = Panasonic_RunSet.state.intValue.toString 
    httpString = "http://192.168.100.145/send_ir_dke.html?power=" + number1Str
    val String response = sendHttpGetRequest(httpString)
    
end

Do you have any idea what this error is?

09:34:59.554 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'http string': 'intValue' is not a member of 'org.eclipse.smarthome.core.types.State'; line 14, column 29, length 31

Try:

    val String number1Str = Panasonic_RunSet.state.toString("%d")

That seems to work, however I need to parse the complete request

http://192.168.100.145/send_ir_dke.html?power=1&mode=3&fan=6&temperature=20&vswing=2&hswing=1

I really don’t know to “split” the httpstring so it contains static text and the 6 variables?

Hope I explained it ok?

rule "http string"
when
    Item Panasonic_RunSet changed
then
    var String httpString = ""
    val String number1Str = Panasonic_RunSet.state.intValue.toString("%d")
    httpString = "http://192.168.100.145/send_ir_dke.html?power=" + number1Str
    val String number2Str = item2.state.toString("%d)
    httpString = httpString + "&mode=" + number2Str
   // ...
   // Carry on like this with all the other values until your httpString is complete
    val String response = sendHttpGetRequest(httpString)
end
2 Likes

Thank you so much for all your effort - it works perfectly now :slight_smile: