Announcement

Collapse
No announcement yet.

In scripts: How can I use current time as a condition? And delays?

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

    In scripts: How can I use current time as a condition? And delays?

    I am trying to consolidate multiple events into one single script (because it is more compact, easier to edit and it looks more transparent).
    I spent hours searching the forum but was not able to find an answer to how time and delays can be used in a script.

    Here is what I am trying to achieve:
    I would like to have a device "A1" to be turned "ON", wait for 5 minutes, then turned "OFF". It should be happening in 25 minutes cycles between 11am and 7pm.

    Thank you for your time/help on this. I would really appreciate a script sample...
    Alex

    #2
    Unless you're doing this as a script writing excerise to my way of thinking it's far easier and and more transparent to do this with a recurring event.
    Marty
    ------
    XPpro SP3 /w HS Standard 2.5.0.80, HSTouch Server - 1.0.0.70, HSTouch Client 1.0.0.73 HSTouch Android - 1.0.0.2, HSTouch iPhone - 1.0.0.2
    Playing with HS3 a bit but it's just play at this point.

    Comment


      #3
      I agree with Marty. You can do everything you are asking within one event, with no script.

      Create the event with a recurring trigger, every 25 minutes. Check the "Apply Conditions", and add two Time of Day conditions in a single group: One after 11:00am and one before 7:00pm. In the event action, add two device actions: One to turn it ON, and one to turn it OFF with a 5 minute delay.

      No mess, no fuss (and no script!).

      Steve

      Comment


        #4
        Steve, Marty, thank you.
        I currently have it set up as an event (events, to be precise) and it works.
        The thing is that my system setup is more complicated than the example that I gave in my post. In reality I have multiple devices plus conditions based on temperature readings and on status of other virtual devices (and, of course, time).

        I currently have many copies of these events (or I have to create events with multiple groups of conditions) for different time of the day/night.

        I occasionally edit those events adjusting the settings to real life and I found it as a tedious task because I have to go over all of them one by one, delete certain groups/conditions and recreate them from scratch. I don't remember a single time when I did it right on the first try and there is always room for errors and typos.

        I was hoping that if someone would give me a hint on how I could use time as a string (to assign this sting value to a virtual device, for example).
        This way I could have all my parameters into a script - all in one place - easy to look through and easy to edit.
        Alex

        Comment


          #5
          Delays for your scripts:
          hs.WaitSecs #ofsecnds

          Comment


            #6
            Originally posted by Alexey View Post
            Steve, Marty, thank you.
            I currently have it set up as an event (events, to be precise) and it works.
            The thing is that my system setup is more complicated than the example that I gave in my post. In reality I have multiple devices plus conditions based on temperature readings and on status of other virtual devices (and, of course, time).

            I currently have many copies of these events (or I have to create events with multiple groups of conditions) for different time of the day/night.

            I occasionally edit those events adjusting the settings to real life and I found it as a tedious task because I have to go over all of them one by one, delete certain groups/conditions and recreate them from scratch. I don't remember a single time when I did it right on the first try and there is always room for errors and typos.

            I was hoping that if someone would give me a hint on how I could use time as a string (to assign this sting value to a virtual device, for example).
            This way I could have all my parameters into a script - all in one place - easy to look through and easy to edit.
            Alex
            Well, more complicated problems (than the one you described in your original question) sometimes require more complicated solutions - but not always.

            I'm certain there is a way to do what you want with scripts. You can save time-of-day for conditions in virtual devices or in INI files, and you can have a script that runs periodically and handles all the logic you are looking for. I'm guessing that - based on what you've said - it will require lots of time for you describe all these contraints and have someone tell you how to handle it (or just write it for you).

            Those who know me will attest to the fact that I am always willing to try and help people, but I'm thinking this one may be something you are going to have to work out yourself. If you can start working on it and break the problem down into smaller pieces, I think you can ask about those individual elements here and get lots of help.

            I'm certainly not meaning to poo-poo what you want to do. It actually sounds like a cool thing to do. I'm just not sure how to help you.

            BTW: You don't want to use waitsecs to pause a script for several minutes. Not good. There are however lots of other ways to handle things spanning minutes or hours.

            Steve

            Comment


              #7
              Originally posted by Alexey View Post
              I was hoping that if someone would give me a hint on how I could use time as a string (to assign this sting value to a virtual device, for example).
              If this is what you're asking for,
              this VB.NET statement should put the current date/time into a device string (where the virtual device in question is D1). This will also set the DeviceLastChange for D1 to the same value:

              hs.SetDeviceString("D1",now, True)

              Or
              just save the current date to an INI file where it can be used/changed as necessary and doesn't use a device:

              hs.SaveINISetting("Section", "CurrentTime", now, "TimeData.ini")

              (see the HS help on SaveINISetting and GetINISetting)

              Like the others, I do think there may be more effective means of accomplishing your task. You're going to encounter the need to do some date/time interval calculations in your script. Help there is available on the web with a little digging. Experiment with it and build your task one step at a time.
              Real courage is not securing your Wi-Fi network.

              Comment


                #8
                DTMF codes to time

                Is there a way to convert DTMF codes to a specific time? For example, have the user dial 1230 and have that converted to a variable with the time 12:30 am?

                Comment

                Working...
                X