LEEDS UK Bin Dates

Flow to display next several weeks of bin collections in the Leeds (UK) area.

It makes use of a small script to download the dm_jobs.csv file and then uses grep to extract all the "jobs" that match your address. You will need to create the getDates.sh script and edit the "job number" 791420 in this case -

#!/bin/bash -ex

cd /home/pi/.node-red/my-data

rm -f dates.txt

rm -f dm_jobs.csv

wget http://opendata.leeds.gov.uk/downloads/bins/dm_jobs.csv

grep -E 791420 dm_jobs.csv > dates.txt

You can find your job number by downloading the Household premises.csv file from here and looking up your address -

https://datamillnorth.org/dataset/household-waste-collections

You may need to edit the flow to change the path in the exec node and template node depending on where you choose to put the script and images files. You can just download the 3 bin images here or create your own ;-)

Untitled GREEN BROWN BLACK

[{"id":"9765237e3099a326","type":"tab","label":"Flow 4","disabled":false,"info":"","env":[]},{"id":"ef2c0fa3aaf3f07d","type":"exec","z":"9765237e3099a326","command":"/home/pi/.node-red/my-data/getDates.sh","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"Get Bin Dates","x":820,"y":420,"wires":[[],[],["22250e27cd8d645e"]]},{"id":"9ebd5fdcf78affb3","type":"csv","z":"9765237e3099a326","name":"","sep":",","hdrin":"","hdrout":"none","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":1150,"y":420,"wires":[["e53e5fb6d90e2308"]]},{"id":"22250e27cd8d645e","type":"file in","z":"9765237e3099a326","name":"read dates","filename":"/home/pi/.node-red/my-data/dates.txt","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":1010,"y":420,"wires":[["9ebd5fdcf78affb3"]]},{"id":"e53e5fb6d90e2308","type":"function","z":"9765237e3099a326","name":"Add Dates","func":"let binDates = []\n\nfor (let index = 0; index < msg.payload.length; index++) {\n    let date = msg.payload[index].col3.split('/')\n    date = Date.UTC(parseInt(\"20\" + date[2]), date[1] - 1, date[0])\n    binDates.push({ timestamp: date, bin: msg.payload[index].col2, date: msg.payload[index].col3 })\n}\n\nbinDates.sort((b, a) => b.timestamp - a.timestamp); // b - a for reverse sort\n\nflow.set(\"binDates\", binDates)\n\nmsg.payload=binDates\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1290,"y":420,"wires":[["ab98afadfb47de29"]],"info":"let binDates = flow.get(\"binDates\") || {}\r\n\r\n\r\nfor (let index = 0; index < msg.payload.length; index++) {\r\n    let date = msg.payload[index].col3.split('/')\r\n    date = Date.UTC(parseInt(\"20\" + date[2]),date[1]-1,date[0])\r\n    \r\n    if (!binDates[date]) {\r\n        binDates[date] = { bin: msg.payload[index].col2, date: msg.payload[index].col3}\r\n        \r\n    }\r\n    \r\n}\r\n\r\nflow.set(\"binDates\",binDates)\r\n\r\n\r\nreturn msg;\r\n\r\n\r\n\r\n"},{"id":"1d522aa443d44106","type":"cronplus","z":"9765237e3099a326","name":"1st of Month","outputField":"payload","timeZone":"","persistDynamic":true,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule1","topic":"topic1","payloadType":"default","payload":"","expressionType":"cron","expression":"0 5 0 1 * ? *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":630,"y":420,"wires":[["ef2c0fa3aaf3f07d"]]},{"id":"2d88be0f46aaedc1","type":"ui_template","z":"9765237e3099a326","group":"acf0ac46b53c1e66","name":"Green","order":2,"width":"6","height":"5","format":"<style>\n    .bin_green {\n        border: 5px solid #00a550;\n        border-radius: 12px;\n        font-size: 25px;\n    }\n</style>\n\n<table>\n    <tr>\n        <td>\n            <img src=\"/images/{{msg.payload[0][0].bin}}.png\"  style=\"width: 130px\" >\n        </td>\n        <td>\n            <div ng-repeat=\"item in msg.payload[0]\">\n                {{item.date}}\n            </div>\n        </td>\n    </tr>\n</table>","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","className":"bin_green","x":1470,"y":360,"wires":[[]],"info":"<style>\r\n    md-checkbox .md-label {\r\n        top: unset;\r\n    }\r\n</style>\r\n\r\n<form>\r\n    <fieldset style=\"width:90%\">\r\n        <legend>Select Zones</legend>\r\n        <div layout=\"row\" layout-wrap  flex>\r\n            <div flex=\"45\" ng-repeat=\"item in msg.payload\">\r\n                <md-checkbox ng-model=\"item.value\" aria-label=\"checkbox\"> {{item.name}}</md-checkbox>\r\n\r\n            </div>\r\n        </div>\r\n    </fieldset>\r\n\r\n    <fieldset style=\"width:90%\">\r\n        <md-button ng-click=\"send(msg)\">\r\n            Refresh\r\n        </md-button>\r\n        <md-button ng-click=\"send({select:'all'})\">\r\n            All\r\n        </md-button>\r\n        <md-button ng-click=\"send({select:'none'})\">\r\n            None\r\n        </md-button>\r\n    </fieldset>\r\n</form>"},{"id":"557f685755b061d2","type":"inject","z":"9765237e3099a326","name":"refresh","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1170,"y":360,"wires":[["ab98afadfb47de29"]]},{"id":"4e7156631b569b51","type":"ui_template","z":"9765237e3099a326","group":"acf0ac46b53c1e66","name":"Brown","order":3,"width":"6","height":"5","format":"<style>\n    .bin_brown {\n        border: 5px solid #80612e;\n        border-radius: 12px;\n        font-size: 25px;\n    }\n</style>\n\n\n<table>\n    <tr>\n        <td>\n            <img src=\"/images/{{msg.payload[0][0].bin}}.png\"  style=\"width: 130px\" >\n        </td>\n        <td>\n            <div ng-repeat=\"item in msg.payload[0]\">\n                {{item.date}}\n            </div>\n        </td>\n    </tr>\n</table>\n","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","className":"bin_brown","x":1470,"y":320,"wires":[[]],"info":"<style>\r\n    md-checkbox .md-label {\r\n        top: unset;\r\n    }\r\n</style>\r\n\r\n<form>\r\n    <fieldset style=\"width:90%\">\r\n        <legend>Select Zones</legend>\r\n        <div layout=\"row\" layout-wrap  flex>\r\n            <div flex=\"45\" ng-repeat=\"item in msg.payload\">\r\n                <md-checkbox ng-model=\"item.value\" aria-label=\"checkbox\"> {{item.name}}</md-checkbox>\r\n\r\n            </div>\r\n        </div>\r\n    </fieldset>\r\n\r\n    <fieldset style=\"width:90%\">\r\n        <md-button ng-click=\"send(msg)\">\r\n            Refresh\r\n        </md-button>\r\n        <md-button ng-click=\"send({select:'all'})\">\r\n            All\r\n        </md-button>\r\n        <md-button ng-click=\"send({select:'none'})\">\r\n            None\r\n        </md-button>\r\n    </fieldset>\r\n</form>"},{"id":"bc989aae29e34d4c","type":"ui_template","z":"9765237e3099a326","group":"acf0ac46b53c1e66","name":"Black","order":1,"width":"6","height":"5","format":"<style>\n    .bin_black {\n        border: 5px solid black;\n        border-radius: 12px;\n        font-size: 25px;\n    }\n</style>\n\n<table>\n    <tr>\n        <td>\n            <img src=\"/images/{{msg.payload[0][0].bin}}.png\"  style=\"width: 130px\" >\n        </td>\n        <td>\n            <div ng-repeat=\"item in msg.payload[0]\">\n                {{item.date}}\n            </div>\n        </td>\n    </tr>\n</table>","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","className":"bin_black","x":1470,"y":400,"wires":[[]],"info":"<style>\r\n    md-checkbox .md-label {\r\n        top: unset;\r\n    }\r\n</style>\r\n\r\n<form>\r\n    <fieldset style=\"width:90%\">\r\n        <legend>Select Zones</legend>\r\n        <div layout=\"row\" layout-wrap  flex>\r\n            <div flex=\"45\" ng-repeat=\"item in msg.payload\">\r\n                <md-checkbox ng-model=\"item.value\" aria-label=\"checkbox\"> {{item.name}}</md-checkbox>\r\n\r\n            </div>\r\n        </div>\r\n    </fieldset>\r\n\r\n    <fieldset style=\"width:90%\">\r\n        <md-button ng-click=\"send(msg)\">\r\n            Refresh\r\n        </md-button>\r\n        <md-button ng-click=\"send({select:'all'})\">\r\n            All\r\n        </md-button>\r\n        <md-button ng-click=\"send({select:'none'})\">\r\n            None\r\n        </md-button>\r\n    </fieldset>\r\n</form>"},{"id":"ab98afadfb47de29","type":"function","z":"9765237e3099a326","name":"","func":"let binDates = flow.get(\"binDates\")\nvar brown = []\nvar green = []\nvar black = []\nbrown.push(binDates.filter(e => e.bin === \"BROWN\"))\ngreen.push(binDates.filter(e => e.bin === \"GREEN\"))\nblack.push(binDates.filter(e => e.bin === \"BLACK\"))\nlet msg1 = { payload: brown }\nlet msg2 = { payload: green }\nlet msg3 = { payload: black }\nreturn [msg1, msg2, msg3]","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1320,"y":360,"wires":[["4e7156631b569b51"],["2d88be0f46aaedc1"],["bc989aae29e34d4c","6544e0f202163bec"]]},{"id":"6544e0f202163bec","type":"debug","z":"9765237e3099a326","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1490,"y":440,"wires":[]},{"id":"acf0ac46b53c1e66","type":"ui_group","name":"Bins","tab":"6ef0f00b7932b858","order":1,"disp":false,"width":"6","collapse":false,"className":""},{"id":"6ef0f00b7932b858","type":"ui_tab","name":"Bins","icon":"iconify-fa-solid:trash-alt","order":20,"disabled":false,"hidden":false}]

Flow Info

Created 2 years, 9 months ago
Rating: 4 1

Owner

Actions

Rate:

Node Types

Core
  • csv (x1)
  • debug (x1)
  • exec (x1)
  • file in (x1)
  • function (x2)
  • inject (x1)
Other

Tags

Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option