# Waste Collection Belgium \[4.0.0.0;5.9.9.9\]

**URL:** <https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015>\
**Category:** Rule Templates\
**Tags:** stable, published\
**Created:** [June 2, 2023, 3:05pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015 "2023-06-02T15:05:04Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mherwege](https://community.openhab.org/user_avatar/community.openhab.org/mherwege/32/19924_2.png) [@Mherwege](https://community.openhab.org/u/Mherwege)\
**Post date:** [June 2, 2023, 3:05pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/1 "2023-06-02T15:05:04Z")

</div>

![recycelapp](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/4/7/479be2d519f77af211716bf9893eb29596cabdda.svg)

A rule created by this rule template will query the [recycleapp.be](https://recycleapp.be/home) 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](https://community.openhab.org/t/garbage-collection/114871) 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. Not all fractions may be available in your location.

- Residual Waste Item
- PMD Item
- GFT Item
- Paper and Cardboard Item
- Textile Item
- Pruning Wood Item
- Glass Item
- Metal Item
- Wood 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](https://community.openhab.org/t/garbage-collection/114871) 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:

```php
		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.6

- Updated URL and removed token authentication as no longer required
- Made retry logic more robust

### Version 2.5

- Fix Days variable type
- Add metal and wood fractions

### 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](https://community.openhab.org/t/waste-collection-belgium-3-3-0-3-4-9/135739).

## Resources

See the original [forum discussion](https://community.openhab.org/t/waste-collections-belgium/105021) with reference to the work of @BeanzBE.

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

---

<div class="post-metadata">

**Author:** ![Fdewaele](https://community.openhab.org/user_avatar/community.openhab.org/fdewaele/32/105173_2.png) [@Fdewaele](https://community.openhab.org/u/Fdewaele)\
**Post date:** [June 8, 2023, 1:47pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/2 "2023-06-08T13:47:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ErikDB](https://community.openhab.org/letter_avatar_proxy/v4/letter/e/ac8455/32.png) [@ErikDB](https://community.openhab.org/u/ErikDB)\
**Post date:** [January 9, 2024, 6:53pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/3 "2024-01-09T18:53:20Z")

</div>

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! 🙂

---

<div class="post-metadata">

**Author:** ![Mherwege](https://community.openhab.org/user_avatar/community.openhab.org/mherwege/32/19924_2.png) [@Mherwege](https://community.openhab.org/u/Mherwege)\
**Post date:** [January 9, 2024, 7:20pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/4 "2024-01-09T19:20:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ErikDB](https://community.openhab.org/letter_avatar_proxy/v4/letter/e/ac8455/32.png) [@ErikDB](https://community.openhab.org/u/ErikDB)\
**Post date:** [January 9, 2024, 9:50pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/5 "2024-01-09T21:50:03Z")

</div>

I see! Thanks 🙂

> [@Mherwege](#):
>
> 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.

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…

---

<div class="post-metadata">

**Author:** ![Mherwege](https://community.openhab.org/user_avatar/community.openhab.org/mherwege/32/19924_2.png) [@Mherwege](https://community.openhab.org/u/Mherwege)\
**Post date:** [January 12, 2024, 7:57am UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/6 "2024-01-12T07:57:16Z")

</div>

> [@ErikDB](#):
>
> 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?

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?

---

<div class="post-metadata">

**Author:** ![Mherwege](https://community.openhab.org/user_avatar/community.openhab.org/mherwege/32/19924_2.png) [@Mherwege](https://community.openhab.org/u/Mherwege)\
**Post date:** [January 12, 2024, 8:11am UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/7 "2024-01-12T08:11:18Z")

</div>

> [@Fdewaele](#):
>
> 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 …

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

 ![image](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/9/6/96a15137e9fb780301a0d5fef1a108f73912d8b3.png)

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

---

<div class="post-metadata">

**Author:** ![ErikDB](https://community.openhab.org/letter_avatar_proxy/v4/letter/e/ac8455/32.png) [@ErikDB](https://community.openhab.org/u/ErikDB)\
**Post date:** [January 17, 2024, 7:05pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/8 "2024-01-17T19:05:10Z")

</div>

I suppose that’s a solution. 🙂

---

<div class="post-metadata">

**Author:** ![stamate\_viorel](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/41988e/32.png) [@stamate\_viorel](https://community.openhab.org/u/stamate_viorel)\
**Post date:** [January 26, 2024, 2:53pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/9 "2024-01-26T14:53:23Z")

</div>

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

```auto
[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

```

---

<div class="post-metadata">

**Author:** ![Mherwege](https://community.openhab.org/user_avatar/community.openhab.org/mherwege/32/19924_2.png) [@Mherwege](https://community.openhab.org/u/Mherwege)\
**Post date:** [January 26, 2024, 4:45pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/10 "2024-01-26T16:45:26Z")

</div>

Yes, it has.

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

```auto
var X_SECRET = "Op2tDi2pBmh1wzeC5TaN2U3knZan7ATcfOQgxh4vqC0mDKmnPP2qzoQusmInpglfIkxx8SZrasBqi5zgMSvyHggK9j6xCQNQ8xwPFY2o03GCcQfcXVOyKsvGWLze7iwcfcgk2Ujpl0dmrt3hSJMCDqzAlvTrsvAEiaSzC9hKRwhijQAFHuFIhJssnHtDSB76vnFQeTCCvwVB27DjSVpDmq8fWQKEmjEncdLqIsRnfxLcOjGIVwX5V0LBntVbeiBvcjyKF2nQ08rIxqHHGXNJ6SbnAmTgsPTg7k6Ejqa7dVfTmGtEPdftezDbuEc8DdK66KDecqnxwOOPSJIN0zaJ6k2Ye2tgMSxxf16gxAmaOUqHS0i7dtG5PgPSINti3qlDdw6DTKEPni7X0rxM";

```

---

<div class="post-metadata">

**Author:** ![ErikDB](https://community.openhab.org/letter_avatar_proxy/v4/letter/e/ac8455/32.png) [@ErikDB](https://community.openhab.org/u/ErikDB)\
**Post date:** [June 2, 2024, 5:36pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/11 "2024-06-02T17:36:46Z")

</div>

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](https://community.openhab.org/t/waste-collections-belgium/105021/31)), but without any success. The file/page with the name `access-token` doesn’t appear in the list, nor does `main.js`.

---

<div class="post-metadata">

**Author:** ![Mherwege](https://community.openhab.org/user_avatar/community.openhab.org/mherwege/32/19924_2.png) [@Mherwege](https://community.openhab.org/u/Mherwege)\
**Post date:** [June 2, 2024, 6:34pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/12 "2024-06-02T18:34:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Pollegazon](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/5f8ce5/32.png) [@Pollegazon](https://community.openhab.org/u/Pollegazon)\
**Post date:** [June 20, 2024, 6:48pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/13 "2024-06-20T18:48:07Z")

</div>

Secret changed:

```auto
Op2tDi2pBmh1wzeC5TaN2U3knZan7ATcfOQgxh4vqC0mDKmnPP2qzoQusmInpglfIkxx8SZrasBqi5zgMSvyHggK9j6xCQNQ8xwPFY2o03GCcQfcXVOyKsvGWLze7iwcfcgk2Ujpl0dmrt3hSJMCDqzAlvTrsvAEiaSzC9hKRwhijQAFHuFIhJssnHtDSB76vnFQeTCCvwVB27DjSVpDmq8fWQKEmjEncdLqIsRnfxLcOjGIVwX5V0LBntVbeiBvcjyKF2nQ08rIxqHHGXNJ6SbnAmTgsPTg7k6Ejqa7dVfTmGtEPdftezDbuEc8DdK66KDecqnxwOOPSJIN0zaJ6k2Ye2tgMSxxf16gxAmaOUqHS0i7dtG5PgPSINti3qlDdw6DTKEPni7X0rxM

```

---

<div class="post-metadata">

**Author:** ![Mherwege](https://community.openhab.org/user_avatar/community.openhab.org/mherwege/32/19924_2.png) [@Mherwege](https://community.openhab.org/u/Mherwege)\
**Post date:** [June 20, 2024, 7:36pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/14 "2024-06-20T19:36:51Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![Mherwege](https://community.openhab.org/user_avatar/community.openhab.org/mherwege/32/19924_2.png) [@Mherwege](https://community.openhab.org/u/Mherwege)\
**Post date:** [June 20, 2024, 7:43pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/16 "2024-06-20T19:43:56Z")

</div>

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](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-4-9-9-9/147015/10)

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

---

<div class="post-metadata">

**Author:** ![Pollegazon](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/5f8ce5/32.png) [@Pollegazon](https://community.openhab.org/u/Pollegazon)\
**Post date:** [June 20, 2024, 7:43pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/17 "2024-06-20T19:43:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![erhapp](https://community.openhab.org/user_avatar/community.openhab.org/erhapp/32/73919_2.png) [@erhapp](https://community.openhab.org/u/erhapp)\
**Post date:** [August 31, 2024, 7:43pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/18 "2024-08-31T19:43:18Z")

</div>

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

```yaml
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.

---

<div class="post-metadata">

**Author:** ![Mherwege](https://community.openhab.org/user_avatar/community.openhab.org/mherwege/32/19924_2.png) [@Mherwege](https://community.openhab.org/u/Mherwege)\
**Post date:** [September 2, 2024, 10:35am UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/19 "2024-09-02T10:35:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![koenraad](https://community.openhab.org/letter_avatar_proxy/v4/letter/k/6de8d8/32.png) [@koenraad](https://community.openhab.org/u/koenraad)\
**Post date:** [May 8, 2025, 7:40am UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/20 "2025-05-08T07:40:37Z")

</div>

Hi,  
I had a problem renewing info, so I tried to debug the code. It seems that for my location there is a modification and an addition. This is what I got when querying the API :

```auto
2025-05-07 21:07:16.047 [DEBUG] [b.automation.openhab-js.wastebelgium] - Collections: [
...
{"timestamp":"2025-05-16","fraction":"houtafval"},
...
{"timestamp":"2025-07-18","fraction":"gemengde metalen"}]
2025-05-07 21:07:16.070 [INFO] [b.automation.openhab-js.wastebelgium] - Successfully updated waste calendar

```

I added both in my version of the code.

---

<div class="post-metadata">

**Author:** ![koenraad](https://community.openhab.org/letter_avatar_proxy/v4/letter/k/6de8d8/32.png) [@koenraad](https://community.openhab.org/u/koenraad)\
**Post date:** [May 31, 2025, 12:08pm UTC](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015/21 "2025-05-31T12:08:04Z")

</div>

I though my problem was solved, but I do have it again. Further debugging I found this (after adding a log-info line just before the actual query) :

```auto
2025-05-31 09:40:27.100 [INFO] [b.automation.openhab-js.wastebelgium] - Retrieving waste calendar
2025-05-31 09:40:27.354 [INFO] [b.automation.openhab-js.wastebelgium] - URL: https://api.fostplus.be/recyclecms/app/v1/collections?...&fromDate=2025-05-31&untilDate=7511-07-11
2025-05-31 09:40:27.408 [INFO] [b.automation.openhab-js.wastebelgium] - Successfully updated waste calendar

```

untilDate is very strange. DAYS is defined as “60”.  
After changing DAYS to 60 (so without quotes) the untilDate is OK :

```auto
2025-05-31 14:06:41.167 [INFO] [b.automation.openhab-js.wastebelgium] - Retrieving waste calendar
2025-05-31 14:06:41.362 [INFO] [b.automation.openhab-js.wastebelgium] - URL: https://api.fostplus.be/recyclecms/app/v1/collections?...&fromDate=2025-05-31&untilDate=2025-07-30
2025-05-31 14:06:41.417 [INFO] [b.automation.openhab-js.wastebelgium] - Successfully updated waste calendar

```

[Next page](https://community.openhab.org/t/waste-collection-belgium-4-0-0-0-5-9-9-9/147015.md?page=2)
