I have created a script to calculate the time of day at which I would like to raise some Lutron shades. This time corresponds to the point at which the sun passes the back face of my house, and so it varies by day. I don't see a trigger that I can use to run this event. All of the time triggers are related to sunrise and sunset. I have Easy Trigger, but I don't see anything there either. Could I accomplish this with another script? Also, I have stored the time in question in a global variable. Is that the correct approach?
Announcement
Collapse
No announcement yet.
How to Run an Event at a Calculated Time?
Collapse
X
-
I'm not really sure if a global variable can be used to trigger an event, but you should be able to create a device that can be used as a trigger. Maybe call it something like "Shade Control" with values for Up and Down. Use you're script to update that device value, and then set your events to act based on that device change.
-
you can use easy trigger to do a daily sunrise+5 hours if you wanted to. but in order to vary with the arc of the changing seasons of the sun you may have to make a couple of different easy trigger schedules. I would think you would only need about 5 or 6 daily schedules to cover it over the course of a year. maybe even less.....
Comment
-
Here's a script snippet to add events to run at a specific times. This one creates two events, one to turn a device on at a specific time and one to turn it off.
Code:Sub CreateEvent(StartTime,StartDate,Delay,DeviceName) dim Evref as integer dim Ok as Boolean dim CC as CAPIControl Dim logName As String = "Block Heater Event Creation" 'set log type for HS log Dim Debug As Boolean = True 'set to True if the script give you errors and it will provide additional info in the HS3 log to help troubleshoot Dim StartDateTime As Date = CDate(StartDate & " " & StartTime) If Debug Then hs.writelog(logName,CStr(StartDateTime)) ' create a new event Evref = hs.NewEventEx("Block Heater On " & Cstr(DeviceName), "Block Heaters", "Block Heaters") ' set the trigger time of the event Ok = hs.EventSetTimeTrigger(Evref, CStr(StartDateTime)) ' set the event to delete itself after it runs hs.DeleteAfterTrigger_Set(Evref) ' add a device action to the event CC = hs.CAPIGetSingleControlByUse(DeviceName, ePairControlUse._On) hs.AddDeviceActionToEvent(Evref, CC) hs.EnableEventByRef(Evref) Dim StopDateTime As Date = StartDateTime.AddMinutes(Delay) If Debug Then hs.writelog(logName,CStr(StopDateTime)) ' create a new event Evref = hs.NewEventEx("Block Heater Off " & Cstr(DeviceName), "Block Heaters", "Block Heaters") ' set the trigger time of the event Ok = hs.EventSetTimeTrigger(Evref, CStr(StopDateTime)) ' set the event to delete itself after it runs hs.DeleteAfterTrigger_Set(Evref) ' add a device action to the event CC = hs.CAPIGetSingleControlByUse(DeviceName, ePairControlUse._Off) hs.AddDeviceActionToEvent(Evref, CC) hs.EnableEventByRef(Evref) End Sub
HS 4.2.8.0: 2134 Devices 1252 Events
Z-Wave 3.0.10.0: 133 Nodes on one Z-Net
Comment
-
socalsharky It is vb.net. Sometimes it's easy to tell based on functions, etc. that are not available in the other, but a lot of times it is not. If you need a vbs example, I should be able to provide that too as the original script I had was written in vbs and I converted it a few years ago to vb.net.HS 4.2.8.0: 2134 Devices 1252 Events
Z-Wave 3.0.10.0: 133 Nodes on one Z-Net
Comment
-
Originally posted by sparkman View Postsocalsharky It is vb.net. Sometimes it's easy to tell based on functions, etc. that are not available in the other, but a lot of times it is not. If you need a vbs example, I should be able to provide that too as the original script I had was written in vbs and I converted it a few years ago to vb.net.
Comment
-
I would go straight to vb.net at this point. I converted all my scripts to vb.net a few years ago and most examples you'll see these days are vb.net. Let me know if you still want me to post the vbs version.
EDIT: I just checked my archives and the only vbscript version I have of this script was the one for HS2. I must have converted it to vb.net right away when I migrated from HS2 to HS3.HS 4.2.8.0: 2134 Devices 1252 Events
Z-Wave 3.0.10.0: 133 Nodes on one Z-Net
Comment
-
Originally posted by sparkman View PostI would go straight to vb.net at this point. I converted all my scripts to vb.net a few years ago and most examples you'll see these days are vb.net. Let me know if you still want me to post the vbs version.
EDIT: I just checked my archives and the only vbscript version I have of this script was the one for HS2. I must have converted it to vb.net right away when I migrated from HS2 to HS3.
Comment
-
Originally posted by socalsharky View Post
Thanks for checking sparkman. How did you post that scrollable window with your code? Very cool. Would you mind looking at what I have so far in vbs?HS 4.2.8.0: 2134 Devices 1252 Events
Z-Wave 3.0.10.0: 133 Nodes on one Z-Net
Comment
-
Originally posted by sparkman View Post
No problem. If you go into the Advanced Editor (A icon), then there are a lot more options and there's a button with a # sign on it which will create the tags for showing the code. Paste your code between the two tags and then it should show that way.
Code:Sub Main() Dim SolarNoon Dim Sunrise Dim Sunset Dim DayLength Dim SunAt153 Dim Offset SolarNoon=hs.Solarnoon Sunrise=hs.SunriseDt Sunset=hs.SunsetDt DayLength=(Sunset-Sunrise)*24 'DayLength in hours and Offset in seconds hs.writelog "msg","Length of Day is " & DayLength & " hrs" Offset=(4.764-0.3059*DayLength)*3600 hs.writelog "msg","Offset is " & Offset & " seconds" SunAt153=DateAdd("s", -Offset, SolarNoon) hs.writelog "msg","Sun is at AZ 153 at " & SunAt153 'hs.writelog "msg","Sun is at AZ 153 at " & FormatDateTime(SunAt153, vbLongTime) hs.writelog "msg","Solar Noon is at " & SolarNoon End Sub
Comment
-
Looks like you are using vbscript so far. One thing with vbscript is that it is very forgiving with allowing operations on variables that are different types. VB.NET is not forgiving at all, so declaring variables and converting them to other types is important. Below is the equivalent VB.NET version. I also like using a "Debug" variable that I set to True when debugging the script, and False when done debugging. That way I don't have to keep manually editing each writelog line to comment it out. I also like to use a variable for the log name entry so that I can change it one spot if I ever change it.
Code:Sub Main(ByVal Parms As object) Dim Debug As Boolean = True Dim LogName As String = "msg" Dim SolarNoon As Date = hs.Solarnoon Dim Sunrise As Date = hs.SunriseDt Dim Sunset As Date = hs.SunsetDt Dim DayLength As Double Dim SunAt153 As Date Dim Offset As Double If Debug Then hs.writelog(LogName,"Solar Noon is at " & SolarNoon) If Debug Then hs.writelog(LogName,"Sunrise is at " & Sunrise) If Debug Then hs.writelog(LogName,"Sunset is at " & Sunset) DayLength=DateDiff(DateInterval.Second,Sunrise,Sunset) 'DayLength in seconds and Offset in seconds If Debug Then hs.writelog(LogName,"Length of Day is " & DayLength & " seconds") Offset=4.764-0.3059*DayLength If Debug Then hs.writelog(LogName,"Offset is " & Offset & " seconds") SunAt153=DateAdd("s", -Offset, SolarNoon) If Debug Then hs.writelog(LogName,"Sun is at AZ 153 at " & CStr(SunAt153)) End Sub
HS 4.2.8.0: 2134 Devices 1252 Events
Z-Wave 3.0.10.0: 133 Nodes on one Z-Net
Comment
-
I didn't make any progress on fully implementing this script last year, and now with a lot of free time on my hands I want to get it up and running. With sparkman 's help I have a script that will calculate the time at which the sun is past the back face of my house on any given day. Now I am trying to figure out how to use an event to trigger the blinds to raise when the Current Time > Calculated Time. I was thinking of using a virtual device to track the calculated time, but how do I compare that to the current time of day? Easy Trigger has quite a few options, but I don't see any that will work for that case.
Comment
Comment