Waste Collection Belgium [4.0.0.0;4.9.9.9]

recycelapp

A rule created by this rule template will query the recycleapp.be website once per day for the waste collection calendar on a specific address in Belgium. It will then update a number of items by fraction for the next collection date of that specific fraction.

The rule template combines well with the Garbage Collection UI widget by @DrRSatzteil.

Language: javascript

Dependencies

  • JavaScript Scripting Add-on installed.

Configuration

The rule has a number of parameters:

  • Time: time of day to trigger the rule, defaults to midnight
  • Street: street name for collection
  • Street number: street number for collection
  • Zip code: zip code for collection
  • Days: number of days to look ahead, optional parameter, default 60

The rule will update one or more DateTime items with the next collection date for the specific fraction. These items are optional. You only need to create items for, and configure the ones, you are interested in.

  • Residual Waste Item
  • PMD Item
  • GFT Item
  • Paper and Cardboard Item
  • Textile Item
  • Pruning Wood Item
  • Glass Item
  • Bulky Waste Item

Note that the above 8 fractions are the ones configured in the rule. The collection of fractions may vary by region. E.g. pruning wood would return the deadline for a pruning woord collection appointment in some places. Not all fractions are collected in all regions.
Also, the strings used in the API response to describe certain (the same) fractions vary by region. Therefore, if one of your fractions is not recognized, it may require adding alternative detection strings to the rule. If you notice this, let me know and the template rule will be completed.
If you have other fractions, you can manually add them to the created rule. If you communicate back, the template will be adjusted.

The rule template will by default log success and failure. The logging level can be increased to DEBUG or TRACE for more detailed information. Use following command in the openHAB console for DEBUG level:
log:set DEBUG org.openhab.automation.openhab-js.wastebelgium

Suggestions

For a nice representation of the next waste collection, combine this rule template with the Garbage Collection UI widget by @DrRSatzteil.

If you use sitemaps, you can easily render a line in the UI when the collection is in the next days. Here is an example of such a configuration:

		Text item=ResidualWaste label="Residual waste [%1$tA]" icon="error" visibility=[ResidualWaste > -172800]
		Text item=PMD label="PMD [%1$tA]" icon="error" visibility=[PMD > -172800]
		Text item=Paper label="Paper and cardboard [%1$tA]" icon="error" visibility=[Paper > -172800]

A line will only render for a collection within the next 48 hours.

Changelog

This rule template is heavily inspired by the work of @BeanzBE, who developed a binding for the same purpose, not currently part of the openHAB distribution. Many thanks for that. Rather than using the binding as a dependency, I opted to do the required http GET calls directly from the rule.

Version 2.4

  • Adjust to breaking change in JavaScript Scripting Add-on
  • Change URL to current URL used on website

Version 2.3

  • Update secret key

Version 2.2

  • Added “kerstboom” matching

Version 2.1

  • Added “snoeihout” and “grofvuil” matching

Version 2.0

  • Adapted older version of rule template (developed for ECMAScript 5.1) to ECMAScript 2022+ (ES6), for use with JavaScript Scripting Add-on and OH4.0.

Version 1.x

  • Version developed for ECMAScript 5.1 (Nashorn), available here.

Resources

See the original forum discussion with reference to the work of @BeanzBE.

https://raw.githubusercontent.com/mherwege/openhab-rule-templates/main/wasteBelgium/wasteBelgium-ES6.yaml

2 Likes

Hello,

thanks for the nice script. Is there a way you could add to the script the “Next date of Waste Collection” and the “next type of Waste Collection”? We can use this then easily in Items and Rules 


Many thanks!

Joris De Waele

I’m not really sure what to do with the .yaml file found under “Resources”. If I put it in my conf\rules folder, the rule doesn’t show up under rules in the MainUI.

It’s not a widget either, because the semicolon in the uid isn’t allowed for widgets


Thanks in advance for your guidance! :slight_smile:

In your OH installation, go to the add-on store, under automations. You will find it is one of the rule templates there. Once installed, you an create a new rule drom the rules menu, using this template. When creating the rule, it will ask for the necessary parameters. That’s it.

I see! Thanks :slight_smile:

I noticed today (too late unfortunately), that “Kerstboom” is also an entry in Pulle (2243, deelgemeente van Zandhoven). Is that something that is extractable from the API as well?

I’ve tried looking around for this API, but this is out of my league


It should be, but is currently not matched. Rather than create a separate category for it, is it OK to make it show up as a ‘snoeihout’ entry?

I don’t think you need anything extra to do that. Here is an example of a Blockly rule I use:

Notice I defined a group Afval, type DateTime with aggregation function Earliest. That will give you the next date for collection.

I suppose that’s a solution. :slight_smile:

Did the api key changes again ? i am getting strange errors after the rules fired

[ERROR] [enhab.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

Yes, it has.

The templates have been updates. You can update the X_SECRET in an existing rule, replacing it with:

var X_SECRET = "Op2tDi2pBmh1wzeC5TaN2U3knZan7ATcfOQgxh4vqC0mDKmnPP2qzoQusmInpglfIkxx8SZrasBqi5zgMSvyHggK9j6xCQNQ8xwPFY2o03GCcQfcXVOyKsvGWLze7iwcfcgk2Ujpl0dmrt3hSJMCDqzAlvTrsvAEiaSzC9hKRwhijQAFHuFIhJssnHtDSB76vnFQeTCCvwVB27DjSVpDmq8fWQKEmjEncdLqIsRnfxLcOjGIVwX5V0LBntVbeiBvcjyKF2nQ08rIxqHHGXNJ6SbnAmTgsPTg7k6Ejqa7dVfTmGtEPdftezDbuEc8DdK66KDecqnxwOOPSJIN0zaJ6k2Ye2tgMSxxf16gxAmaOUqHS0i7dtG5PgPSINti3qlDdw6DTKEPni7X0rxM";
2 Likes

I assume it’s not possible to have the X_SECRET retrieved automatically?

But where do you get it from? I tried what was suggested here (Waste collections Belgium - #31 by BeanzBE), but without any success. The file/page with the name access-token doesn’t appear in the list, nor does main.js.

That’s how I got it. You need to look at the network traffic in development tools when you open the website. I don’t see an easy way to automate retrieving it.
I am using the rule, and I believe the X-SECRET in the template is still correct. At least I got the collection dates updated this week.

Secret changed:

Op2tDi2pBmh1wzeC5TaN2U3knZan7ATcfOQgxh4vqC0mDKmnPP2qzoQusmInpglfIkxx8SZrasBqi5zgMSvyHggK9j6xCQNQ8xwPFY2o03GCcQfcXVOyKsvGWLze7iwcfcgk2Ujpl0dmrt3hSJMCDqzAlvTrsvAEiaSzC9hKRwhijQAFHuFIhJssnHtDSB76vnFQeTCCvwVB27DjSVpDmq8fWQKEmjEncdLqIsRnfxLcOjGIVwX5V0LBntVbeiBvcjyKF2nQ08rIxqHHGXNJ6SbnAmTgsPTg7k6Ejqa7dVfTmGtEPdftezDbuEc8DdK66KDecqnxwOOPSJIN0zaJ6k2Ye2tgMSxxf16gxAmaOUqHS0i7dtG5PgPSINti3qlDdw6DTKEPni7X0rxM

@Pollegazon That is the secret that is in the current code and has been there for I think more than a year. That still worked for me this week without any change. Did you still have an older version of the code?

I was wrong about when I updated it. It has been on January 26th, see the earlier post in this thread: Waste Collection Belgium [4.0.0.0;4.9.9.9] - #10 by Mherwege

Please remove your last posted code as that will not work anymore and may confuse people.

Sh*t - sorry for the confusion. I see now that the new code was already shared earlier in the thread. I was still using the old one which produced a 401. Conclusion 
 there is no new code, yet.

The script stopped posting the new dates to the configured items on my installation. It appears that

if (item && item.type === "DateTimeItem")

prevents the code to reach the postUpdate command since i updated to the latest OpenHab4 release.

Removing the item.type === “DateTimeItem” check solves the problem.

The template had already been corrected for this javascript change. Look at the first post for version 2.4.