Announcement

Collapse
No announcement yet.

Run event when the time equals a device value or string

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

    Run event when the time equals a device value or string

    I need to trigger an event when the time is equal to a device's value.
    Specifically, I want to set a virtual device's value to a time such as 2300(hhmm). When the time is equal to the value of the device, I want to trigger an event.

    I set the value of the device in HSTouch. I could also use, I believe, the device's string value.
    The event would start a water sprinkler zone based on a time that can be changed from HSTouch.

    #2
    One way to do this would be to use a recurring event that sets a (new) device value to the current time in the same format as your current watering time device. Then use EasyTrigger to trigger an event when the two device values become equal.
    Mike____________________________________________________________ __________________
    HS3 Pro Edition 3.0.0.548, NUC i3

    HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF | RFXCOM | Vantage Pro | Green-Eye | Edgeport/8 | Way2Call | Ecobee3 | EtherRain | Ubiquiti

    Comment


      #3
      Years ago I was trying to do the same thing for a bedside alarm clock. I was hoping it would be as easy as to use the EasyTrigger String compare, but I couldn't get that to work for me. My solution was to do as Michael said about checking the time every minute. I put the current time into a virtual device to compare to my alarm time then ran the comparison script.
      Click image for larger version  Name:	Screen Shot 2019-12-10 at 11.32.30 AM.png Views:	0 Size:	106.8 KB ID:	1345745

      I have some other logic assembling the alarm time into the desired format, but my solution to compare the values was with a script.

      Click image for larger version  Name:	Screen Shot 2019-12-10 at 11.33.23 AM.png Views:	0 Size:	294.2 KB ID:	1345746

      Finally, here are the devices. You can see 377 and 379 down at the bottom. If they match, it turns 380 On which triggers my alarm.
      Click image for larger version

Name:	image_84032.png
Views:	548
Size:	215.0 KB
ID:	1345747

      Comment


        #4
        Here is the outline of a script that would be called on the days needed at midnight. It would check every 60 seconds to see if it should activate the zone. After activation it would exit. The event to water would be manually triggered.

        You will need to create global variable in startup.vb to store the HSTouch settings.

        An outline script is given below to get you started. You could pass parameters if you want.

        'Trigger a zone

        Sub Main()

        Dim ZoneTime As Time = hs.GetVar("zntime") 'get the time set by hstouch
        Dim CurrentTime As DateTime


        'You need to add the current date to the time to get a datetime for your hstouch time. <-------------------------------------

        Do While Minute < 1438 'allow for some time creep

        CurrentTime = Time 'Set the current time

        If (ZoneTime - CurrentTime).TotalSeconds < 59 then

        hs.TriggerEvent "WaterZone" 'Activate your watering device or event here

        Exit Sub 'Exit after it is run

        End If

        Minute = Minute + 1

        hs.WaitSecs(60)

        Loop

        End Sub

        Comment


          #5
          Here is my startup.vb to declare and initialize global variables. It is .vb on my system but have to rename to .txt to upload.

          Startup.txt
          Attached Files

          Comment


            #6
            Many thanks to everyone's responses. I will try each of the methods provided to me. Your help is really appreciated.

            Comment


              #7
              Originally posted by Grundcm View Post
              Years ago I was trying to do the same thing for a bedside alarm clock. I was hoping it would be as easy as to use the EasyTrigger String compare, but I couldn't get that to work for me. My solution was to do as Michael said about checking the time every minute. I put the current time into a virtual device to compare to my alarm time then ran the comparison script.
              Click image for larger version Name:	Screen Shot 2019-12-10 at 11.32.30 AM.png Views:	0 Size:	106.8 KB ID:	1345745

              I have some other logic assembling the alarm time into the desired format, but my solution to compare the values was with a script.

              Click image for larger version Name:	Screen Shot 2019-12-10 at 11.33.23 AM.png Views:	0 Size:	294.2 KB ID:	1345746

              Finally, here are the devices. You can see 377 and 379 down at the bottom. If they match, it turns 380 On which triggers my alarm.
              Click image for larger version

Name:	image_84032.png
Views:	548
Size:	215.0 KB
ID:	1345747
              This is exactly what im working on right now - thanx!
              However, Im stuck on how you combine the values from 374, 375 and 376 into your device 377?

              Comment


                #8
                I have an event that runs whenever any of the values change:
                Click image for larger version

Name:	Screen Shot 2021-07-28 at 7.35.29 PM.png
Views:	267
Size:	308.5 KB
ID:	1486451


                And here is the logic inside "Alarm_Time_Load.vb": ( I did not use a picture, maybe you can copy/paste and save some time.


                Sub Main(parm as object)

                Dim Chh as String
                Dim Cmm as String
                Dim Campm as Integer


                Chh=hs.DeviceValue(374)
                Cmm=hs.DeviceValue(375)
                Campm=hs.DeviceValue(376)


                if Campm=0 then
                if Cmm<10 then
                hs.SetDeviceString(377, Chh & ":0" & Cmm & " AM", True)
                else
                hs.SetDeviceString(377, Chh & ":" & Cmm & " AM", True)
                End If
                else
                if Cmm<10 then
                hs.SetDeviceString(377, Chh & ":0" & Cmm & " PM", True)
                else
                hs.SetDeviceString(377, Chh & ":" & Cmm & " PM", True)
                End If
                End If




                As always there is probably a better or at least many different ways to do this. This is just the first way I got it to work.

                Comment

                Working...
                X