Bin / Waste Collection Reading a CSV to MQTT

I have seen Heaps of these here
I wanted to lean node-red

so here my verson of waste Collection.

first you need nodered installed
next a csv file of the dates its pickup.

Calendar,PickDate,FoodScraps,LandFill,Recycling,Glass,ChristmasTree
TuesdayDay,9/03/2019,P,0,P,0,0
TuesdayDay,9/10/2019,P,P,0,P,0
TuesdayDay,09/17/2019,P,0,P,0,0
TuesdayDay,09/24/2019,P,P,0,P,0
TuesdayDay,10/01/2019,P,0,P,0,0
TuesdayDay,10/08/2019,P,P,0,P,0
TuesdayDay,10/15/2019,P,0,P,0,0
TuesdayDay,10/22/2019,P,P,0,P,0
TuesdayDay,10/29/2019,P,0,P,0,0
TuesdayDay,11/05/2019,P,P,0,P,0

only RULE DATE MUST BE USA FORMAT MM/DD/YYYY
the date is the date its been pick up

P = what been pickup
screen shot

the code

[{"id":"48285083.b188b","type":"function","z":"39c278b3.923268","name":"Read CSV find the Current Week and output Data","func":"\nlet toda = new Date()\nlet today = new Date(DateToNumber( toda.getDate() , toda.getMonth() ,toda.getFullYear()));\nlet mod = today.getDay();\nlet Diff =(mod * 86400000)\nvar FirstDayWeek  = today - Diff ;\n//node.warn( \" mod = \" + mod );\n//node.warn( \" today = \" + getDate(today) );\n//node.warn( \" FirstDayWeek = \" + getDate(FirstDayWeek) );\nvar payload1={};\nvar FoodScraps = {};\nvar LandFill = {};\nvar Recycling = {};\nvar Glass = {};\nvar ChristmasTree = {};\nvar Mix = {};\nvar MaxRows = 0;\npayload1.payload = getDate(today) ; \nvar pickup = msg.payload;\nfor (i = 0; i < msg.payload.length; i++) {\n        MaxRows = msg.payload.length\n        pickup = msg.payload[i];\n        var bla = pickup.PickDate.split(\"/\")\n        var PickDate = new Date(DateToNumber(bla[1] , Number(bla[0])-1 , bla[2]));\n        // node.warn( i + \"+++++++++++++++++\");\n        // node.warn( i + \" WeekStarting = \" + getDate(PickDate) );\n        // what Day is it 0=Sun 1=Mon ....\n        var wmod = PickDate.getDay();\n        // as there are 86400000 milliseconds in a day\n        var wDiff = (wmod * 86400000);\n        // node.warn(\"wmod = \" + wmod);\n        // node.warn(\"wDiff = \" + wDiff);\n        // find start or week\n        var FirstDayStarting = PickDate - wDiff; \n        //node.warn(\"CC FirstDayWeek = \" + getDate(FirstDayWeek));\n        //node.warn(\"CC FirstDayStarting = \" + getDate(FirstDayStarting));\n        // does this equal the current week if so get out of loop\n        if ( FirstDayWeek === FirstDayStarting) { break; }\n    }\n\n\n// is today > pickup day if so get mext line in CSV file\nif (today > PickDate) {\n    i = i +1\n} else {\n    \n}\n\n// is i less than MaxRows  \nif (i <= MaxRows ) {\n    pickup = msg.payload[i];\n    \n    bla = pickup.PickDate.split(\"/\");\n    \n    var pickupdate = DateToNumber(bla[1] , bla[0]-1 , bla[2]);\n    \n    msg.payload = pickup;\n    FoodScraps.payload = (pickup.FoodScraps !== 0 ?  Formatit(today,pickupdate) : \"\");\n    LandFill.payload =  (pickup.LandFill !== 0 ?  Formatit(today,pickupdate) : \"\");\n    Recycling.payload =  (pickup.Recycling !== 0 ?  Formatit(today,pickupdate) : \"\");\n    Glass.payload =  (pickup.Glass !== 0 ?  Formatit(today,pickupdate) : \"\");\n    ChristmasTree.payload =  (pickup.ChristmasTree !== 0 ?  Formatit(today,pickupdate) : \"\");\n}else {\n    // csv needs updating\n    msg.payload = pickup;\n    FoodScraps.payload = \"UPDATE CSV\";\n    LandFill.payload =  \"UPDATE CSV\";\n    Recycling.payload =  \"UPDATE CSV\";\n    Glass.payload =  \"UPDATE CSV\";\n    ChristmasTree.payload =  \"UPDATE CSV\";\n    \n}\n\n \n// we have landfill and glass on the same day \n// \nif ((LandFill.payload === \"\") || (Glass.payload === \"\")) {\n    Mix.payload = \"\";\n}else {\n    Mix.payload = (LandFill.payload === Glass.payload ?  Formatit(today,pickupdate) : \"\");\n}\n\n\n// output what we know\nreturn  [msg,payload1,FoodScraps,LandFill,Recycling,Glass,ChristmasTree,Mix];\n\n// These are just funtion i wrote to make codeing easyer\nfunction Formatit(vartoday,pickUpDate) {\n    MyMaths = (pickUpDate - vartoday) / 86400000 ;\n    // node.warn(\"MyMaths = \" + MyMaths );\n    if (MyMaths === 0) {\n        return \"Today\"\n    }\n    else if (MyMaths === 1) {\n        return \"Tomorrow\"    \n    }\n    else if (MyMaths < 6) {\n        return getWeekDay((pickUpDate));\n    }\n    else {\n        return getDate((pickUpDate));\n    }\n}\n\nfunction getWeekDay(ThisDate){\n    var Bla = new Date(ThisDate);\n    var WeekDays = [\"Sun\",\"Mon\",\"Tue\",\"Wed\",\"Thu\",\"Fri\",\"Sat\"];\n    return WeekDays[Bla.getDay()];\n}\n    \nfunction getDate(ThisDate){\n//    node.warn(\"ThisDate = \" + ThisDate );\n    var Bla = new Date(ThisDate);\n    var shortMonths = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];\n    return Bla.getDate() + \" \" + shortMonths[Bla.getMonth()] ;\n}\n\nfunction DateToNumber(ThisDay,ThisMonth,ThisYear) {\n    // node.warn(\"ThisMonth = \" + ThisMonth );\n    // node.warn(\"ThisDay = \" + ThisDay );\n    return new Date(ThisYear , ThisMonth, ThisDay, 0,0,0).getTime()\n}\n\n","outputs":8,"noerr":0,"x":250,"y":400,"wires":[["d4ffe39a.ae53a"],["b9a98ba4.d2f348"],["a2e3c5a6.31b9d8","1fcd790c.3aa327"],["73207f0c.0d8c2","c58b56ae.7778f8"],["53e043e7.9b223c","552f833a.52bb9c"],["e98959f3.bc44b8","d42b335f.2f076"],["43bbf526.4192fc","e0165613.43baa8"],["24c92c75.c38674","2e99b72b.264c98"]],"outputLabels":["msg","today","FoodScraps","LandFill","Recycling","Glass","ChristmasTree","Mix"]}]

have left all my working in side it

there heaps of Comments

landfill-glass

food glass recycling landfill

Sensor are

#=======================================================================
#
#=======================================================================
  - platform: mqtt
    name: "Pickup FoodScraps"
    state_topic: "nodered/FoodScraps"
    qos: 1
#=======================================================================
#
#=======================================================================
  - platform: mqtt
    name: "Pickup LandFill"
    state_topic: "nodered/LandFill"
    qos: 1
#=======================================================================
#
#=======================================================================
  - platform: mqtt
    name: "Pickup Recycling"
    state_topic: "nodered/Recycling"
    qos: 1
#=======================================================================
#
#=======================================================================
  - platform: mqtt
    name: "Pickup Glass"
    state_topic: "nodered/Glass"
    qos: 1
#=======================================================================
#
#=======================================================================
  - platform: mqtt
    name: "Pickup Christmas Trees"
    state_topic: "nodered/ChristmasTree"
    qos: 1
#=======================================================================
#
#=======================================================================
  - platform: mqtt
    name: "Pickup Mix"
    state_topic: "nodered/Mix"
    qos: 1

the lovelace look

image

its code

cards:
  - cards:
      - entity: sensor.pickup_foodscraps
        entity_picture: /local/images/food.png
        name: Food
        show_entity_picture: true
        show_icon: false
        show_state: true
        style:
          - border: 0px
          - box-shadow: 0px
        styles:
          card:
            - border: 0px
            - box-shadow: 0px
          name:
            - font-size: 10px
        type: 'custom:button-card'
      - entity: sensor.pickup_recycling
        entity_picture: /local/images/recycling.png
        name: Recycling
        show_entity_picture: true
        show_icon: false
        show_state: true
        style:
          - border: 0px
          - box-shadow: 0px
        styles:
          card:
            - border: 0px
            - box-shadow: 0px
          name:
            - font-size: 10px
        type: 'custom:button-card'
      - entity: sensor.pickup_mix
        entity_picture: /local/images/landfill-glass.png
        name: Mix
        show_entity_picture: true
        show_icon: false
        show_state: true
        style:
          - border: 0px
          - box-shadow: 0px
        styles:
          card:
            - border: 0px
            - box-shadow: 0px
          name:
            - font-size: 10px
        type: 'custom:button-card'
    type: horizontal-stack
style:
  border: false
  font_size: 24px
title: Refuse Collection
type: 'custom:vertical-stack-in-card'

in side the function are a number of other functions

hope this help out someone else

see clear as mud

So your council/utility only has this available as csv? Tell them to get out of the 90’s!

NO
can’t find the api for ours they have a google app but can’t find the data

but wanted to lean nodered