Simple Recycling Bin Week Indicator

At our home our local council provides two bins - one for waste and the other recycling.

The recycling bin needs to be put out every second week and to help me remember I wanted to create a simple indicator in the UI that would show either just the green waste bin, or both the waste and recycling bin.

There are a bunch of ways to do this, but I wanted to get the whole solution down to the minimum configuration.

First I created a String item:

String BinCollectionWeek “Bin Week [%s]” (Home) // [%s] due to iphone App bug

A Frame in my sitemap:

Frame label="Home Info" {
    Text item= BinCollectionWeek
}

Then a rule to change the state between ‘waste’ or ‘recycling’:

// This rule is designed to show whether it's a recycling bin week or just a waste pickup
// It triggers every Monday morning and sets the state of BinCollectionWeek based on 
// a BinCollectionStartDate - a known recycling week.
// The BinCollectionWeek item displays an waste or waste/recycling icon depending on value.
rule "Bin Week"
when
   Time cron "0 0 7 ? * MON *" 
then
  val DateTime BinCollectionStartDate = new DateTime("2020-08-07T00:00:00") // On this date both recycle and waste was picked up

  logDebug(LogSubpackage, "Bin Week rule started")

  // Calculate if it's an even or odd week since BinCollectionStartDate	
  if (Weeks.weeksBetween(BinCollectionStartDate, now).getWeeks() % 2 == 0)
      BinCollectionWeek.sendCommand("recycling")
    else
      BinCollectionWeek.sendCommand("waste")
  
  logDebug(LogSubpackage, "Bin Week rule finished")
end 

Finally two icons:
bin-waste bin-waste.png
bin-recycling bin-recycling.png

You’ll also need to copy the ‘bin-waste.png’ file to create a duplicate called ‘bin.png’ as the icon wont appear without it. These files are placed in OPENHAB-conf->icons->classic

Now I have an indicator in my Habpanel app

6 Likes

Updated for OH3

// Imports
import java.time.temporal.ChronoUnit

// this rule is designed to show whether it's a recycling bin week or just a waste pickup
// It triggers early every Saturday morning and sets the state of BinCollectionWeek based on
// a BinCollectionStartDate - a known recycling week.
// The BinCollectionWeek item displays an waste or waste/recycling icon depending on value.

rule "Bin Week"
when
  Time cron "0 0 6 ? * SAT *" or System started
then

  val LocalDate today = LocalDate.now()
  val LocalDate BinCollectionStartDate = LocalDate.of(2020, 8, 7) // .of(YYYY, MM, DD)

  logDebug(LogSubpackage, "Bin Week rule started")

  // Calculate if it's an even or odd week since BinCollectionStartDate
  if (ChronoUnit.WEEKS.between(BinCollectionStartDate, today) % 2 == 0)
      BinCollectionWeek.sendCommand("recycling")
  else
      BinCollectionWeek.sendCommand("waste")

  logDebug(LogSubpackage, "Bin Week rule finished")
end
2 Likes

Thank you for this, it is exactly what I needed!