No announcement yet.

Run event when the time equals a device value or string

  • 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.

    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, NUC i3

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


      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:	234
Size:	215.0 KB
ID:	1345747


        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



        End Sub


          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.

          Attached Files


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