Announcement

Collapse
No announcement yet.

VB.Net script - fortnightly recycling collection

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    VB.Net script - fortnightly recycling collection

    Just a couple of scripts that have been working for me for the past couple of years without a worry, and thought someone else might find it useful.

    I seem to remember that I had to search a bit to figure out how to manage fortnights - and getting a hint from these boards that helped me work out a solution using the hs.weeksleftinyear command.

    The code is really quite simple and just requires the setting up of a virtual device to store a recycling variable.


    Code:
    '==============
    'This script changes the recycling variable.z1 and is triggered once a week at 
    '2am every Sunday morning.
    'To make sure the weeks are properly in synch, set it to fire the same week 
    'as you read the variable.
    '==============
    Sub Main(parm as object)
    dim recWeekCurr
    dim weeksleft
    weeksleft = hs.weeksleftinyear
    recWeekCurr = hs.DeviceValue("z1")
    hs.speak(recWeekCurr)
    hs.speak(weeksleft)
    '==============
    'This only changes the variable every fortnight so that the recycling
    ' announcement can check against it.
    '==============
    If recWeekCurr - hs.weeksleftinyear = 2 then
      recweekCurr = recWeekCurr - 2
    end if
    '========
    'This happens at the end of the year to start the new year's count.
    '==========
      if recweekCurr < 2 then
        recWeekCurr = recWeekCurr + 52
      end if
    hs.SetDeviceValue("z1",recWeekCurr)
    End Sub
    '===============
    '===============
    '===============
    The second script is triggered by an 'any' device status change of one of the house lights on the day before collection day (or any reliable trigger of your choice).

    It checks the variable, makes sure the computer volume is not muted, and announces whether it's just a normal weekly collection or weekly plus recycling.

    You may need to adjust the condition (ie reverse the messages) depending on which week you have the fortnightly collection.

    Just delete any code that you don't need - it's got some padding
    Code:
     
    '=============
    Sub Main(parm as object)
    Dim mutestat
    If hs.GetMuteStatus("computer") = True then
      mutestat = 1
      hs.unmuteaudio("computer")
    else
      mutestat = 0
    end if
    dim recWeekCurr
    dim recWeekSave
    dim recWeekNew
    recWeekCurr = hs.DeviceValue("z1")
    '===========
    'You can reverse the following messages, depending which fortnight the 
    'collection occurs.
    hs.speak("The next recycling collection is " & recWeekCurr & " weeks from the end of the year.")
    hs.waitsecs(3)
    hs.speak("There are " & hs.weeksleftinyear & " weeks left this year.")
    hs.waitsecs(3)
    If (recWeekCurr - hs.weeksleftinyear) = 0 then
      hs.speak("So, it's recycling week this week.  Don't forget to put out the bin for recycling as well as the normal rubbish collection.")
    else
      hs.speak("It's rubbish day tomorrow.  It's not recycling week this week. Hey! Don't forget to put out the bin tonight!")
    end if
    hs.waitsecs(4)
    If mutestat = 1 then
      hs.muteaudio("computer")
    end if 
    End Sub
Working...
X