Trying to get the air quality of my city from a webpage using the http binding and REGEX transformation.
I managed to have a REGEX transform which is working on the REGEX tester pages and seems compatible with openhab (no \ or " in the transform or result).
My first REGEX was data-index="(.*)">Aujourd but this resulted in problems with displayed items so I had to remove the " and >.
But it doesn’t seem to access the webpage, there is no displayed number on the sitemap. Also tried to replace the (.*) by (\d*.\d) without success.
Could it be because the page is secured https?
Any tips welcome
logging only shows that the item changed from NULL to null… No error appears.
I am not having more luck with the different writing of the REGEX. And using square brackets instead of brackets leads to “Error REGEX does not follow the expected pattern”
16:45:43.491 [INFO ] [smarthome.event.ItemStateChangedEvent] - Air_quality_today changed from NULL to null
I did use regex101: build, test, and debug regex to check the REGEX code, and it seems to pick up correctly the numbers I am looking for… Not sure where to look.
rule "test"
when
Item Test_Switch changed to ON
then
var String myString = sendHttpGetRequest("https://www.atmo-auvergnerhonealpes.fr/monair/commune/38185", 5000)
myString = transform("REGEX", myString, "data-index=\"(.*)\">Aujourd")
logInfo("TEST", myString)
end
One thing to note about how REGEX works in OH is that it must match the full webpage. Try adding .* at the start and end of the expression. Something like .*data-index=\"(.*)\"\>Aujourd.*. You might have to double escape. .*data-index=\\"(.*)\\"\\>Aujourd.*.