Announcement

Collapse
No announcement yet.

Am I biting off too much

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

    Am I biting off too much

    I've never written a script, but I want to write my first one for my HS setup. Basically, using a virtual device, I want to store the rain accumulation for the last four days and come up with some kind of variable that will be the answer as to whether to turn on my sprinklers or not.

    I found tenscripting, but I assume I need something like VB from microsoft. Or have I bitten off more than I can chew.

    #2
    I think that sounds like a great learning project. If you are using TenScripting, then I assume you have a version of Visual Studio installed. If so, that provides the vb scripting environment. It's not absolutely necessary, but makes the learning a bit easier. (You can actually do all the coding in something as simple as Notepad.) HS has all the necessary capability to execute your code. (I also recommend TenScriptAid. It's an excellent tool for helping use devices in your scripts.)

    Depending on your preferences, a good basic book on vb.net or a web based tutorial is the place to start. A web search for "vb.net introduction" will get you lots of links to basic examples and tutorials. You can also find some good example scripts on the HS Board.
    Mike____________________________________________________________ __________________
    HS3 Pro Edition 3.0.0.548, NUC i3

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

    Comment


      #3
      I use WeatherXml, EasyTrigger and a couple of events to perform a similar task. I also have a small scrappy script to grab forecast rain for today and tomorrow from the WeatherUnderground API. That should go away soon when Jeff adds this to WeatherXml.

      I have virtual devices for:
      Today's forecast rain
      Tomorrow's forecast rain
      Yesterday's rain
      2, 3, 4, 5 and 6 day's ago
      4 day total
      7 day total

      When today's actual rain changes I use the simple calc function in Easytrigger to re-sum the last 4 and last 7 days totals and store those in their respective virtual devices.

      At 23:59 I have an event that moves the historic totals one day further back (using EasyTrigger again) and then re-calcs the last 4 & 7 day totals

      Just after midnight I run an event that checks whether 4 day total or (what is now yesterday's rain) or the forecast rain are above certain levels and use that to set a rain delay on my OpenSprinkler controller.
      cheeryfool

      Comment


        #4
        Originally posted by cheeryfool View Post
        2, 3, 4, 5 and 6 day's ago

        When today's actual rain changes I use the simple calc function in Easytrigger to re-sum the last 4 and last 7 days totals and store those in their respective virtual devices.

        At 23:59 I have an event that moves the historic totals one day further back (using EasyTrigger again) and then re-calcs the last 4 & 7 day totals

        Just after midnight I run an event that checks whether 4 day total or (what is now yesterday's rain) or the forecast rain are above certain levels and use that to set a rain delay on my OpenSprinkler controller.
        If I am reading this correctly, you are not storing totals added up for all the days in the 2,3,4,5 and 6 days. You are storing the amount of rain for that day only. Is that correct?

        See this thread for the plans for rain totals
        https://forums.homeseer.com/showthread.php?p=1322869

        I am hoping that we can all work together to come up with a great way to use the data to help control a sprinkler system. I purchased one of the GoControl units earlier this year.
        --
        Jeff Farmer
        HS 3, HSPhone
        My HS3 Plugins: CFHSExtras, Random, Restart, Tracker, WeatherXML, PanaBluRay
        Other Plugins In Use: APCUPSD, BLOnkyo, Device History, EasyTrigger, HSTouch Server, PHLocation2, Pushover, RFXCom, UltraGCIR3, UltraMon3, UltraPioneerAVR3, X10, Z-Wave

        Hardware: GoControl Irrigation Controler, Schlage Lever Lock, Schlage Deadbolt, Way2Call Hi-Phone, RFXCom RFXrec433 Receiver, WGL 800, TI-103, Z-Net, Pioneer 1120, Pioneer 1021, Pioneer LX302, Panasonic BDT-110, Panasonic BDT-210 x2

        Comment


          #5
          Originally posted by CFGuy View Post
          If I am reading this correctly, you are not storing totals added up for all the days in the 2,3,4,5 and 6 days. You are storing the amount of rain for that day only. Is that correct?

          See this thread for the plans for rain totals
          https://forums.homeseer.com/showthread.php?p=1322869

          I am hoping that we can all work together to come up with a great way to use the data to help control a sprinkler system. I purchased one of the GoControl units earlier this year.
          Jeff, yes correct. I am storing Yesterday to 6 days ago as static individual day amounts in their own virtual devices. Separately I have 4 and 7 day cumulative totals which include today's actual rain (the native WeatherXml device) and recalc every time today's rain updates and at midnight after I've shifted the individual day devices one day further back.

          I am not currently using the 7 day total in my decision, but am using the 4 day cumulative total, yesterday's rain, today and tomorrow's forecast amounts to decide whether to skip sprinkling for the day.
          cheeryfool

          Comment


            #6
            Thanks all for the info. One more quick question (there's always one more question) Is there a version of Visual Studio that's preferred over others or should I just install the latest? I remember thinking about stuff like this years ago and there were so many versions of VB, C++ and others.

            I actually programmed quite a bit back in the days of Pascal and WatV, but things sure have changed.

            I am hoping that we can all work together to come up with a great way to use the data to help control a sprinkler system. I purchased one of the GoControl units earlier this year.
            Yup, I have the same one but the rain sensor from my old system makes the Go Control think it's rained and the sprinklers never come on. Hence my desire to see rain totals.

            Personally, I'm not interested in forecasts although I can see where knowing tomorrow will be a deluge might help determine how much water to apply today.

            Comment


              #7
              Originally posted by racerfern View Post
              Thanks all for the info. One more quick question (there's always one more question) Is there a version of Visual Studio that's preferred over others or should I just install the latest? I remember thinking about stuff like this years ago and there were so many versions of VB, C++ and others.

              I actually programmed quite a bit back in the days of Pascal and WatV, but things sure have changed.



              Yup, I have the same one but the rain sensor from my old system makes the Go Control think it's rained and the sprinklers never come on. Hence my desire to see rain totals.

              Personally, I'm not interested in forecasts although I can see where knowing tomorrow will be a deluge might help determine how much water to apply today.
              You need nothing more complex than notepad for scripting (in fact you can do it entirely inside the HS event engine if you wanted) so don't need to worry about Visual Studio. If you wanted a semi useful text editor for scripts you could use something like Visual Studio Code or NotePad++

              Comment


                #8
                You need nothing more complex than notepad for scripting (in fact you can do it entirely inside the HS event engine if you wanted) so don't need to worry about Visual Studio. If you wanted a semi useful text editor for scripts you could use something like Visual Studio Code or NotePad++
                Thanks, I use FOXE for text/XML editing but I'll give NotePad++ a try if FOXE doesn't play nice with script files. I'll stay away from Visual Studio for now. KISS!

                Comment


                  #9
                  As a reference point, below is a simple vb script that gets two values (L1 Watts and L2 Watts) and adds them together. It then saves the new value (Total Watts) in a virtual device. A similar script can be used for adding daily rainfall for 4 or 7 days. Also a flat file could be used to store daily rain if needed.

                  Bob

                  Code:
                  '***************************************************************************
                  '*                      Update Total Watts Value                           *
                  '* This Script will be run by an Event which runs every minute and updates *
                  '* a virtual device with the total watts being used at the time of the     *
                  '* execution of the script. This value will be used to announce the value  *
                  '* on the hourly chime.                                                    *
                  '***************************************************************************
                  
                  
                  Imports System.IO
                  Imports System.Text
                  
                  Sub Main(parm as object)
                     Dim watts1 as Double = 0
                     Dim watts2 as Double = 0
                     Dim total_watts as Double = 0
                     DIM Accumulated_watts as Double
                     Dim SToday as Date = DateTime.Today 
                     Dim STime as String = DateTime.Now.ToString("HH:mm:ss")
                     Dim write_string as String = ""
                     Dim device_ref as Integer
                     Dim device_ref1 as Integer 
                     DIM device_ref2 as Integer
                     Dim FILE_NAME As String = "C:\Program Files (x86)\HomeSeer HS3\Data\Hourly_Watts.csv"
                  
                  '***************************************************************************
                  '*                 Get Device Reference Number                             *
                  '*                                                                         *
                  '*     Note: You must change the Name String to Match Your Device          *
                  '*           There is no error processing on this command                  *
                  '***************************************************************************
                  
                    device_ref = hs.GetDeviceRefByName("1st Floor Power Total Watts")
                    device_ref1 = hs.GetDeviceRefByName("1st Floor Power Watts 1")
                    device_ref2 = hs.GetDeviceRefByName("1st Floor Power Watts 2")
                  
                  '***************************************************************************
                  '*                    Get Current Device Value                             *
                  '*                                                                         *
                  '*     Get Today's Date and create a string to write to the Log and File   *
                  '*                                                                         *
                  '***************************************************************************
                     
                     Try
                        watts1 = hs.DeviceValue(device_ref1)
                        watts2 = hs.DeviceValue(device_ref2)
                        total_watts = (watts1 + watts2)
                        write_string = SToday & " " & STime & ";" & CStr(total_watts) & ControlChars.CrLf
                  '     hs.WriteLog("Total Watts",write_string)
                       
                     Catch ex as Exception
                        hs.WriteLog("Total Watts",ex.Message)
                     End Try   
                         
                        hs.SetDeviceValueByRef(device_ref, total_watts, True)
                  
                  End Sub

                  Comment


                    #10
                    I'd still recommend taking Spud's EasyTrigger plugin for the free trial. You may decide that scripting is for you , but there's a wealth of features in there (that arguably should be part of the core HS3 product). It does support exactly the type of device summing and devicevalue setting that I described earlier and Bob is showing in this example. It also handles schedules and much more.
                    cheeryfool

                    Comment


                      #11
                      Originally posted by racerfern View Post
                      I'll stay away from Visual Studio for now. KISS!
                      If you want to use TenScripting you need VS because TenScripting is a VS project. I've been using VS Express 2013 and it works without issue. The most helpful part of using VS and TenScripting is that you get auto complete for commands and on-the-fly syntax checking. Adding TenScriptAid also gives access to HS device properties and sample code to add device control to your scripts.
                      Mike____________________________________________________________ __________________
                      HS3 Pro Edition 3.0.0.548, NUC i3

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

                      Comment


                        #12
                        @cheeryfool You've done what I plan on doing. I've installed easytrigger and will stumble through it. You're right, I might not need tenscripting with VS.

                        I already have an event that looks at the day of the week, time of day, week of the year and turns on the sprinklers for a period of time. It works fine except of course I don't need them to come on when it has rained. I could probably use them to come on a bit more if it hasn't rained for days and days.

                        I see that I need an event to determine yesterday's rain and put it in a variable to save for future use. I'll need to do that for about four days and I see myself taking the average of the four days to determine how long to water for.

                        I'm using WeatherXML and Jon00 Cumulus plug-in at this time. Jon00Cumulus has yesterday's rain fall but I don't understand how to store that value. I'm trying Easytrigger: Set device to Variable, but it wants a number input rather than allow me to pick where the value comes from.

                        What am I missing?

                        I suppose I should start a new thread in the EasyTrigger plug-in section after this posting.

                        Comment


                          #13
                          Originally posted by racerfern View Post
                          @cheeryfool You've done what I plan on doing. I've installed easytrigger and will stumble through it. You're right, I might not need tenscripting with VS.

                          I already have an event that looks at the day of the week, time of day, week of the year and turns on the sprinklers for a period of time. It works fine except of course I don't need them to come on when it has rained. I could probably use them to come on a bit more if it hasn't rained for days and days.

                          I see that I need an event to determine yesterday's rain and put it in a variable to save for future use. I'll need to do that for about four days and I see myself taking the average of the four days to determine how long to water for.

                          I'm using WeatherXML and Jon00 Cumulus plug-in at this time. Jon00Cumulus has yesterday's rain fall but I don't understand how to store that value. I'm trying Easytrigger: Set device to Variable, but it wants a number input rather than allow me to pick where the value comes from.

                          What am I missing?

                          I suppose I should start a new thread in the EasyTrigger plug-in section after this posting.
                          For the data, I would try a WeatherUnderground Personal Weather Station (PWS) that's close enough to you and use that as one of your locations in WeatherXML. For me, there's a PWS about 1/2 mile away.

                          This should give you the total of today's rain, in a WeatherXML device, which you can then copy to a Virtual Device (not a global variable) at midnight to become "Yesterday's Rain".

                          I have virtual devices for:
                          Yesterday's Rain (Day total)
                          2 Days ago Rain (Day total)
                          3 Days ago Rain (Day total)
                          4 Days ago Rain (Day total)
                          4 Days Rain (Cumulative)

                          In my event (at midnight) I copy the 3 Day value to the 4 day ago value
                          2 days ago to 3 days ago
                          Yesterday to 2 days ago
                          Today to Yesterday etc

                          Then recalc the 4 day Cumulative and store that.

                          The EasyTrigger event action to do this is:

                          EasyTrigger: Set Device to Another Device
                          Set Rain 4 Days ago to Rain 3 Days ago
                          Wait 2seconds
                          Set Rain 3 Days ago to Rain 2 Days ago

                          etc etc

                          I do these sequentially in a single event, with a 2 second wait between updating values, which is probably not necessary, but works for me.

                          To set the Cumulative 4 day virtual device I use the EasyTrigger Set Device to Expression Action

                          As an example, if your PWS rain today device reference is 101 and your 3 previous days are 102, 103 and 104 and your 4 day total is 105, then I use the change in Rain Today to trigger updating the 4 day total as follows:

                          IF Rain Today [device 101] just had its value set or changed
                          THEN Easy Trigger:Set Device to Expression
                          Set Rain Last 4 days [device 105] to $$DVR:101: + $$DVR:102: + $$DVR:103: + $$DVR:104:


                          If that's not clear, I will try and post some screenshots later.

                          Cheers
                          James
                          cheeryfool

                          Comment


                            #14
                            @cheeryfool

                            Yes, I have weather stations all around me. I even have an ambient weather station myself that I registered but it is not reliable so I took it off line.

                            Am I correct in that you create the virtual devices by selecting the items you want in the HS Touch devices tab? I don't see any other place.

                            I'm ok with a slightly steep learning curve, it helps keep the mind sharp. But thanks for the code to add the four days together, that surely would have stumped me.

                            I'll report back at the next roadblock.

                            Comment


                              #15
                              Originally posted by racerfern View Post
                              @cheeryfool

                              Yes, I have weather stations all around me. I even have an ambient weather station myself that I registered but it is not reliable so I took it off line.

                              Am I correct in that you create the virtual devices by selecting the items you want in the HS Touch devices tab? I don't see any other place.

                              I'm ok with a slightly steep learning curve, it helps keep the mind sharp. But thanks for the code to add the four days together, that surely would have stumped me.

                              I'll report back at the next roadblock.
                              No, these are standard HS3 virtual devices that you create manually by hitting the white/green cross on the top right corner of the Device Management page. See Randy's tutorial here on how to create virtual devices:

                              https://forums.homeseer.com/showthread.php?t=181973
                              cheeryfool

                              Comment

                              Working...
                              X