Dynamic fan speed controlled by CO2 Measurements

I am attempting to create a rule to dynamically adjust the fan speed when CO2 measurement reaches a certain value. I think my problem is that the measurement from my NetAtmo returns “xxx ppm” and not just a number. How can I strip out “ppm” from the returned string/value?

Thanks in advance

Item ‘MainIndoorStation_CO2’ changed from 666 ppm to 630 ppm
2021-11-07 11:40:58.721 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘AdditionalModuleGryogVilde_CO2’ changed from 571 ppm to 568 ppm

rule “Adjust Fan Speed”
when
Item AdditionalModuleMasterBedroom_CO2 changed
then

val Measurement = AdditionalModuleMasterBedroom_CO2.state as DecimalType
Thread::sleep(5000)
val threshold1 = 690
Thread::sleep(5000)

if (Measurement < threshold1) {
Ventilation.SendCommand(101)
}
else {
Ventilation.SendCommand(104)
}

end

You don’t need to do that, you can more meaningfully compare your reading with a threshold also in ppm

What are the sleeps supposed to achieve? Neither the captured reading nor the threshold can change in that time.

Thanks a lot. The following works with NetAtmo CO2 ppm measurements.

“val int Measurement = (AdditionalModuleMasterBedroom_CO2.state as QuantityType).intValue”