Letting the Dog Out - Door Sensor Automation?

Hey folks, first post but I tried searching and couldn’t find anything that suited.

How would I set up an automation/routine with a door sensor on a patio door which, when opened and closed… turned on the lights, and then after say 5 minutes, when open and closed again, turned off the lights? Only applicable during sunset-sunrise.

Maybe it’s a simple thing, but I’m just looking for the best way to automate turning on and off the lights. I also will have a motion sensor as well if that can assist, but I can’t see how that would.

To make things even more interesting - any suggestions for more than one dog if they go out at the same time/come in at different times? Ugh this sounds tough.

1 Like

I ended up having to set this up in webcore. There was too much complication for native SmartThings apps to handle. What if i’m outside grilling, what if I manually turn on the light, etc.

Are you able to share what you did in webcore? Even the logic behind it may be something useful :slight_smile:

yeah, let me get a screen shot and import code for you

here you go. I use a variable to determine when to automatically turn off the light. The variable only gets set to true when the automation turns the light on. If the light is manually turned on, the automation doesn’t run.

1 Like

Hello, @Len_Currie

Another approach that could help with your automation is the use of the Rules API, find below a JSON example for your use case.

  • Workflow:
  1. If this contact sensor is opened and if now is between Sunset and Sunrise.
  2. Then turn on the light.
  3. Else wait 5 minutes and Turn Off the light.
{
    "name": "Letting the Dog Out",
    "action": [
        {
            "if": {
                "and": [
                    {
                        "equals": {
                            "left": {
                                "device": {
                                    "devices": [ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ],
                                    "component": "main",
                                    "capability": "contactSensor",
                                    "attribute": "contact"
                                }
                            },
                            "right": {
                                "string": "open"
                            }
                        }
                    },
                    {
                        "between": {
                            "value": {
                                "time": {
                                    "reference": "Now"
                                }
                            },
                            "start": {
                                "time": {
                                    "reference": "Sunset"
                                }
                            },
                            "end": {
                                "time": {
                                    "reference": "Sunrise"
                                }
                            }
                        }
                    }
                ],
                "then": [
                    {
                        "command": {
                            "devices": [ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ],
                            "commands": [
                                {
                                    "component": "main",
                                    "capability": "switch",
                                    "command": "on",
                                    "arguments": []
                                }
                            ]
                        }
                    }
                ],
                "else": [
                    {
                        "sleep": {
                            "duration": {
                                "value": {
                                    "integer": 5
                                },
                                "unit": "Minute"
                            }
                        }
                    },
                    {
                        "command": {
                            "devices": [ "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ],
                            "commands": {
                                "component": "main",
                                "capability": "switch",
                                "command": "off",
                                "arguments": []
                            }
                        }
                    }
                ]
            }
        }
    ],
    "timeZoneId": "yourTimeZoneId"
}

I hope this example results useful to you.

Hmm… sorry to bug and appreciate you posting it, but any chance I can get a ‘copy + paste’ instead of a screenshot? :smiley: Like to play around with it a bit…

I will say that I used IFTTT and was able to create a filter which, as long as I don’t close the door completely… works great between certain hours… so it’s a great start, but always room for improvement :slight_smile:

You can use the import code on the picture to import the whole piston into your webCoRE environment.