Announcement

Collapse
No announcement yet.

Using a calendar to change a virtual device

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

    Using a calendar to change a virtual device

    I am using various google calendars, and with the help of this PI I display upcoming appointments and birthdays in virtual devices. Now I have created anotehr calendar, with public holidays and my holidays. I want to create a event (script) which turns a virtual device on if the calendar has an entry holiday. The calendar is called Holidays, and the only entries are all day events called Holiday.

    I use this script (which needs to be adapted) to grab events from my existing calendar to be displayed in my virtual device.

    Code:
    Sub Main(parm as object)
    
    Const ScriptName As String = "SendCalEvents"
    
        Dim allEvents As Object()
        Dim calevents as string = ""
    
    allEvents = hs.PluginFunction("BLGData", "", "GetCalendarEventsForXDays", new Object(){"xxx@gmail.com","Holidays",0})
    
    If allEvents.GetUpperBound(0) = -1
    
            ' calevents = ""
    
            hs.SetDeviceValueByRef(2035,0,true)
    
    Else
    
           ' For Each ev As Object In allEvents
    
               ' hs.writelog("Info", ev.StartDate & " " & ev.Name)
    
               ' calevents = calevents  & ev.StartDate.Substring(0, ev.StartDate.Length - 5)& " " & ev.Name & "<br>"
    
    
    
               hs.SetDeviceValueByRef(2035,100,true)
    
    End If
    
    
    End Sub

    How do I need to change this, to load todays events from Holidays (is {"xxx@gmail.com","Holidays",0}) that right ? I only need to determine if there is an entry, as that calendar is only to store holidays

    #2
    I just tested this, it seems to work. What is not working yet, I would like to write into the log 'Holiday' when the script runs and it finds a holiday, if it doesnt 'no holiday'

    I tried adding:

    hs.writelog("No Holiday found in calendar")

    but got an error...

    Running script C:\Program Files (x86)\HomeSeer HS3\scripts\HolidayCalendar.vb :Exception has been thrown by the target of an invocation.Overload resolution failed because no accessible 'writelog' accepts this number of arguments.

    Got it.

    hs.writelog("Info", "No Holiday found in calendar") all seems to work now.

    I'll leave these posts as it might help others

    Comment


      #3
      This a cleaned up version of the working script:

      Code:
      Sub Main(parm as object)
      
      Const ScriptName As String = "SendCalEvents"
      
          Dim allEvents As Object()
          Dim calevents as string = ""
      
      allEvents = hs.PluginFunction("BLGData", "", "GetCalendarEventsForXDays", new Object(){"xxx@gmail.com","Holidays",0})
      
      If allEvents.GetUpperBound(0) = -1
      
                 hs.writelog("Info", "No Holiday found in calendar")
      
      
                 hs.SetDeviceValueByRef(2046,0,true)
      
      Else
      
                 hs.writelog("Info", "Holiday found in calendar")
      
      
                 hs.SetDeviceValueByRef(2046,100,true)
      
      End If
      
      
      End Sub

      Comment


        #4
        I also want to create a virtual event that will turn on if it's a holiday and turn off if it is not a holiday. I created the virtual event which is node #287 in my system.

        I created the script similar to yours and placed it in the scripts folder. I then created an event in HS4 that is triggered to run at 12:01 AM. In the event I run the script that was placed in the scripts folder. The script then runs at 12:01 AM successfully, but the event is deleted after running. The script still exists in the scripts folder.

        Question: Why is my event deleted? (Please understand, I am new at writing scripts) See script below that is called in the event.


        Sub Main(parm as object)
        Const ScriptName As String = "SendCalEvents"
        Dim allEvents As Object()
        Dim calevents as string = ""
        allEvents = hs.PluginFunction("BLGData", "", "GetCalendarEventsForXDays", new Object(){"name@gmail.com","Holiday in United States",0})

        If allEvents.GetUpperBound(0) = -1

        hs.writelog("Info", "No Holiday found in calendar")
        hs.SetDeviceValueByRef(287,0,true)
        Else
        hs.writelog("Info", "Holiday found in calendar")
        hs.SetDeviceValueByRef(287,100,true)
        End If
        End Sub

        Comment


          #5
          is it at all possible that you checked 'remove event after triggering' under advanced options?
          HS4 Pro on Shuttle NC10U, Win10; Z-NET
          Number of Devices: 1005
          Number of Events: 293

          Plug-Ins: BLLock, DirecTv, EasyTrigger, Honeywell WiFi Thermostat, Marquis monoprice Amp, MeiHarmonyHub, PHLocation2, Pushover 3P, UltraM1G3, rnbWeather, Worx Landroid, Z-Wave

          External applications: Homebridge-homeseer, Geofency, EgiGeoZone.

          Comment


            #6
            Yes, that was the issue. I meant to check "Include in Power Failure Recovery" and selected the wrong check box. I was worried about the script and forgot to check the obvious. Thanks.

            Comment

            Working...
            X