Garbage display

Last Updated or created 2023-09-20

I wanted to know when trash is being collected. So i made a dual led thingy.

Version without lid .. just to test

When we lived in Utrecht, the website which mentions when, what is collected was easy .. like a API

We live in Hilversum now, so i had to write a scraper.

UPDATE : Script not working anymore. Site has been changed, and I’m not willing to run a headless browser (phantomjs) to scrape the info

See below my new solution

Script to set leds

#!/bin/bash
set -x

if [[ $# -eq 0 ]] ; then
curl  http://10.1.0.46/control?cmd=NeoPixel,1,0,0,0
curl  http://10.1.0.46/control?cmd=NeoPixel,2,0,0,0
exit 0
fi


set -x
if [ $1 = "GFT" ] ;then led1="150,0,0" ;fi
if [ $1 = "Rest" ] ;then led1="150,150,150" ;fi
if [ $1 = "Paper" ] ;then led1="0,0,150" ;fi
if [ $1 = "Plastic" ] ;then led1="75,191,0" ;fi
if [ $1 = "Textiel" ] ;then led1="191,191,191" ;fi
if [ $1 = "Kerstbomen" ] ;then led1="191,0,0" ;fi

if [ "w$2" = "wgft" ] ;then led2="255,0,0" ;fi
if [ "w$2" = "wRest" ] ;then led2="150,150,150" ;fi
if [ "w$2" = "wpapier" ] ;then led2="0,0,255" ;fi
if [ "w$2" = "wplastic" ] ;then led2="100,255,0" ;fi
if [ "w$2" = "wTextiel" ] ;then led2="191,191,191" ;fi
if [ "w$2" = "wKerstbomen" ] ;then led2="191,0,0" ;fi

if [[ $# -eq 1 ]] ; then
led2=$led1
fi
curl  http://10.1.0.46/control?cmd=NeoPixel,1,$led1
curl  http://10.1.0.46/control?cmd=NeoPixel,2,$led2

Scraper ( calls setleds and mqtt )

#!/bin/bash
cd /home/pi/
./afvalleds
curl -s https://inzamelkalender.gad.nl/adres/1222HP:39 > /tmp/afvalcurl
today=$(date +%F)
tomorrow=$(date --date="next day" +%F)
for f in petfles-blik-drankpak-pmd.svg appel-gft.svg kliko-grijs-rest.svg doos-karton-papier.svg shirt-textiel.svg kerstboom.svg ; do
p1=$(cat /tmp/afvalcurl | grep -i  -A2 "$f" | grep class | cut -f2 -d\> | cut -f1 -d\< | cut -f2- -d" ")
p2=$(echo $p1 | sed s/mei/may/g | sed s/okt/oct/g )
p3=$(date --date="$p2" +%F)
dater=$p3
now=$(date -d $(date --date="1 days ago" +%F) +%s)
p3epoch=$(date --date="$p3" +%s)
diff=$(expr $p3epoch - $now)
if [ $diff -lt 0 ] ; then
                dater=$(date -d "$p3 1 year" +%F)
fi
whatdate=$(echo $f | sed s/petfles-blik-drankpak-pmd.svg/Plastic/g |sed s/appel-gft.svg/GFT/g | sed s/kliko-grijs-rest.svg/Rest/g | sed s/doos-karton-papier.svg/Paper/g | sed s/shirt-textiel.svg/Textiel/g | sed s/kerstboom.svg/Kerstbomen/g)
mosquitto_pub -h 127.0.0.1 -p 1883 -t "afvalwijzer/$whatdate" -m "$dater"
if [ "w$today" == "w$dater" ]; then
alltoday="$alltoday $whatdate"
fi
if [ "w$tomorrow" == "w$dater" ]; then
alltomorrow="$alltomorrow $whatdate"
fi
done
mosquitto_pub -h 127.0.0.1 -p 1883 -t "afvalwijzer/Today" -m "$alltoday"
mosquitto_pub -h 127.0.0.1 -p 1883 -t "afvalwijzer/Tomorrow" -m "$alltomorrow"
./afvalleds $alltomorrow

Utrecht scraper

#!/bin/bash
set -x
curl -s "http://json.mijnafvalwijzer.nl/?method=postcodecheck&postcode=3543eh&huisnummer=72&" > /tmp/afv
cat /tmp/afv | python -mjson.tool > /tmp/afv.json
today=$(cat /tmp/afv.json | grep -A1 $(date +%Y-%m-%d) | grep nameType | cut -f4 -d\" | paste -sd "/" -)
today=$(echo $today | sed s/\ /,/g)

tomorrow=$(cat /tmp/afv.json | grep -A1 $(date -d "+1 days" +%Y-%m-%d) | grep nameType | cut -f4 -d\" | paste -sd "/" -)
tomorrow=$(echo  $tomorrow" | sed s/\ /,/g)

cat /tmp/afv.json | grep -B1 nameType | grep -B1 gft | cut -f4 -d\" | grep 202 > /tmp/gft.afv
cat /tmp/afv.json | grep -B1 nameType | grep -B1 papier | cut -f4 -d\" | grep 202 > /tmp/papier.afv
cat /tmp/afv.json | grep -B1 nameType | grep -B1 plastic | cut -f4 -d\" | grep 202 > /tmp/plastic.afv
cat /tmp/afv.json | grep -B1 nameType | grep -B1 kerst | cut -f4 -d\" | grep 202 > /tmp/kerst.afv
(
(
for f in $(seq 1 31) ; do
 dater=$(date -d "+$f days" +%Y-%m-%d)
 grep $dater /tmp/gft.afv > /dev/null &&  echo "$dater GFT" | head -1
done ) | head -1

(
for f in $(seq 1 31) ; do
 dater=$(date -d "+$f days" +%Y-%m-%d)
 grep $dater /tmp/papier.afv > /dev/null && echo "$dater Papier"  | head -1
done ) | head -1

(
for f in $(seq 1 31) ; do
 dater=$(date -d "+$f days" +%Y-%m-%d)
 grep $dater /tmp/plastic.afv > /dev/null && echo "$dater Plastic"  | head -1
done ) | head -1

(
for f in $(seq 1 31) ; do
 dater=$(date -d "+$f days" +%Y-%m-%d)
 grep $dater /tmp/kerst.afv > /dev/null && echo "$dater Kerstboom"  | head -1
done ) | head -1

) | sort -n -k1 | sed s/\ /,/g > /tmp/afv.sorted
gft=$(cat /tmp/afv.sorted | grep GFT | cut -f1 -d,)
papier=$(cat /tmp/afv.sorted | grep Papier | cut -f1 -d,)
plastic=$(cat /tmp/afv.sorted | grep Plastic | cut -f1 -d,)

mosquitto_pub -h 127.0.0.1 -p 1883 -t "afvalwijzer/Today" -m "$today " 
mosquitto_pub -h 127.0.0.1 -p 1883 -t "afvalwijzer/Tomorrow" -m "$tomorrow " 
mosquitto_pub -h 127.0.0.1 -p 1883 -t "afvalwijzer/Papier" -m "$papier" 
mosquitto_pub -h 127.0.0.1 -p 1883 -t "afvalwijzer/GFT" -m "$gft" 
mosquitto_pub -h 127.0.0.1 -p 1883 -t "afvalwijzer/Plastic" -m "$plastic" 

Update new solution

My home assistant has a hacs addon installed which does the heavy lifting for me.
Why not use this info?

I wrote about NR and HA here

So getting the info for NR to parse:

I only need to use the lightblue node bottom right!

It is the current state node, inject a timestamp every day to get new values.
Parse this and send using Mqtt to my Led display thingy

Spread the love