Announcement

Collapse
No announcement yet.

Can a script check if the time is in a schedule ?

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

    Can a script check if the time is in a schedule ?

    I have created a few schedules. I have a script (see below), but some of the conditions (case) I only want to run or trigger if it is inside a specific schedule

    Sub Main(ByVal Parms As Object)
    Dim Temperature As Double
    Temperature = hs.DeviceValueEx(18)
    Select Case Temperature
    Case < 20.4
    hs.TriggerEvent("AC off auto trigger")
    Case 22.0 To 23.5
    hs.TriggerEvent("AC on low auto trigger")
    Case > 23.5
    hs.TriggerEvent("AC on high auto trigger")
    End Select
    End Sub

    so each case should have another 'if in schedule x then...'

    #2
    Originally posted by mikee123 View Post
    I have created a few schedules. I have a script (see below), but some of the conditions (case) I only want to run or trigger if it is inside a specific schedule

    Sub Main(ByVal Parms As Object)
    Dim Temperature As Double
    Temperature = hs.DeviceValueEx(18)
    Select Case Temperature
    Case < 20.4
    hs.TriggerEvent("AC off auto trigger")
    Case 22.0 To 23.5
    hs.TriggerEvent("AC on low auto trigger")
    Case > 23.5
    hs.TriggerEvent("AC on high auto trigger")
    End Select
    End Sub

    so each case should have another 'if in schedule x then...'
    Since you are calling events from this script, why don't you put your triggers, temperature conditions and schedule conditions in the events and avoid the script altogether? Since you are going to have to use a event with some sort of trigger to run this script, make that the trigger for the three events. Then use your minimum and maximum temperatures and the EasyTrigger schedule as conditions. That would seem to be more direct and manageable than using an event to trigger a script which in turn triggers one of three events.
    HS4 Pro, 4.2.19.16 Windows 10 pro, Supermicro LP Xeon

    Comment


      #3
      One of the problems with that is that RFX temperature devices do not trigger. If you set an event trigger, if temperature of device x goes above...
      It will not trigger. I have posted about that in the RFXcom forum but had no response, but others have confirmed that since an update a while ago (might even be HS2) they do not trigger any more. So I had to get my logic onto a script. The way this is set up with various schedules it would be very awkward to get that into events, especially given that the temperature devices do not trigger. I also have a recurring trigger which triggers when time is in one of the schedules. Another triggers before to trigger another event, but I would like to incorporate this into the script. Now I also wanted a third schedule incorporated, and the only way I see is via this script...
      and I guess (and hope) that it would be possible to check if a easytrigger schedule is in or out of the scheduled times

      Comment


        #4
        right now the EasyTrigger plug-in does not expose any function to scripting (because most of the time this plug-in is used to avoid scripting), but this is a feature easy to add, so I just added it to my TODO list.

        Comment


          #5
          That's good news. I cannot always avoid scripts, so it would be a good addition. And the more I learn about scripts, they can make life easier.

          Comment


            #6
            Can't you put conditions (schedule) on the event so that when you trigger it from your script the conditions must be met otherwise the event won't go off?
            - Bram

            Send from my Commodore VIC-20

            Ashai_Rey____________________________________________________________ ________________
            HS3 Pro 3.0.0.534
            PIugins: ZMC audio | ZMC VR | ZMC IR | ZMC NDS | RFXcom | AZ scripts | Jon00 Scripts | BLBackup | FritzBox | Z-Wave | mcsMQTT | AK Ikea

            Comment


              #7
              Originally posted by AshaiRey View Post
              Can't you put conditions (schedule) on the event so that when you trigger it from your script the conditions must be met otherwise the event won't go off?
              No, not if I want a different schedule for each case.

              Comment


                #8
                Am i wrong when i think you use 3 different events to trigger?
                Code:
                 Case < 20.4
                hs.TriggerEvent("[COLOR=green]AC off auto trigger[/COLOR]")
                Case 22.0 To 23.5
                hs.TriggerEvent("[COLOR=lime]AC on low auto trigger[/COLOR]")
                Case > 23.5
                hs.TriggerEvent("[COLOR="DarkOliveGreen"]AC on high auto trigger[/COLOR]")
                - Bram

                Send from my Commodore VIC-20

                Ashai_Rey____________________________________________________________ ________________
                HS3 Pro 3.0.0.534
                PIugins: ZMC audio | ZMC VR | ZMC IR | ZMC NDS | RFXcom | AZ scripts | Jon00 Scripts | BLBackup | FritzBox | Z-Wave | mcsMQTT | AK Ikea

                Comment


                  #9
                  You re right in that is use 3 different triggers, so could check in the event about the schedule. I want to expand this though, keeping 3 events, but checking 5 schedules and possibly more. Then it gets quite complicated with events. Maybe still possible, but would be a lot easier to maintain and understand if I had it in the script, especially as I have to use a script anyway because of the RFXcom devices not triggering events

                  Comment


                    #10
                    in version 3.0.0.28 available here I have added the following functions accessible from scripts:

                    Code:
                    public bool IsTimeInScheduleTimeRange(string scheduleName)
                    public bool IsPluginRunning(string pluginName, string pluginInstance = "")
                    here is an example of a C# script using the IsTimeInScheduleTimeRange function:

                    Code:
                    public object Main(object[] Parms)
                    {
                        bool isInSchedule = (bool) hs.PluginFunction("EasyTrigger", "", "IsTimeInScheduleTimeRange", new object[] { "Test" });
                        
                        hs.WriteLog("EasyTrigger Script", "IsInSchedule = " + isInSchedule.ToString());
                        return 0;
                    }

                    Comment


                      #11
                      That's great.
                      As I am not that good with scripting yet, the result is in bool, so if in schedule bool would return 1 and if not bool would return 0 ?

                      Comment


                        #12
                        Originally posted by AshaiRey View Post
                        Am i wrong when i think you use 3 different events to trigger?
                        Code:
                         Case < 20.4
                        hs.TriggerEvent("[COLOR=green]AC off auto trigger[/COLOR]")
                        Case 22.0 To 23.5
                        hs.TriggerEvent("[COLOR=lime]AC on low auto trigger[/COLOR]")
                        Case > 23.5
                        hs.TriggerEvent("[COLOR=darkolivegreen]AC on high auto trigger[/COLOR]")
                        In this case I was triggering 3 different events, but that script has expanded, and I have others like that which are even more complex, habing more events I am triggering, and some with more than one condition to trigger an event.
                        The addition of being able to check if in schedule from a script will make a lot of my programming a lot easier, and I will be able to simplify a lot of my events

                        Comment


                          #13
                          Originally posted by mikee123 View Post
                          That's great.
                          As I am not that good with scripting yet, the result is in bool, so if in schedule bool would return 1 and if not bool would return 0 ?
                          the result is of type bool (=Boolean), if in schedule the function would return true, if not it would return false.

                          Note that the example I posted is C#, if you use VB .NET instead, you will have to adapt it.

                          Comment


                            #14
                            I am trying to test the new script functionality, but must have got something wrong

                            Code:
                            Sub Main(ByVal Parms As Object)
                                     Dim Temperature As Double
                                    Dim ScheduleName As String
                                    Dim high as Boolean
                                    Dim norm as Boolean
                                     Temperature = hs.DeviceValueEx(18)
                                     public high IsTimeInScheduleTimeRange(AC_High)
                                    public norm IsTimeInScheduleTimeRange(AC)
                                    
                                     Select Case Temperature
                                         Case < 20.4
                                            hs.TriggerEvent("Test AC off auto trigger")
                                         Case 22.0 To 23.5
                                            hs.TriggerEvent("Test AC on low auto trigger")
                                         Case > 23.5
                                            hs.TriggerEvent("Test AC on high auto trigger")
                             
                                     
                                    End Select
                                 
                                      If high = true and norm = false then    
                                         If temperature > 24.6
                                            hs.TriggerEvent("Test AC on high auto trigger")
                                         End If
                             
                                     End If
                                 
                                 End Sub
                            I get these errors in the log:

                            Aug-15 14:48:45 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\scheduletest.vb: End of statement expected. Aug-15 14:48:45 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\scheduletest.vb: End of statement expected. Aug-15 14:48:45 Error Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\scheduletest.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

                            Comment

                            Working...
                            X