Converting Prometheus to Openhab

Hi,

I have this output from an AirGradient sensor:

$ curl http://airgradient-ip-address:9926/metrics
# HELP pm02 Particulate Matter PM2.5 value
# TYPE pm02 gauge
pm02{id="Airgradient"}6
# HELP rco2 CO2 value, in ppm
# TYPE rco2 gauge
rco2{id="Airgradient"}862
# HELP atmp Temperature, in degrees Celsius
# TYPE atmp gauge
atmp{id="Airgradient"}31.6
# HELP rhum Relative humidity, in percent
# TYPE rhum gauge
rhum{id="Airgradient"}38

I have this thing:

Thing http:url:airgradient1 "Airgradient 1" [
	baseURL="http://10.0.15.87:9926/metrics",
	refresh=30] {
		Channels:
			Type string : hum "Humidity" [ stateTransformation="REGEX:.*rhum.*}([0-9]*)" ]
            Type string : temp "Temperature" [ stateTransformation="REGEX:.*atmp.*}([0-9.]*).*"]
            Type string : co2 "CO2" [ stateTransformation="REGEX:.*rco2.*}([0-9.]*).*"]
            Type string : pm02 "PM02" [ stateTransformation="REGEX:.*pm02.*}([0-9.]*).*"]
}

All the regex match in the regex tester:

Sadly OH3 does not seem to agree:

2021-12-18 22:59:55.408 [WARN ] [.transform.SingleValueTransformation] - Transformation service REGEX for pattern .*pm02.*}([0-9.]*).* not found!
2021-12-18 22:59:55.409 [WARN ] [.transform.SingleValueTransformation] - Transformation service REGEX for pattern .*atmp.*}([0-9.]*).* not found!
2021-12-18 22:59:55.409 [WARN ] [.transform.SingleValueTransformation] - Transformation service REGEX for pattern .*rhum.*}([0-9]*) not found!
2021-12-18 22:59:55.409 [WARN ] [.transform.SingleValueTransformation] - Transformation service REGEX for pattern .*rco2.*}([0-9.]*).* not found!

Any ideas?

Daniel

wouldn’t that be the first match for “pm02”?

even if so (it isn’t in the regex tester). the “}” limits it to the right number.
Doesn’t it?

I reprogrammed the Airgradient to output JSON.
JSONPATH works. REGEX seems broken

Looks like the optional add-on is not installed.

Doesn’t appear to.
I find experimenting with transforms in rules is convenient.

val rawtext = '# HELP pm02 Particulate Matter PM2.5 value
# TYPE pm02 gauge
pm02{id="Airgradient"}6
# HELP rco2 CO2 value, in ppm
# TYPE rco2 gauge
rco2{id="Airgradient"}862
# HELP atmp Temperature, in degrees Celsius
# TYPE atmp gauge
atmp{id="Airgradient"}31.6
# HELP rhum Relative humidity, in percent
# TYPE rhum gauge
rhum{id="Airgradient"}38'
var results = transform("REGEX", ".*pm02.*}([0-9.]*).*", rawtext)
logInfo("test", "extracts " + results)

yields

2021-12-19 15:09:50.382 [INFO ] [.eclipse.smarthome.model.script.test] - extracts 38

I don’t think that’s quite what you wanted? I don’t know regex well enough to correct.

Hi Rossko,

This was it. Thanks for the hint!

Daniel

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.