Lighting Recipe Advice/guidance required


Although this is my first post to this forum, I have been a Smartthings user for some time and although I manage to get most of what I need for my basic requirements, the following is leaving me somewhat bemused - despite my attempts with the varying applications available. So I thought this was a great time to ‘sign up’ to here and ask for some assistance.

My need: I would like a bulb (wemo) to turn on and stay on with a specific circumstance using a combination of a Smartthings Multipurpose sensor and a Smartthings Motion Sensor.

The devices: Three are three - all situated in the same room.

  1. A Motion Sensor (ST).
  2. A Contact Sensor (ST).
  3. A Smart Bulb (Belkin Wemo).

What I would like to see happens is:

  1. Under Motion (which is usually the first event) turn on the bulb.

  2. Turn off light when motion stops.
    (this I have working via either CoRE or Smart Lighting)

  3. If the Contact Sensor changes to open (from closed) turn on the light.

  4. If the Contact Sensor changes to closed turn off the light.
    (this I have working in a way … but if the contact sensor stays open, after a short period of time the light appears to turn off … again this is currently set up via a Smart Lighting recipe).

What I would like to see happen are the following scenarios:
A. If Contact Sensor changes to Open turn on light.
B. If Contact Sensor changes to Closed turn off light.
C. If Contact Sensor remains Open leave on the light, until the Contact Sensor is closed.
D. If Contact Sensor is closed but Motion is detected leave the light on (this also is something I do not seem to be able to find the way).
E. If Motion detection stops (i.e. no Motion) but the Contact Sensor is open leave light on - given that Motion detection would be the first item here to activate the bulb - currently it seems that the light will go off after a short period of time.
F. If Contact Sensor is Closed and there is no Motion turn off the light.

So in summation what I would like is the room illuminated if one or a combination of the Sensors are in use (i.e. Motion active and/or open (no matter for how long)), the light to turn off when both of them are inactive (i.e. no motion and contact sensor closed).

Thanks for your time, and I trust I have explained my scenario with clarity.

Thank you.

Hi, I imagine CoRE could do this, turn on with either motion or contact and off when both are off. Also since it is very straight forward a simple program might be easier to do exactly what you need.
Give this code a try:

 *  Control light with motion and contact sensor
 *  Author: Lightnjac

    name: "Wemo Light follows me",
    namespace: "Lightnjac",
    author: "",
    description: "Turns on a light when contact opened, off when closed, also can turn on/off with motion.",
    category: "Convenience",
    iconUrl: "",
    iconX2Url: ""

preferences {
	section("Turn on when contact opens..."){
                input "contact1", "capability.contactSensor", title: "Which Contact Sensor?"
	section("Turn on when motion starts..."){
            input "motion1", "capability.motionSensor", title: "Which Motion Sensor?"
	section("Turn on/off light..."){
		input "light1", "capability.switch"

def sub()
    subscribe(contact1, "", contactOpen)
    subscribe(contact1, "contact.closed", contactClosed)
    subscribe(motion1, "", motionStart)
    subscribe(motion1, "motion.inactive", motionStop)
    state.contactOpen = false
    state.motion = false

def installed()

def updated()

def contactOpen(evt)
	state.contactOpen = true
    log.debug "Open, contactOpen = ${state.contactOpen}, motion = ${state.motion}"

def motionStart(evt)
	state.motion = true
    log.debug "Motion, contactOpen = ${state.contactOpen}, motion = ${state.motion}"

def contactClosed(evt)
	state.contactOpen = false
    log.debug "Closed, contactOpen = ${state.contactOpen}, motion = ${state.motion}"
    if(!state.motion) {

def motionStop(evt)
	state.motion = false
    log.debug "Motion Stopped, contactOpen = ${state.contactOpen}, motion = ${state.motion}"
    if(!state.contactOpen) {