Announcement

Collapse
No announcement yet.

Advice on best approach for complex action

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

  • Advice on best approach for complex action

    Hi

    Still trying to get my head around events and scripts. Although this is the scripting section my question is regarding both but I figured that the scripters would know the best way to do what I want

    I want to trigger a lamp to gradually come on over an hour before sunset. I have considered two options to do this.

    1)
    I have created an event group with four events. The first one checks the time and sets a counter from 0 to 1 when it's time to start the light coming on. Then there is a second event that runs once a minute (only when the counter is 1) that fires an event that runs a script to increase the lamp brightness. Lastly there is an event that checks the lamp brightness and once reached max sets the counter back to 0. This works fine but is a bit clunky

    2)
    I believe this approach to be simpler yet more versatile. I have just one event that runs when the time is right to start the lamp coming on. This event then runs a script. The script is essentially a for next loop that increases the brightness by 1 on each loop. I would then put a waitsecs in there to wait a minute before moving on in the loop.

    What are your thoughts advice etc?

  • #2
    I don't know if this will do what you want, and may be overly complex but could you not have delayed event actions that increase the brightness my 10% every x minutes.

    For example, if time is nighttime then:

    Set Light to 10%
    after 5 minutes set light to 20%
    after 10 minutes set light to 30%
    after 15 minutes set light to 40%
    after 20 minutes set light to 50%
    HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

    Facebook | Twitter | Flickr | Google+ | Website | YouTube

    Comment


    • #3
      Hi thanks for the reply.

      I have considered your suggestion but I want to increase the value by 1 every minute which means creating 99 events for nth morning and evening. This then becomes a pain if I decide I want to change it to increasing by 1 every 30 seconds.

      I'm pretty sure the script route is the way to do it I just don't know if having a few long running scripts eg taking an hour, will cause a performance issue.

      Comment


      • #4
        You could still increase by one every minute by having delayed actions, it would not mean having 99 events, but one event with 99 actions which may be overkill, Scripting sounds like the best way to do it.
        HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

        Facebook | Twitter | Flickr | Google+ | Website | YouTube

        Comment


        • #5
          Sorry I meant 99 actions not events.

          I've now written a script that does what I want with a lot of extra flexibility so I think I'll stick with that

          Comment


          • #6
            I would get a luminosity sensor (HSM-100 I think) and have a recurring event that checks luminosity and sets dim level based on luminosity (assuming of course you want to make the light brighter as it gets darker outside). If it's something else, it would help if you told us
            ________________________

            Dell Zino HD - HSPRo 2.x
            HSTouch - iPhone 3GS, 4S, iPad2 and iPad 3, 3xKindle Fire (Wall mounted)
            2 x Brultech ECM1240 with UltraECM
            USB UIRT
            Cooper Aspire Z-Wave Switches
            WGL800 w ACRF2 and 3xDS10a (Sump Level/Activity sensing)
            HM ST812-2 Flood Sensor
            HSM100 - Motion Detector with Light and Temperature
            2GIG Thermostat
            BLDSC - Alarm Plug-in
            BLUPS
            UltraLog (SQL2008)
            Jon00 Plugins
            Host XR3 BT and Jon00 BT Proximity
            Global Cache IP2IR
            Foscam FI8918W

            Comment


            • #7
              Ooh there's an idea! That would be even better! Yes that Is exactly what I want to do Thanks

              Comment


              • #8
                There was an HSM-100 in for sale forum
                ________________________

                Dell Zino HD - HSPRo 2.x
                HSTouch - iPhone 3GS, 4S, iPad2 and iPad 3, 3xKindle Fire (Wall mounted)
                2 x Brultech ECM1240 with UltraECM
                USB UIRT
                Cooper Aspire Z-Wave Switches
                WGL800 w ACRF2 and 3xDS10a (Sump Level/Activity sensing)
                HM ST812-2 Flood Sensor
                HSM100 - Motion Detector with Light and Temperature
                2GIG Thermostat
                BLDSC - Alarm Plug-in
                BLUPS
                UltraLog (SQL2008)
                Jon00 Plugins
                Host XR3 BT and Jon00 BT Proximity
                Global Cache IP2IR
                Foscam FI8918W

                Comment


                • #9
                  You don't say what lighting protocol you're using but I do this exact thing using UPB. I have my living room lamp set to ramp up over an hour after being triggered 30 minutes before sunset. It's worked really well.
                  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


                  • #10
                    Hi AquaCom,
                    Is there any chance of posting the script, I would like to see how you ramp the lighting and I have no idea how to do it with a script in HS3. Thanks in advance.
                    Peter

                    Comment


                    • #11
                      Originally posted by nightwalker View Post
                      You don't say what lighting protocol you're using but I do this exact thing using UPB. I have my living room lamp set to ramp up over an hour after being triggered 30 minutes before sunset. It's worked really well.
                      I'm using zwave. I don't think you can set the ramp rate with zwave.

                      Comment


                      • #12
                        Originally posted by Pervez2602 View Post
                        Hi AquaCom,
                        Is there any chance of posting the script, I would like to see how you ramp the lighting and I have no idea how to do it with a script in HS3. Thanks in advance.
                        Peter
                        Sure. I'm going to try and tidy it a bit tomorrow so I'll send it on after that

                        Comment


                        • #13
                          Originally posted by AquaCom View Post
                          I'm using zwave. I don't think you can set the ramp rate with zwave.
                          Not dynamically. It's a device configuration parameter, but cannot be set by a script/event. Myself and others have requested it
                          ________________________

                          Dell Zino HD - HSPRo 2.x
                          HSTouch - iPhone 3GS, 4S, iPad2 and iPad 3, 3xKindle Fire (Wall mounted)
                          2 x Brultech ECM1240 with UltraECM
                          USB UIRT
                          Cooper Aspire Z-Wave Switches
                          WGL800 w ACRF2 and 3xDS10a (Sump Level/Activity sensing)
                          HM ST812-2 Flood Sensor
                          HSM100 - Motion Detector with Light and Temperature
                          2GIG Thermostat
                          BLDSC - Alarm Plug-in
                          BLUPS
                          UltraLog (SQL2008)
                          Jon00 Plugins
                          Host XR3 BT and Jon00 BT Proximity
                          Global Cache IP2IR
                          Foscam FI8918W

                          Comment


                          • #14
                            Originally posted by AquaCom View Post
                            I'm using zwave. I don't think you can set the ramp rate with zwave.
                            I don't think you can either, it's something that's built into upstart and the switches you can trigger when you want the slow ramp up or down.
                            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


                            • #15
                              Originally posted by Pervez2602 View Post
                              Hi AquaCom,
                              Is there any chance of posting the script, I would like to see how you ramp the lighting and I have no idea how to do it with a script in HS3. Thanks in advance.
                              Peter
                              As requested here is a copy of my script. Credit due to the poster who posted about the capi



                              ' sub SlowDimmerChange(Params) - Changes the devices dim level over period of time - Params should be (RefID, Direction (1 = increase -1 = decrease), Change Interval in seconds, Start Value, Stop Value)

                              'sub ControlDevice(params) - Controls devices - Params should be (RefID, Command, DimValue) - (commands are "on", "off", "toggle", "dim")


                              Sub SlowDimmerChange(byval params as string)
                              Dim StrValues = Params.split(",")
                              Dim IntDevRef as integer = cint(strValues(0))
                              Dim intStep as integer = cint(strValues(1))
                              Dim IntWaitInterval as integer = cint(strValues(2))
                              Dim IntStartValue as integer = cint(strValues(3))
                              Dim IntStopValue as integer = cint(strValues(4))
                              Dim intDimValue as integer

                              For IntDimValue = IntStartValue to IntStopValue step IntStep
                              hs.writelog("Scripting - Zwave.vb", "SlowDimmerChange - " & intDimValue & ", " & IntStartValue & ", " & intStopValue & ", " & intStep)
                              ControlDevice(IntDevRef & ",dim," & intDimValue)
                              Hs.waitsecs(IntWaitInterval)
                              Next

                              End sub

                              sub ControlDevice(byval params as string)
                              Dim aryText() As String
                              Dim intDevRef As Integer
                              Dim strDevCmd As String
                              Dim intDimValue As Integer

                              aryText = params.Split( "," )
                              intDevRef = cint(aryText(0))
                              strDevCmd = ltrim(rtrim(aryText(1)))
                              intDimValue = cint(aryText(2))

                              'if intDimValue < 0 then intDimValue = 0
                              'if intDimValue > 99 then intDimValue = 99

                              if strDevCmd = "toggle" then
                              if IsOnCAPI(intDevRef) then
                              strDevCmd = "off"
                              else
                              strDevCmd = "on"
                              end if
                              end if

                              If intDimValue <= 0 then strDevCmd = "off"
                              If intDimValue >= 99 then strDevCmd = "on"

                              if strDevCmd = "dim" then
                              hs.writelog("Scripting - Zwave.vb", "ControlDevice - Dim " & DimCAPI(intDevRef, intDimValue))
                              else
                              hs.writelog("Scripting - Zwave.vb", "ControlDevice - " & strDevCmd & " " & CallCAPI(intDevRef, strDevCmd))
                              end if
                              end sub



                              Function CallCAPI(ByVal intDevRef As Integer, ByVal strDevCmd As String) As CAPIControlResponse
                              hs.writelog("Scripting - Zwave.vb", "CallCAPI - " & intDevRef & " - " & strDevCmd)
                              CallCAPI = CAPIControlResponse.Indeterminate
                              For Each objCAPIControl As CAPIControl In hs.CAPIGetControl(intDevRef)
                              If LCase(objCAPIControl.Label) = LCase(strDevCmd) Then
                              CallCAPI = hs.CAPIControlHandler(objCAPIControl)
                              Exit For
                              End If
                              Next
                              End Function

                              Function DimCAPI(ByVal intDevRef As Integer, ByVal intDimValue As Integer, optional ByVal intOffSetMax As Integer = 5) As CAPIControlResponse
                              Dim blnMatch As Boolean
                              Dim intOffset As Integer
                              Dim intStartPos As Integer
                              Dim strDimVal As String
                              Dim intDimVal As Integer

                              DimCAPI = CAPIControlResponse.Indeterminate
                              blnMatch = False
                              intOffSet = 0
                              While True
                              For Each objCAPIControl As CAPIControl In hs.CAPIGetControl(intDevRef)
                              If Len(objCAPIControl.Label) > 5 Then
                              If LCase(Left(objCAPIControl.Label, 4)) = "dim " Then
                              intStartPos = InStr(4, objCAPIControl.Label, "%")
                              If intStartPos > 5 Then
                              strDimVal = Mid(objCAPIControl.Label, 5, intStartPos - 5)
                              If IsNumeric(strDimVal) Then
                              intDimVal = CInt(strDimVal)
                              If ((intDimVal - intOffSet) = intDimValue) Or ((intDimVal + intOffSet) = intDimValue) Then
                              DimCAPI = hs.CAPIControlHandler(objCAPIControl)
                              blnMatch = True
                              Exit For
                              End If
                              End If
                              End If
                              End If
                              End If
                              Next
                              If blnMatch Then Exit While
                              intOffSet = intOffSet + 1
                              If intOffSet > intOffSetMax Then Exit While
                              End While
                              End Function



                              Sub DescribeDevice(ByVal strDevRef As string)
                              hs.WriteLog("DevInfo","DescribeDevice" & strDevRef)

                              Dim objDev As Object
                              Dim intDevRef as Integer
                              Dim intCount As Integer

                              intDevRef = CInt(strDevRef)
                              objDev = hs.GetDevicebyRef(intDevRef)
                              If objDev Is Nothing Then
                              hs.WriteLog("DevInfo","Invalid device ref: " & strDevRef)
                              Else
                              hs.WriteLog("DevInfo", "Ref=" & strDevRef & " Name=" & objDev.Name(hs) & " Location=" & objDev.Location(hs) & " Location2=" & objDev.Location2(hs) & " Address=" & objDev.Address(hs))

                              intCount = 0

                              For Each objCAPIControl As CAPIControl In hs.CAPIGetControl(intDevRef)
                              hs.WriteLog("DevInfo", ".CCIndex=" & CStr(objCAPIControl.CCIndex) & " Label=" & Cstr(objCAPIControl.Label) & " ControlType=" & CStr(objCAPIControl.ControlType) & " ControlValue=" & CStr(objCAPIControl.ControlValue) & " ControlString=" & objCAPIControl.ControlString)

                              intCount = intCount + 1
                              Next

                              If intCount = 0 Then hs.WriteLog("DevInfo", "No CAPIControl objects defined for this device")
                              hs.WriteLog("DevInfo", "IsOn=" & IsOnCAPI(intDevRef) & " IsOff=" & IsOffCAPI(intDevRef))


                              End If
                              end sub

                              Function IsOnCAPI(ByVal intDevRef As Integer) As Boolean
                              Dim intValue = hs.DeviceValueEx(intDevRef)

                              IsOnCAPI = False
                              For Each objCAPIControl As CAPIControl In hs.CAPIGetControl(intDevRef)
                              If intValue = objCAPIControl.ControlValue Then
                              If LCase(objCAPIControl.Label) = "on" Then
                              IsOnCAPI = True
                              End If
                              Exit For
                              End If
                              Next
                              End Function

                              Function IsOffCAPI(ByVal intDevRef As Integer) As Boolean
                              Dim intValue = hs.DeviceValueEx(intDevRef)

                              IsOffCAPI = False
                              For Each objCAPIControl As CAPIControl In hs.CAPIGetControl(intDevRef)
                              If intValue = objCAPIControl.ControlValue Then
                              If LCase(objCAPIControl.Label) = "off" Then
                              IsOffCAPI = True
                              End If
                              Exit For
                              End If
                              Next
                              End Function

                              Comment

                              Working...
                              X