Waste Collection Belgium [3.3.0;3.4.9)

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

I’m running openHAB 4.0.0.M1 with the ‘JavaScript Scripting (Nashorn)’ installed.
But getting the error, not sure if I need something else?

Just had a quick look, and I can’t find graalVM.

You shouldn’t need anything else. Did you try with the adjusted version I loaded 1h ago? I made a slight change that could have an impact.

I need to copy/paste from 2 installation since I can’t find the rule template in OH4. But if I did it correct, I’m getting now following error:

Script execution of rule with UID '07f5211181' failed: java.lang.NullPointerException: Cannot invoke "java.time.temporal.TemporalUnit.addTo(java.time.temporal.Temporal, long)" because "unit" is null

I just tried with an OH4 snapshot and Nashorn js installed. It runs fine.
Check out line 66 in the script. That’s where I have made the change. It should be:

timer = ScriptExecution.createTimerWithArgument(now.plus(delayInSeconds, ChronoUnit.SECONDS), func, function() {

That’s correct, I’ve got the latest version. But still having:

2023-04-26 19:38:46.775 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '07f5211181' failed: java.lang.NullPointerException: Cannot invoke "java.time.temporal.TemporalUnit.addTo(java.time.temporal.Temporal, long)" because "unit" is null

Will have some other tests tomorrow.

Guess something is wrong in my system, but not sure where. Everything else seems to be working fine. Can I add extra debugs to the logs?

Just did an upgrade towards 4.0.0.M2, but no luck :cry:

When I check the installed bundles, I see I have 2 JavaScript Scripting? Not sure why. But no difference with 1 installed, the other or both. Always the same error.

openhab> bundle:list | grep ava
 37 │ Active   │  80 │ 30.1.0.jre             │ Guava: Google Core Libraries for Java
 38 │ Active   │  80 │ 1.0.1                  │ Guava InternalFutureFailureAccess and InternalFutures
 54 │ Active   │  80 │ 1.2                    │ javax.annotation API
 88 │ Active   │  80 │ 1.0.0.2                │ Apache ServiceMix :: Bundles :: javax.inject
234 │ Active   │  80 │ 2.1.0                  │ Units of Measurement Common Library for Java
240 │ Active   │  80 │ 1.6.2                  │ JavaMail API
253 │ Active   │  80 │ 2.2.19                 │ rxjava
256 │ Active   │  80 │ 20180813.0.0           │ JSON in Java
257 │ Active   │  80 │ 0.3.0.v20220506-1020   │ EdDSA-Java
258 │ Active   │  80 │ 5.2.1.OH1              │ nrjavaserial
266 │ Active   │  80 │ 2.1.2                  │ Java Concurrency Tools Core Library
268 │ Active   │  80 │ 4.0.0.M2               │ openHAB Add-ons :: Bundles :: Automation :: JavaScript Scripting (Nashorn)
323 │ Active   │  80 │ 4.0.0.M2               │ openHAB Add-ons :: Bundles :: Automation :: JavaScript Scripting

You installes both the old javascript addon (nashorn) and the new one (using graalvm). It is likely the code is run using the newer one. I did not test that, so that’s likely the problem. I will look into it when I move to OH4.

@brononius A version for OH 4.0 for the JavaScript Scripting Add-on (ECMAScript 2022+ ES6) is now available here.

1 Like

Ahhh, nice !!!
Works perfectly.

2023-06-02 18:17:14.224 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'garbage_collection_waste' updated to 2023-06-02T00:00:00.000+0200
2023-06-02 18:17:14.224 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'garbage_collection_waste' changed from NULL to 2023-06-02T00:00:00.000+0200
2023-06-02 18:17:14.224 [INFO ] [openhab.event.GroupStateUpdatedEvent] - Group 'garbage_collection' updated to 2023-06-02T00:00:00.000+0200 through garbage_collection_waste
2023-06-02 18:17:14.224 [INFO ] [hab.event.GroupItemStateChangedEvent] - Item 'garbage_collection' changed from NULL to 2023-06-02T00:00:00.000+0200 through garbage_collection_waste
2023-06-02 18:17:14.228 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'garbage_collection_pmd' updated to 2023-06-02T00:00:00.000+0200
2023-06-02 18:17:14.228 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'garbage_collection_pmd' changed from NULL to 2023-06-02T00:00:00.000+0200
2023-06-02 18:17:14.228 [INFO ] [openhab.event.GroupStateUpdatedEvent] - Group 'garbage_collection' updated to 2023-06-02T00:00:00.000+0200 through garbage_collection_pmd
2023-06-02 18:17:14.233 [INFO ] [openhab.event.ItemStateUpdatedEvent ] - Item 'garbage_collection_paper' updated to 2023-06-02T00:00:00.000+0200
2023-06-02 18:17:14.234 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'garbage_collection_paper' changed from NULL to 2023-06-02T00:00:00.000+0200
2023-06-02 18:17:14.234 [INFO ] [openhab.event.GroupStateUpdatedEvent] - Group 'garbage_collection' updated to 2023-06-02T00:00:00.000+0200 through garbage_collection_paper

Thanks!

Please find some updates for the Flemish region in Belgium:
var WASTE_ITEMS = {
RESIDUAL_WASTE: { “item”: “Waste_residual”, “fraction”: [“residu”, “huisvuil”, “omb”, “restafval”, “huisvuil diftar”] },
PMD: { “item”: “Waste_pmd”, “fraction”: [“pmd”] },
GFT: { “item”: “Waste_gft”, “fraction”: [“gft”, “vegetable”, “kitchen”, “organiques”, “gft-diftar”] },
PAPER_CARDBOARD: { “item”: “Waste_paper”, “fraction”: [“paper”, “paper-cardboard”] },
TEXTILE: { “item”: “”, “fraction”: [“textile”] },
PRUNING_WOOD: { “item”: “Waste_wood”, “fraction”: [“pruning”, “verhakselen”, “snoeihout”] },
GLASS: { “item”: “”, “fraction”: [“glass”] },
BULKY_WASTE: { “item”: “Waste_bulk”, “fraction”: [“bulky”, “grofvuil”] }
};

@lvdh
“huisvuil diftar” and “gft-diftar” should already work (“huisvuil” and “gft” are in the search strings and it looks for substrings.
Do you have an example output where “snoeihout” and/or “grofvuil” are used? I can then add them.