Can someone help me write a code for a contact sensor


(Boris) #1

Hello, I’m wondering if someone can help me write a simple code for a contact sensor, I’m happy to reimburse for the time, considering I can’t really offer much else :frowning:.

Im looking for a door contact sensor to turn a light or lights on when a door is opened, but turn them off when a door is closed a second time with in a specific amount of time that could be entered on the smartapp (considering the first time a door is closed would be when someone goes into a room and closes the door initially). I would also like to add a scheduling ability as different lights would need to be triggered during day or night.

Any help is appreciated. Thank You.


#2

You Might not need custom code for this, just a shortcut group.

Check this FAQ and see if it helps:


(Jody) #3

Just one door? Can you describe the actual scenario? Like someone enters the bathroom and then exits within a certain amount of time.


(Boris) #4

I’ve tried literally every function thats built in and even some smart apps. The main thing I need is the function of a contact sensor causing an off action when closed the 2nd time. Basically this would be for a bathroom, Ive come to understand that motion sensors don’t work because they dont detect motion while someone is showering, humidity sensors work but it takes too long for humidity to drop down for actions to occur, so that left me with the current idea which it seems would work flawlessly.


(Boris) #5

Exactly right.

Person enters bathroom, light(s) turn on and door closes but lights remain on. Person leaves bathroom and closes door (technically 2nd time door closes within a short time) lights turn off.

In the event person opened door, then closed door to use restroom but left the restroom and never closed the door, then lights would turn off automatically at the set amount of time.


(Jody) #6

Your best bet is still motion sensors. The door opens and then closes scenario breaks when someone goes to the bathroom just to drop off some towels and does not shut the door. The next person after them will open and close the door and the lights will be out.


(Jody) #7

You just need to set a large time window for turning the light out after no motion is detected. Detecting humidity would also work for when someone is in the shower. The bathroom is one of the places I don’t automate. Your partner will not appreciate getting out of the shower in the dark. My partner for example wants absolutely no light on when she goes to the bathroom at night. I automated our guest bath, but not the master bath.


(Boris) #8

I was thinking to have both a motion sensor and door contact as well for those times that the door was left open, and the time out where the lights would turn off would be the scenario reset.

Any chance you can recommend someone that can code this, I really think it may work without my partner going crazy, I put a lot of thought into this. I think it will work.


(Eric R) #9

I can code it, but I am still a little confused on exactly the sequence of events you want with both the contact sensor and the motion sensor.


(Jody) #10

I can code it. I will post an example of how to do this over the weekend.


(Cody Truscott) #11

I’ve actually had a lot of luck with my bathroom — I use a ceiling mounted motion sensor that picks up the shower, toilet area, entrance, sink. During the day, it turns on the all the lighting, and at night, it slowly dims up a cute ikea moon lamp with a very low wattage bulb over the toilet.

I’ve set the dip switches on the motion sensor to be highly sensitive and it only turns off after five minutes of inactivity. Seems to work. In fact, it’s the most reliable part of my ST setup.


(Boris) #12

Thank you. Eric and Jodyalbritton. Is there a way for me to private message so I can give my phone number and explain over the phone.


(Eric R) #13

Click on the picture of me and you will see “Private Message”


(Jody) #14

@April Let’s make this a code challenge. Can there be a badge for the Bathroom SmartApp that does not tick people off.


(Boris) #15

It doesn’t come up with a private message icon for now, I think its because I am new. Can you PM me.


(Eric R) #16

@jodyalbritton - I accept your challenge :wink:


(Jim Anderson) #17

I need this for my bathroom.


(Jody) #18

@baldeagle072 @Jim

If it was not clear, I just spoke with @borya on the phone, and what he wants is for when someone enters the bathroom and closes the door the lights are. After some amount of time they exit the bathroom and the the lights turn off. He wants this to work using a door contact sensor and a motion detector. So the motion detector will take over anytime the door is open and the contact sensors will turn the lights on and off based on open close events.


(Eric R) #19

If it is before that amount of time, the lights will stay on?


(Jody) #20

That is the voodoo

  1. Door Opens, Light comes on and Person Enters
  2. Door Closes lights stay on.
  3. Person Exits the bathroom and door opens.
  4. Door closes and the Lights go out.

He also said he wants the motion detector to work when the door is open and that motion could be used to determine bathroom occupancy.

There are other things to take into consideration. Like the door being left open, or someone just entering and exiting. I think I have a method for accomplishing this.