Announcement

Collapse
No announcement yet.

Help with IF Then .. AND .. Else Statement .. More then 2 conditions ???

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

    Help with IF Then .. AND .. Else Statement .. More then 2 conditions ???

    Can anyone tell me if there is any way that I can test more then two conditions in a single IF AND THEN Statement...

    Here's what I'm trying to do, I have Z-wave RF light switches that report their conditions back to HS, Im trying to have HS check the elapsed time of a light, allowing me to know when it has been on for a specified amount of time. I want HS to turn the light off if there is no motion in the room after that specified amount of time.

    What I've got so far that does work is, there is an Event that runs every 5 minutes that runs this script, what this script does now is:

    1. checks to see if 59 minutes have elapsed
    2. checks to see if the light is on or dim

    BathRmLight is a variable that is loaded by "hs.Devicetime("Q20")"
    BathRmLightStat is a variable that is loaded by hs.Devicestatus("Q20")

    Current IF THEN Statement below....

    If BathRmLight > 59 And BathRmLightStat <> 3 then
    hs.writelog "Timed Lights","Master Bathroom light has been on for " & BathRmLight & " minutes"
    hs.speak "Master Bathroom light has been on for " & BathRmLight & " minutes, Turning off in 15 seconds"
    hs.Waitsecs 15
    hs.ExecX10 "Q20", "off"
    end If

    What I would like to do, Is make the "IF AND THEN" statement be a IF AND AND THEN" statement, but it doesnt seam to work... I want to add a motion detector to the mix so that the light(s) will not turn off if someone is still in the room.... but when I try to put the Motion Dector in the mix it just doesn't seem to work out..

    Perposed, IF THEN Statement below....

    If BathRmLight > 59 AND BathRmMotion <> AND BathRmLightStat <> 3 then
    hs.writelog "Timed Lights","Master Bathroom light has been on for " & BathRmLight & " minutes"
    hs.speak "Master Bathroom light has been on for " & BathRmLight & " minutes, Turning off in 15 seconds"
    hs.Waitsecs 15
    hs.ExecX10 "Q20", "off"
    end If


    I'm not a programmer, I've only learned what I know from asking questions on here and trial and error. Please if someone can help me on what I'm trying to accomplish I greatly appreciate it....

    Thank You,

    Charles
    Last edited by definityone2002; December 13, 2009, 01:20 AM. Reason: Missed something

    #2
    If BathRmLight > 59 AND BathRmMotion <> AND BathRmLightStat <> 3 then
    It looks like your issue is a syntax error. Break each of these apart and you get:
    if
    BathRmLight > 59
    and
    BathRmMotion <>
    and
    BathRmLightStat <> 3
    then

    You're missing the comparison value after the <> for the 2nd term:
    BathRmMotion <> ???

    You can have many and operators in a single if-then. For example, the following code works fine:
    Code:
    a = 1
    b = 2
    c = 3
    d = 5
    if a>0 and b<10 and c=3 and d=5 then
     msgbox "Good"
    else
     msgbox "Bad"
    end if
    Sometimes I'll add parentheses around the comparisons to make them obvious. In your case:
    If (BathRmLight > 59) AND (BathRmMotion <> 1) AND (BathRmLightStat <> 3) then ...
    Best regards,
    -Mark-

    If you're not out on the edge, you're taking up too much room!
    Interested in 3D maps? Check out my company site: Solid Terrain Modeling

    Comment


      #3
      Got it ! It works great now Thanks

      Comment

      Working...
      X