Announcement

Collapse
No announcement yet.

Logical expression in light fade event

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

    Logical expression in light fade event

    Hi,

    I am trying to figure out how to create an event that will slowly change the value of a global light value (that all my devices change to) on a set schedule. I currently have something along the lines of (using EasyTrigger):
    Click image for larger version

Name:	Screen Shot 2019-05-08 at 9.58.38 AM.png
Views:	284
Size:	38.8 KB
ID:	1303520
    (one increments a global light level value, the other a global color temperature value, devices 433, color and 434, level are the global virtual devices if that wasn't clear)

    The issue is I think I am creating a bit of a loop in that there is not a way to arrive at 92 (for example) from, for example, 74 by adding 5 and thus the statement can never be true (or essentially, not require a change). I also realize that my above expression is missing what to do if the value does finally equal the specified value. Not sure the best way to handle the third scenario of the device value eventually equaling the target value. Finally, I am not addressing the need for whole-numbers, which I assume are needed.

    This is a long way of asking, how can I do the above better? In addition to a better way to construct the expression, is there also a better way to approach this that is less taxing on the system? I use the counter condition to control which event is "allowed" to run and the counter is changed via other scheduled events. Again, I am sure there is probably a better way!

    Thank you very much!

    #2
    Personally I would put that logic into a script as in it you have more options (i.e. if the value becomes above 92, then set it to 92).
    HS 4.2.8.0: 2134 Devices 1252 Events
    Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

    Comment


      #3
      Fair enough, I actually started w/ this script: https://forums.homeseer.com/forum/ho...hten-over-time

      But the above only is designed to go in one direction (from lower to higher). I spent a bit of time trying to re-code the script to basically work like my above routine, if higher than target, subtract, if lower, then add but my VB skills are non existent.

      That said, if I did get the script working, it seems like it would only work if incrementing +/-1 which I think is going to take too long and or over tax the system when making large color temperature changes, for example. Won't I still have the problem I have now, if I use anything other than 1 with this script, there will be times I can't hit the target value?

      Thank you!

      Comment


        #4
        Use the Min/Max functions to keep it at or below 92 and at or above 0.

        Code:
        min(max (If ($$DVR:432: > 92,  $$DVR:432: - 5, $$DVR:432: + 5), 92), 0)
        min(max (If ($$DVR:433: > 4400,  $$DVR:433: - 50, $$DVR:433: + 50), 6500), 2700)
        Once you get within 5 on the low side of 92, the event will move the light 1 more time to 92 and then simply keep it there because a a change of 5 would exceed the Min setting.


        --Barry

        Comment


          #5
          Thank you for your reply. I get what you are talking about but when I use what you wrote above, the device just jumps to the minimum value (0). I tried setting the Min/ Max to 92 to see if that would change anything but it just jumps to 92 right away. Do you think the issue is where the min/max is in the expression? Like, should it be part of the "then" section of the expression?

          To be clear, this is what I am currently using in the test:
          Code:
          Min(Max (if ($$DVR:434: > 92,  $$DVR:434: - 5, $$DVR:434: + 5), 92), 0)
          Thank you!

          Comment


            #6
            Originally posted by fx12002 View Post
            Fair enough, I actually started w/ this script: https://forums.homeseer.com/forum/ho...hten-over-time

            But the above only is designed to go in one direction (from lower to higher). I spent a bit of time trying to re-code the script to basically work like my above routine, if higher than target, subtract, if lower, then add but my VB skills are non existent.

            That said, if I did get the script working, it seems like it would only work if incrementing +/-1 which I think is going to take too long and or over tax the system when making large color temperature changes, for example. Won't I still have the problem I have now, if I use anything other than 1 with this script, there will be times I can't hit the target value?

            Thank you!
            Hey, that's my script

            It would be relatively easy to recode that to support up and down. You could pass a negative number for it to go down and then check if the number is negative and use the opposite logic. Let me know if you need help with that.
            HS 4.2.8.0: 2134 Devices 1252 Events
            Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

            Comment


              #7
              Thank you for the script! And yes, would love your help figuring out how to modify it because my VB syntax isn't good enough and every (trial and error) tweak I make towards getting the script to do what I am trying to do just breaks it ... any help is appreciated!

              Comment


                #8
                Originally posted by fx12002 View Post
                Do you think the issue is where the min/max is in the expression? Like, should it be part of the "then" section of the expression?

                To be clear, this is what I am currently using in the test:
                Code:
                Min(Max (if ($$DVR:434: > 92, $$DVR:434: - 5, $$DVR:434: + 5), 92), 0)
                Thank you!
                No, I think I have the syntax right... I even ran it through a regex validator to be sure. But you are right, it appears HS is getting confused about where the true/false statement lies in the expression. It may be the way HS parses expressions is different with global variables. Try these and see if either work or if they still jump to Min/Max:

                Code:
                Min(Max (if (($$DVR:434: > 92, $$DVR:434: - 5, $$DVR:434: + 5), 92), 0)
                Min(Max (if (($$DVR:434: > 92, $$DVR:434: - 5, $$DVR:434: + 5)), 92), 0)
                --Barry

                Comment


                  #9
                  Thank you! Ok, so when I run your top expression, I get:
                  EasyTrigger ERROR missing ')' at ',' at line 1:20

                  When I run the bottom expression, I get:
                  EasyTrigger ERROR missing ')' at ',' at line 1:20 missing EOF at ',' at line 1:41

                  Maybe this is an issue with EasyTrigger? Not sure where to try adding the suggested paren or comma.

                  Comment


                    #10
                    Originally posted by fx12002 View Post
                    Thank you for the script! And yes, would love your help figuring out how to modify it because my VB syntax isn't good enough and every (trial and error) tweak I make towards getting the script to do what I am trying to do just breaks it ... any help is appreciated!
                    The script is based on setting a maximum brightness with steps based on seconds. Would you want a target brightness, the step (negative or positive) and the number of seconds at each step as your input parameters?
                    HS 4.2.8.0: 2134 Devices 1252 Events
                    Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                    Comment


                      #11
                      In my case, there is really only one variable that changes - the target brightness (or color temperature, I change both). I was hoping to have script that would determine if it needs to count up or down to hit the target number (for instance, night into day may be going from a low to a high target but day into night could be going from a high to a lower number. It would be nice if I could reuse the same event for both instances, only changing the target value as there are around 25 changes (events) throughout the day

                      Not sure if this is a factor at all but in my case, the device I am changing is a virtual device that around 70 different bulbs and switches reference. So, if everyone is home, there could be quite a few devices changing every single time this global value changes. Thus, I thought I would make the steps a bit larger and less frequent because I don't want to flood the system with constant changes. I also could be misunderstanding how HS handles this type of thing and its not worth worrying about.

                      Currently, I just change the value at a specific time and any device that was on will jump to the new value, so even with a larger step size it will be a nicer transition than what I currently have.

                      Thank you!

                      Comment


                        #12
                        Originally posted by sparkman View Post

                        Hey, that's my script

                        It would be relatively easy to recode that to support up and down. You could pass a negative number for it to go down and then check if the number is negative and use the opposite logic. Let me know if you need help with that.
                        Al as always your scripts comes in handy for a number of situations per chance did you every update your script to reflect the latest? Mike
                        Computer: CUK Intel NUC7i7BNH
                        Op System: Windows10 Pro - Work Station
                        HS Version: HS4 Pro Edition 4.2.19.0

                        Plug-Ins: AK Weather 4.0.5.25,APCUPSD 3.3.2.3,BLBackup 2.0.63.0,BLEditor 2.0.11.0,BLGData 3.0.55.0,BLOccupied 2.0.28.0,BLShutdown 1.0.6.0,Blue-Iris 3.1.3.33206,Device History 3.2.0.2,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,iRobot 5.22.41.1,JowiHue 4.0.8.7,Nest 3.0.0.34,NetCam Plugin 1.0.0.5,PHLocation2 3.0.0.64,Pushover 4.0.10.0,Random 3.0.0.2,Restart 1.0.0.7,Ring 1.0.0.9,SDJ-Health 3.1.1.3,Sonos 3.1.0.59,Sonos4 4.0.1.12,UltraCID3 3.0.6681.34300,UltraMon3 3.0.6554.33094,UltraNetCam3 3.0.6413.20219,Unifi 4.0.32.0,Zigbee 4.0.11.0,Z-Wave 4.0.3.0, and Jon00 scripts.

                        Comment


                          #13
                          fx12002 The modified script is below. I've set it up to take 4 parameters in order to be more versatile. The 4 parameters are the reference id of the target device, the target level, the time in seconds between each step, and the amount to change by per step. If it does not work as expected, please change the line "Dim Debug As Boolean = False" to "Dim Debug As Boolean = True" and it will provide more info in the log as to what is going on.

                          Click image for larger version

Name:	Capture.PNG
Views:	254
Size:	129.1 KB
ID:	1303657

                          Code:
                          Sub Main(ByVal Parms As String)
                          
                              Dim ParmArray() As String
                              ParmArray = Parms.ToString.Split(",")
                              Dim targetDev As Integer = CInt(ParmArray(0))        'reference ID of the device for which to change level
                              Dim targetDim As Integer = CInt(ParmArray(1))        'target level
                              Dim rampRate As Integer = CInt(ParmArray(2))        'ramprate in seconds
                              Dim dimStep As Integer = CInt(ParmArray(3))            'step between dim levels
                          
                              Dim Debug As Boolean = False
                              Dim logName As String = "Change Level Script"        'set log type for HS log
                              Dim devValue,newdevValue As Integer
                              Dim i As Integer = 0
                              Dim ExitLoopEarly As Boolean = False
                          
                              devValue = hs.DeviceValue(targetDev)
                              If targetDim < devValue Then dimStep = 0 - dimStep
                          
                              If Debug Then hs.writelog(logName,"Current:" & CStr(devValue) & " Target:" & CStr(targetDim))
                              If targetDim <> devValue Then
                                  For i = devValue + dimStep To targetDim Step dimStep
                                      If Debug Then hs.writelog(logName,CStr(i))
                                      hs.CAPIControlHandler(hs.CAPIGetSingleControl(targetDev, false, CStr(i), false, true))
                                      hs.WaitEvents()
                                      hs.WaitSecs(rampRate)
                                      newdevValue = hs.DeviceValue(targetDev)
                                      If newdevValue = targetDim Then                'if dim value is changed on switch, stop script to stay at that dim level
                                          If Debug Then hs.writelog(logName,"Exited - Dim Level at target")
                                      ElseIf newdevValue = 0 Then                        'if switch is turned off, stop script
                                          If Debug Then hs.writelog(logName,"Exited - Switch Turned Off")
                                          ExitLoopEarly = True
                                      ElseIf newdevValue <> i Then                'if dim value is changed on switch, stop script to stay at that dim level
                                          If Debug Then hs.writelog(logName,"Exited - Dim Level changed at switch")
                                          ExitLoopEarly = True
                                      ElseIf newdevValue >= targetDim And dimStep > 0 Then        'if dim level at switch exceeds target, stop script to stay at that dim level
                                          If Debug Then hs.writelog(logName,"Exited - Value Exceeds Target")
                                          ExitLoopEarly = True
                                      ElseIf newdevValue <= targetDim And dimStep < 0 Then        'if dim level at switch exceeds target, stop script to stay at that dim level
                                          If Debug Then hs.writelog(logName,"Exited - Value Below Target")
                                          ExitLoopEarly = True
                                      End If
                                      If ExitLoopEarly = True Then Exit For
                                  Next
                                  If newdevValue <> targetDim And Not ExitLoopEarly Then 
                                      hs.CAPIControlHandler(hs.CAPIGetSingleControl(targetDev, false, CStr(targetDim), false, true))
                                      If Debug Then hs.writelog(logName,CStr(targetDim))
                                      If Debug Then hs.writelog(logName,"Dim Level at target")
                                  End If
                              Else
                                      If Debug Then hs.writelog(logName,"Dim Level already at target")
                              End If
                          
                          End Sub
                          HS 4.2.8.0: 2134 Devices 1252 Events
                          Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                          Comment


                            #14
                            Originally posted by MNB View Post

                            Al as always your scripts comes in handy for a number of situations per chance did you every update your script to reflect the latest? Mike
                            Thanks Mike, when you say "latest", what are you referring to?

                            Cheers
                            Al
                            HS 4.2.8.0: 2134 Devices 1252 Events
                            Z-Wave 3.0.10.0: 133 Nodes on one Z-Net

                            Comment


                              #15
                              Originally posted by sparkman View Post
                              fx12002 The modified script is below. I've set it up to take 4 parameters in order to be more versatile.
                              BOOM! I swear Sparkman, if I had your scripting abilities I'd probably never leave my computer. I'd be scripting everything and giggling like a girl. I'm always amazed at how quick you can bang something out. Nice work!

                              --Barry

                              Comment

                              Working...
                              X