Using Boolean variable{Solved}


#1

Hi all,
Brand new to webcore so i’m sure I’ve made a newbie mistake probably with my Boolean variable but i can’t work out what.
I’m trying to turn on a light with motion then turn it off when no motion unless a door contact has been opened then leave it on for 2 hours.

1) Give a description of the problem
light still goes off when door contact has been opened

2) What is the expected behavior?
light to stay on for 2 hours after door contact has been opened

3) What is happening/not happening?
light is turning off after no motion regardless of door contact

**4) Post a Green Snapshot of the piston


#2

A couple things. In your definition of the variable, you set it to false. This will set the value to false everything time the piston runs and then when the piston runs top to bottom it will always turn off the light. Remove the value assignment from he definition and it will work better. One other thing is your wait will not finish properly. You need to go into the ‘with’ statement under your second ‘if’ statement and set the task cancellation policy (TCP) to ‘never’. This will make sure the door_opened variable gets set to false after the two hour wait. You can find the TCP setting by selecting the with statement and then pressing the gear.


#3

Thanks great tips, i think i have done what you said now the light the doesn’t turn off when no motion and & door contact not opened, is this because the variable goes through the code without setting a value?


#4

I would try…

IF Contact Sensor 1 stays open for 2 hours
  Then
    IF Motion Sensor 1 motion is inactive
      Then
        With Switch 10
          Turn Off
    END IF
END IF

thus eliminating the need for a variable and the WAIT.


#5

Thanks pantheon but that’s not quite what i want to do, the door won’t stay open for 2 hours just opened briefly


#6

I see. So you want the light to stay on for two hours after the door is opened, and turn off if no activity for two hours?

IF Contact Sensor 1 opens
  Then
    IF Motion Sensor 1 motion is inactive for 2 hours
      Then
        With Switch 10
          Turn Off
    END IF
END IF

#7

Just for the light to turn on and off as motion is detected but when the door is opened the light stays on for 2 hours regardless of motion.


#8

I’m not sure I am understanding you…you want the light to stay on for 2 hours if the door is opened? And you want the light to come on if there is any motion? How long do you want the light to stay on after motion? If there is motion, and the 2 hour limit has not expired, do you want to start another 2 hours with the light on?


#9

sorry not explaining myself very well.
i want the light to turn on when motion is detected and turn off when it stops detecting motion, unless the door is open then i want to turn off a different switch and the light to stay on for 2 hours then go back to the previous state if there is motion the light is on if there isn’t it is off.


#10

How long after detecting motion do you want to turn off the light? A few minutes? What if you are standing there doing something (and the door is closed) and motion is not detected…the light might turn off immediately after you stop moving, leaving you standing in the dark. LOL


#11

the door is inside the room where the motion sensor is so you cant open the door without the motion detector seeing you first.
i want it to turn off when it stops detecting motion. unless the door has been opened. but i think i know what you are saying if you’re standing still it will turn off so it would only need about a minute to compensate for that.


#12
IF Motion Sensor 1 changes to active
  Then
    With Switch 10
      Turn On
END IF

IF Motion Sensor 1 stays inactive for 2 minutes
  Then
    IF Contact Sensor 1 is open
      Then
        With Switch 3
          Turn Off
      Else
        With Switch 10      (turn off only if door is closed)
          Turn Off
    END IF
END IF

IF Motion Sensor 1 stays inactive for 2 hours     (the door is open)
  Then
    With
      Switch 10
        Turn Off
END IF

#13

Not sure why you turn off the light if the door is open. That seems opposite of what you want. Thought you want it on for two hours.

I think what you need is something like this:

if motion changes to active       <--trigger
  then
     turn on light
end if
if contact sensor changes.       <-- trigger
then
  if contact sensor is open.       <-- condition
  then
     turn on light
     set door_open=true
     wait 2 hours
     turn off light
  else
    set door_open=false
  end if
end if
if motion stays inactive for 2 minutes.      <-- trigger
   and
   door_opened is false 
then
  turn off light
end if

EDIT: Sorry, @Pantheon was posting at the same time as me. His will probably work better and eliminates the variable. He’s way smarter than me :slight_smile: . You can try either way.


#14

@The_Dire_squire, did you get this working?


#15

I took a break from it as it was driving me insane. Got there in the end with a bit of trail and error, thanks for your help guys, this is what i came up with, the other switch i wanted to turn off when the door opened i created a suppurate piston for seemed like the essayist way round


#16

ALL of us have been there. Glad you were able to get it working! :+1:


#17

LOL thanks again, do you know of any good training material? this looks like such a powerful tool with so many options.


#18

I have used example pistons and active user pistons that are posted here to learn webcore. Also, I depend heavily on many of the users in this forum for assistance. We have a great group of people here who are more than willing to help. Unfortunately, the wiki is missing LOTS of content. I use THIS PAGE often when programming. Since the author of webcore has been hired by SmartThings, we are awaiting a new version of webcore. Not many details as of yet. For me, learning webcore has been like reading a textbook without chapters, a table of contents, or an index (but LOTS of reading the forums).


#19

To be honest, the search button in the top right is (by far) the best resource for specific questions.

pic

Oftentimes, ten minutes of searching can point you directly to a working example, with a bit of learning along the way.


For a more structured approach, the links found in the first section here are what I usually recommend starting with.