Waste Collection Belgium [3.3.0;3.4.9)

Thanks for this nice rule.
Unfortunattely I get an error due to our street name consists of 2 words with a space in between. This results in following error (I replaced my street name by “NAME NAME” and postal code by “9999”). When I use a streetname in 1 word, the error doe not appear.
Any hints to solve this ?

java.lang.IllegalArgumentException: Illegal character in query at index 46: https://recycleapp.be/api/app/v1/streets?q=NAME NAME&zipcodes=9999-13012
	at java.net.URI.create(URI.java:883) ~[?:?]
	at org.eclipse.jetty.client.HttpClient.newRequest(HttpClient.java:453) ~[bundleFile:9.4.43.v20210629]
	at org.openhab.core.io.net.http.HttpUtil.executeUrlAndGetReponse(HttpUtil.java:212) ~[?:?]
	at org.openhab.core.io.net.http.HttpUtil.executeUrl(HttpUtil.java:155) ~[?:?]
	at org.openhab.core.io.net.http.HttpUtil.executeUrl(HttpUtil.java:130) ~[?:?]
	at org.openhab.core.model.script.actions.HTTP.sendHttpGetRequest(HTTP.java:79) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$409$6047$\^eval\_.getStreetId(<eval>:134) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$399$8158A$\^eval\_.updateWasteCalendar(<eval>:182) ~[?:?]
	at jdk.nashorn.internal.scripts.Script$Recompilation$398$3841A$\^eval\_.updateWithRetry#timer(<eval>:66) ~[?:?]
	at jdk.nashorn.javaadapters.org_eclipse_xtext_xbase_lib_Procedures$Procedure1.apply(Unknown Source) ~[?:?]
	at org.openhab.core.model.script.actions.ScriptExecution.lambda$1(ScriptExecution.java:100) ~[?:?]
	at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$12(SchedulerImpl.java:184) ~[?:?]
	at org.openhab.core.internal.scheduler.SchedulerImpl.lambda$1(SchedulerImpl.java:87) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]
Caused by: java.net.URISyntaxException: Illegal character in query at index 46: https://recycleapp.be/api/app/v1/streets?q=NAME NAME&zipcodes=9999-13012
	at java.net.URI$Parser.fail(URI.java:2913) ~[?:?]
	at java.net.URI$Parser.checkChars(URI.java:3084) ~[?:?]
	at java.net.URI$Parser.parseHierarchical(URI.java:3172) ~[?:?]
	at java.net.URI$Parser.parse(URI.java:3114) ~[?:?]
	at java.net.URI.<init>(URI.java:600) ~[?:?]
	at java.net.URI.create(URI.java:881) ~[?:?]
	... 18 more

Besides this error, I also get an error related to the scheduler :

2022-06-02 21:15:20.430 [WARN ] [ore.internal.scheduler.SchedulerImpl] - Scheduled job failed and stopped

Do I need to install any specific additional addon ?

@Beec Can you try putting %20 instead of space in the street name?

Mark, thanks for the prompt response. Error solved :+1:
I’ll now try to get the dates on the sceen.

@Beec I just changed the template. If you download it again, it will work with spaces.

1 Like

Mark, it seems the mapping in my area (Herenthout - IOK) is also not complete.
Any idea how to get this ?


image

@Beec If you switch on TRACE logging for the rule, you will get all details, with the strings to match. The lines from the screenshot need to becextended with the appropriate match strings. You can also send me your address by private message, and I will check it out and extend the rule.

@Beec Download and configure the template again. I think it should work now. Note I couldn’t find a textile fraction in the API response for Herenthout (but I did see a glass fraction, which I added).

@Mherwege It works perfectly now. Big thank you for the prompt support and update.

I’m trying to use this rule but stumble upon two errors. The first one is easily fixed, the second, I can’t find a solution.

13:47:23.953 [ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with UID '0d8aea4804' failed: <eval>:27:90 Missing close quote
  GLASS:           { "item": ",           "fraction": [ "glass"                       ] },
                                                                                          ^ in <eval> at line number 27 at column number 90
13:47:31.762 [TRACE] [ab.model.script.mherwege.wasteBelgium] - Attempt 3 of 10
13:47:31.766 [TRACE] [ab.model.script.mherwege.wasteBelgium] - URL: https://recycleapp.be/api/app/v1/access-token
13:47:31.805 [ERROR] [penhab.core.model.script.actions.HTTP] - Fatal transport error: java.util.concurrent.ExecutionException: org.eclipse.jetty.client.HttpResponseException: HTTP protocol violation: Authentication challenge without WWW-Authenticate header
13:47:31.806 [DEBUG] [ab.model.script.mherwege.wasteBelgium] - JSON Token: null
13:47:31.807 [DEBUG] [ab.model.script.mherwege.wasteBelgium] - Request failed, attempt 3 of 10
13:47:31.809 [DEBUG] [ab.model.script.mherwege.wasteBelgium] - Next attempt in 120s

I fixed the first issue in the template.

What version of OH are you using? I have not seen the second issue yet.

I’m using 3.3.0.

Had the same problem.
The secret token has changed.

Go to the code tab of the rule and find and replace the line with “var X_SECRET=” to:

var X_SECRET = "8eTFgy3AQH0mzAcj3xMwaKnNyNnijEFIEegjgNpBHifqtQ4IEyWqmJGFz3ggKQ7B4vwUYS8xz8KwACZihCmboGb6brtVB3rpne2Ww5uUM2n3i4SKNUg6Vp7lhAS8INDUNH8Ll7WPhWRsQOXBCjVz5H8fr0q6fqZCosXdndbNeiNy73FqJBn794qKuUAPTFj8CuAbwI6Wom98g72Px1MPRYHwyrlHUbCijmDmA2zoWikn34LNTUZPd7kS0uuFkibkLxCc1PeOVYVHeh1xVxxwGBsMINWJEUiIBqZt9VybcHpUJTYzureqfund1aeJvmsUjwyOMhLSxj9MLQ07iTbvzQa6vbJdC0hTsqTlndccBRm9lkxzNpzJBPw8VpYSyS3AhaR2U1n4COZaJyFfUQ3LUBzdj5gV8QGVGCHMlvGJM0ThnRKENSWZLVZoHHeCBOkfgzp0xl0qnDtR8eJF0vLkFiKwjX7DImGoA8IjqOYygV3W9i9rIOfK";

here is some more info how to find the new secret if it should change:

Works for me. I hope it also does work for you.

@Mherwege maybe you can update the template with this new secret?

Thanks @Novanoid. Changed the token and it works flawlessly.
Will keep your solution in mind.

The template has been updated with the new access token.

When checking the new token, I also noticed they use a new/other URL.
Old one is still working but it might fail in the future.
current URL used by binding/script : https://recycleapp.be/api/app/v1
new URL used by the website : https://api.fostplus.be
One is a redirection to the other I think. Something to take into account. When having time, I need to update my binding as well.

@BeanzBE I modified the template to use the new url. The street address GET also needs to be replaced by a POST command.

Many thanks for this script.
For the Wallonia, could you add “omb” in the residual_waste list and “organiques” in the GFT.

Thanks again.

Done

Seems that we (East-Flandres?) need “restafval” in the residual_waste list to have it working. Bit weird that they have so many terms for it. Seems to be a garbage bin of garbages… :wink:



Any plans to make it available for OH4? Seems it spits out an error as we speak :cry:

2023-04-26 12:50:52.189 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '07f5211181' failed: org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (now) on java.time.ZonedDateTime failed due to: Unknown identifier: now

I added “restafval” in the template. I also live in East-Flanders, and there is no issue for me. I believe it depends on the “intercommunale”. As soon as there is a slight difference from the standard in the definition of the allowed content of the fraction, the “intercommunale” creates a new name for the fraction.

The template still works in OH4 if you install the Nashorn extension. It may work with OH4 javascript (without Nashorn, but with graalVM) after the fix I just applied, but I did not test. I am still running 3.4 in my main instance, so did not switch yet. I intend to do so closer to the OH4 release date when I make the switch myself.

1 Like