Help with receiving data from influxdb

I try to get Test item state from influxdb.
This script works ok, but maybe easier way exists?

curl -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d `curl -GET 'http://openhab:openhab@localhost:8086/query?db=openhab_db' --data-urlencode 'q=select last(ppm) from co2 where time > now() - 2h'` "http://localhost:8080/rest/items/Test/state"



It works from console, but not work from rules.
I try it with sudo -u openhab - its ok.

First question is: What’s the purpose to manually request influxdb?

If openHAB writes the data, you could use
MyItem.historicState(time).state or MyItem.avarageSince(time)

where time is something like now.minusHours(2) or another joda string.

This would be used from within openHAB rules, e.g. to set other items.

I have a co2 sensor and its software post data directly to influxdb.
And i need to get latest value ppm from co2 table.