[SOLVED] Items state with curl command

Hi everyone,
i would like to ask something about curl and how to implement it.
I just set up my new boiler controller that has also an internet module. After some research i found out tha i can receive data from it with some curl commands and also post to it changes that i want.
When i type the command below from linux shell

curl "http://xxx.xxx.xxx.xxx/user/cgi-bin/edition.cgi" -H "Author: Basic ****************************" --data "gt=501" -s

i get a response " 501_67" where 67 is the current water temp in the boiler.
How i can make that appear in my openhab as an item and refresh every 5 minutes?
Thank you in advance

You should check out https://www.openhab.org/addons/bindings/http1/#item-configuration

1 Like

Any help? for i haven’t yet managed to transform it to a format that can read my values in openhab,
although the curl command from shell works

did you get the http binding to work with a string item?
to transform the result (from 501_67 to 67) you need to use a transformation service (e.g. regex)

there are many examples in the forum

Thanks for the reply.
I managed to work it out with a script.

#!/bin/sh
CHTemp=`curl "http://192.168.1.32/user/cgi-bin/edition.cgi" -H "Authorization: Basic am9obnltMzA6cDQ1NXcwcmQ=\r\n" --data "gt=501" -s`
echo "CHTemp is: "$CHTemp
#
curl --header "Content-Type: text/plain" -H POST  "http://192.168.1.250:8080/rest/items/CHTemp"  --data "$CHTemp"
#

The thing now is that i am getting, as you mentioned above, all the info ( 501_67 ) and trying now to remove the first part.

1 Like

Are you getting that info in a String item?

Then do:

rule "Text to Temperature"
when
    Item stringItem changed
then
    temperatureItem.postUpdate(stringItem.state.toString.split("_").get(1))
end
1 Like

Thanks vzorglub!!! It seems to be working.
Another thing i missed to mention, is that in the data i receive, the format is 501_670 and not 501_67 so is there any way to discard the last zero? Thank you once more.

Is it always a 0?
then:

    temperatureItem.postUpdate(stringItem.state.toString.split("_").get(1).replace("0", ""))
1 Like

Perfect!!! Thank you once more!!!

No that won’t work if the temperature is 60 then it will return 6 only
So:

rule "Text to Temperature"
when
    Item stringItem changed
then
    var temperature = (Float::parseFloat(stringItem.state.toString.split("_").get(1)) as Number) / 10
    temperatureItem.postUpdate(temperature)
end
1 Like

Please tick the post that provided the solution.
Thanks