Lights on when arriving after sunset?


(Sean Murray) #1

Trying to figure out if there is a smartapp that will turn on a specific set of lights when either my wife or I arrive home after sunset. I already have a smartapp that turns lights on and off at sunset/sunrise, but I want a different set of lights to turn on only if we arrive home and it’s dark out. The closest I’ve found is one that turns on lights at sunset IF we are home and not if we are away. That’s close but if I’m already home at sunset it still turns the lights on.


#2

Yes, if “I’m back!” In Hello Home had a Sunset/Sunrise setting it would be very nice! Maybe someone has created a SmartApp for this?

I don’t see a way to do this using IFTTT.


(Ed Meredith) #3

I use a contact to trigger that in my setup. Basically what I do is when my garage opens during a specified time period I have specific lights that come on. So I set the time for this to trigger between 9:00 pm and Midnight during the summer and adjust it as the days get shorter in the fall and winter.


(Alex) #4

Check out this app. i think this is what you need.


(Sean Murray) #5

That would work except it uses a light sensor which I don’t have. I need it to detect whether or not it’s after sunset based on my local zip code.


(Sean Murray) #6

I found a SmartApp called “Honey, I’m Home” while browsing the published apps section and it seems like it should do exactly what I want. When I try and add it through the web interface on my laptop and then try and pull it up on my phone to add it to my dashboard I get an “unexpected error” message after trying to configure it and press done. I don’t know enough to try and figure out what’s happening. Any ideas?

/**

  • Honey, I’m Home!
  • Author: oneaccttorulethehouse@gmail.com
  • Date: 2014-01-26
  • Heavily borrowed from Night Light/Sunrise/Sunset and Greetings Earthling.
  • Will turn on lights and change the mode when someone arrives home and it is dark outside.

*/

preferences {

section("When one of these people arrive at home") {
	input "people", "capability.presenceSensor", multiple: true
}
section("Change to this mode") {
	input "newMode", "mode", title: "Mode?"
}
section("False alarm threshold (defaults to 10 min)") {
	input "falseAlarmThreshold", "decimal", title: "Number of minutes", required: false
}

/* MINE /
section(“After sunset and before sunrise, turn on a light…”) {
input “lights”, “capability.switch”, title: “Switches”, required: false, multiple: true
}
section (“Sunrise offset (optional)…”) {
input “sunriseOffsetValue”, “text”, title: “HH:MM”, required: false
input “sunriseOffsetDir”, “enum”, title: “Before or After”, required: false, metadata: [values: [“Before”,“After”]]
}
section (“Sunset offset (optional)…”) {
input “sunsetOffsetValue”, “text”, title: “HH:MM”, required: false
input “sunsetOffsetDir”, “enum”, title: “Before or After”, required: false, metadata: [values: [“Before”,“After”]]
}
section (“Zip code (optional, defaults to location coordinates)…”) {
input “zipCode”, “text”, required: false
}
/
END */
section( “Notifications” ) {
input “sendPushMessage”, “enum”, title: “Send a push notification?”, metadata:[values:[“Yes”,“No”]], required:false
input “phone”, “phone”, title: “Send a Text Message?”, required: false
}

}

def installed() {
initialize()
log.debug "Installed with settings: ${settings}"
log.debug "Current mode = ${location.mode}, people = ${people.collect{it.label + ': ’ + it.currentPresence}}"
subscribe(people, “presence”, presence)
}

def updated() {
log.debug "Updated with settings: ${settings}"
log.debug "Current mode = ${location.mode}, people = ${people.collect{it.label + ': ’ + it.currentPresence}}"
unsubscribe()
subscribe(people, “presence”, presence)
unschedule()
initialize()
}

def initialize() {
scheduleAstroCheck()
astroCheck()
}

def scheduleAstroCheck() {
def min = Math.round(Math.floor(Math.random() * 60))
def exp = "0 $min * * * ?"
log.debug "$exp"
schedule(exp, astroCheck) // check every hour since location can change without event?
state.hasRandomSchedule = true
}

def astroCheck() {
if (!state.hasRandomSchedule && state.riseTime) {
log.info "Rescheduling random astro check"
unschedule(“astroCheck”)
scheduleAstroCheck()
}
def s = getSunriseAndSunset(zipCode: zipCode, sunriseOffset: sunriseOffset, sunsetOffset: sunsetOffset)

def now = new Date()
def riseTime = s.sunrise
def setTime = s.sunset
log.debug "riseTime: $riseTime"
log.debug "setTime: $setTime"
if (state.riseTime != riseTime.time || state.setTime != setTime.time) {
	state.riseTime = riseTime.time
	state.setTime = setTime.time

	unschedule("sunriseHandler")
	unschedule("sunsetHandler")

	if (riseTime.after(now)) {
		log.info "scheduling sunrise handler for $riseTime"
		runOnce(riseTime, sunriseHandler)
	}

	if (setTime.after(now)) {
		log.info "scheduling sunset handler for $setTime"
		runOnce(setTime, sunsetHandler)
	}
}

}

private enabled() {
def result
def t = now()
result = t < state.riseTime || t > state.setTime
result
}

def presence(evt)
{
log.debug "evt.name: $evt.value"
def threshold = (falseAlarmThreshold != null && falseAlarmThreshold != “”) ? (falseAlarmThreshold * 60 * 1000) as Long : 10 * 60 * 1000L

if (location.mode != newMode) {

	def t0 = new Date(now() - threshold)
	if (evt.value == "present") {

		def person = getPerson(evt)
		def recentNotPresent = person.statesSince("presence", t0).find{it.value == "not present"}
		if (recentNotPresent) {
			log.debug "skipping notification of arrival of ${person.displayName} because last departure was only ${now() - recentNotPresent.date.time} msec ago"
		}
		else {
			def message = "${person.displayName} arrived at home, changing mode to '${newMode}'"
			log.info message
			send(message)
			setLocationMode(newMode)
				 if (enabled()) {
					log.debug "turning on lights due to presence"
					lights.on()
					state.lastStatus = "on"
				}

		}
	}
}
else {
	log.debug "mode is the same, not evaluating"
}

}

private getPerson(evt)
{
people.find{evt.deviceId == it.id}
}

private send(msg) {
if ( sendPushMessage != “No” ) {
log.debug( “sending push message” )
sendPush( msg )
}

if ( phone ) {
	log.debug( "sending text message" )
	sendSms( phone, msg )
}

log.debug msg

}

private getSunriseOffset() {
sunriseOffsetValue ? (sunriseOffsetDir == “Before” ? “-$sunriseOffsetValue” : sunriseOffsetValue) : null
}

private getSunsetOffset() {
sunsetOffsetValue ? (sunsetOffsetDir == “Before” ? “-$sunsetOffsetValue” : sunsetOffsetValue) : null
}


(Alex) #7

I don’t have a physical light sensor either. I use the weather tile that has a virtual light sensor that calculates light based on time of day in relation to sunrise/sunset and weather conditions at my location. Its free and works well enough.


(Hans) #8

Where can I find that weather tile?


(Sean Murray) #9

Yes, where can I find this weather tile?


(Alex) #10

Go the Developers’ area (link on top/right of this page), under devices, create a new device SmartWeather Tile.

You also need to install an app that refreshes the tile. Either Pollster (search the forum) or in mobile application install SmartWeather Station Tile updater (under category convenience).


(Sean Murray) #11

Thanks, I’ll give it a shot.


(Chris) #13

You can also add modes that activate on sunset and only have the lights triggered if those modes are active. That way you don’t have to do any crazy coding.

For my setup, I have two modes - “Home Sundown” and “Away Sundown”. After adding the mode(s), you can add an action to trigger the mode automatically on sunset (Go to the “Hello, Home” screen, click on the settings icon in the bottom right, add an action and change the “Automatically perform ‘your action’ at…” to “Sundown”).

From there you can add a new “Light & Switches” action, select your bulbs / outlets, use “Turn on when people arrive” and change the “Only when mode is” field to the mode that you created (in my example, “Home Sundown”).


(Chris) #15

@Dave

You have to create both an action and a mode. The action toggles the mode and the mode tells the light to turn on. So, what I did was:

  1. Create a new mode (Go to “Dashboard”, click on the gear icon in the top right, scroll down to the bottom and click “Add a new Mode”. I named mine “Home Sundown”)
  2. Create a new action (Go to the “Hello, Home” screen, click on the gear icon in the lower right, click “Add an action” - I named mine “Sunset”. Then click next.)
  3. In the action screen select “Change the mode to” and select the mode you created in step 1 (for mine it is “Home Sundown”). Press Done.
  4. In the action screen again, select “Automatically perform “Sunset”” (mine was named “Sunset” - yours can be different).
  5. Select “At sunrise or sunset”. Select “Sunset”. Select done (x3).
  6. Now, create your new Lights & Switches action (this will vary depending on your setup) and make sure the “Only when mode is” field has the mode you created in step 1 selected.

It’s a bit convoluted, but this process will give you a single mode that can be used to tell a multitude of things to happen only when the sun is down, rather than custom coding each item for sunset.


#16

Cool thanks, it looks like its in their now. I will have to check it by leaving and coming back during the day and again at night… :slight_smile:

@CBud
The only problem I see is if I leave the house after sunset my ST Mode will change from “Home” to “Away-Day” where it should be “Away-Night”.

If I leave the house before sunset it would go from “Home” to “Away-Day” then switch automatically at sunset to “Away-Night” which is correct.


#17

I wish ST would just add a Sunset to Sunrise option to this:


(Chris) #18

Agreed. That would make a lot of these processes much easier, and wouldn’t cause all the troubles with multiple “Home” and “Away” modes.


(Christopher C. Fox) #19

I would love this being added to the core functionality.
I want to be able to have my out door lights turn on when I pull up to the house after sunset. Then have them turn off at a set time.


(Eric V) #20

I have something like this set up for my front porch.

Dashboard > Lights & Switches > Gear Icon > Select the Light
Turn on when People Arrive
Select the people
More Options
Only during a certain time > Starting Around Sunset and Ending Around Sunrise (error on the side of early - they don’t need to be exact since they only fluctuate by an hour or so)

Done.


(Aaron) #21

I’ve written the EXACT app you’re looking for @seannymurrs. It SHOULD be in the shared apps. It’s called “Lights on when door opens after sundown.” I wanted the same functionality and so we’re in the same boat. This app takes advantage of the lag between your ‘arrival’ and the time you get to the door to open it. Here’s how I have it set up:

  1. I arrive (regardless of time) and the house goes from “away” to “home” mode.
  2. I open the door, which has a multi-sensor on it.
  3. App sees it’s after sundown, flips on some lights, then changes the mode to evening or whatever I choose.

If you can’t find the app in the IDE, here’s the code. Good luck!

/**
*

  • Lights On When Door Open After Sundown
  • Based on “Turn It On When It Opens” by SmartThings
  • Author: Aaron Crocco
    */

// Automatically generated. Make future change here.
definition(
name: “Lights On When Door Opens After Sundown”,
namespace: “MacStainless”,
author: “Aaron Crocco”,
description: “When the front door opens after sundown, turn the lights on and switch the house to a set mode. This is an enhancement of the ‘Turn It On When It Opens’ SmartApp.”,
category: “My Apps”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png”)

preferences {
section(“When the door opens…”){
input “contact1”, “capability.contactSensor”, title: “Where?”
}
section(“Turn on these lights…”){
input “switches”, “capability.switch”, multiple: true
}
section(“and change mode to…”) {
input “HomeAfterDarkMode”, “mode”, title: “Mode?”
}
}

def installed()
{
subscribe(contact1, “contact.open”, contactOpenHandler)
}

def updated()
{
unsubscribe()
subscribe(contact1, “contact.open”, contactOpenHandler)
}

def contactOpenHandler(evt) {
log.debug “$evt.value: $evt, $settings”

//Check current time to see if it's after sundown.
def s = getSunriseAndSunset(zipCode: zipCode, sunriseOffset: sunriseOffset, sunsetOffset: sunsetOffset)
def now = new Date()
def setTime = s.sunset
log.debug "Sunset is at $setTime. Current time is $now"
    
    
if (setTime.before(now)) {	//Executes only if it's after sundown.
		
	log.trace "Turning on switches: $switches"
	switches.on()
	log.trace "Changing house mode to $HomeAfterDarkMode"
    setLocationMode(HomeAfterDarkMode)
    sendPush("Welcome home! Changing mode to $HomeAfterDarkMode.")

}   

}


#22

@625alex
Alex, does your Lights on Arrival only work with presence devices or can a door sensor activate the light (when dark)?

I tried Brighten Dark Places but it did not work for me.
Thx