Trigger a Thing http url by a rule

  • Platform information:
    • OS: Ubuntu Server 22.04.4
    • openHAB version: 4.2.1

Hi community

I am failing to send an https request. I want to start a machine with the following call:

In browser:

http://192.168.0.132/hh?command=setSmartStart&value=%7B%22starttime%22%3A%200%7D

It works fine in the browser. The call sets the start delay to 0 and the machine starts.
(Side note: The time offset for starting the machine in seconds is {“starttime”: 0} converted it is %7B%22starttime%22%3A%200%7D)

Things file:

Thing http:url:TestMachine "TestMachine" [
    baseURL="http://192.168.0.132/",
    refresh=15] {
        Channels:
            Type string : inactiveStatus "Inactive Status" [ 
                stateExtension="ai?command=getDeviceStatus", 
                stateTransformation="JSONPATH:$.Inactive" ]
            Type switch : startMachine "Start Machine" [ 
                commandExtension="hh?command=%2$s",
                onValue="setSmartStart&value=%7B%22starttime%22%3A%200%7D",
                offValue="setSmartStart&value=%7B%22starttime%22%3A%209999%7D",
                mode="WRITEONLY"]
}

Items file:

Switch dishwasher_startMachine "Dishwasher Smart Start" { channel="http:url:TestMachine:startMachine" }
String dishwasherInactiveStatus "Dishwasher Inactive Ready" { channel="http:url:TestMachine:inactiveStatus" }

Rules file:

.....
    dishwasher_startMachine.sendCommand(ON)
    logInfo(logName, "Dishwasher ON")
....
end

Querying the ‘inactiveStatus’ works perfectly. But the machine is never started by the sendCommand.

It would be great if someone had an idea.

Many thanks,
Michael

oh the solution was not far away:

    ......
    Type switch : startMachine "Start Machine" [ 
        commandExtension="hh?command=%2$s",
        onValue="setSmartStart&value={\"starttime\": 0}",
        offValue="setSmartStart&value={\"starttime\": 900}",
        mode="WRITEONLY"]
    ......

But I still have one question, which type should be selected so that the time can be transferred in the ‘sendCommand’ (like dishwasher_startMachine.sendCommand(0) )?

items file

XXXXXX dishwasher_startMachine "Dishwasher Smart Start" { channel="http:url:TestMachine:startMachine" }

things file

    ......
    Type ?????? : startMachine "Start Machine" [ 
        commandExtension="hh?command=????????",
        mode="WRITEONLY"]
    ......

Many thanks,
Michael

You’d need to use a Number item, so you can command it with a number.

Then, according to HTTP - Bindings | openHAB
You’d use %2$ (click the link to read more)

To be more specific:

Thing http:url:TestMachine "TestMachine" [
    baseURL="http://192.168.0.132/",
    refresh=15] {
        Channels:
            Type string : inactiveStatus "Inactive Status" [ 
                stateExtension="ai?command=getDeviceStatus", 
                stateTransformation="JSONPATH:$.Inactive" ]
            Type number : startMachine "Start Machine" [ 
                commandExtension="hh?command=setSmartStart&value={\"starttime\": %2$s}",
                mode="WRITEONLY"]
}

But I did not test :slight_smile:

Thank you @JimT and @Udo_Hartmann . Works perfectly.