Blind control - Open at Sunrise, but not before 7:00am

Disclaimer: I started home automation about four years ago and this forum has been very valuable, although somewhat frustrating at times. For the new comer not knowing the automation terminology or understanding the very basics of home automation, finding examples for a specific task, whatever it was at the time, can be difficult. On occasions I could find another user asking the same question I had, only to have replies such as ?asked and answered elsewhere on this forum? with no information how to find that ?elsewhere.? The following example is from my current home automation system and is provided here as a detailed walk-through with the hopes of helping someone new to Vera UI7.

The Hardware: I have three z-wave automated blinds in the master bedroom running on a VeraPlus controller using UI7 (basically a out of the box factory installation with firmware updates applied). The blinds are HomeDepot Bali DiamondCell Blackout Cellular Shades ordered to fit with the AutoView (z-wave) Motors. The blinds installation is typical and insertion to the z-wave network straightforward.

The Situation: I would like the blinds to open at sunrise, but not before 7:00am. At first, I created a scene to open all three blinds at 7:00am, which works for about 8 months out of the year. Then, when sunrise occurred after 7:00am, I would log into my Vera UI7 interface and change the schedule to open blinds at sunrise. Okay, it is really not that big of a deal to change the schedule 2x per year; however, this is a smart house and I want it to be, well?smart!

The Goal: Using only native features to VeraPlus UI7 (i.e., without third party tools which may be free or cost $), create a scene that will open the blinds at sunrise (but not before 7:00am during the work week and not before 9:00am on the weekend), and to work year-around without having to alter the schedule.

The Scene: Create a typical VeraPlus scene, mine is called ?Master Blinds Open.? Add scheduled triggers as follows: 1) Weekly Schedule Trigger for Saturday and Sunday, scheduled at 9:00am (where I live, sunrise is never later then 9:00am); 2) Weekly Schedule Trigger for Monday, Tuesday, Wednesday, Thursday and Friday, scheduled at 7:00am; and 3) Weekly Schedule Trigger for Monday, Tuesday, Wednesday, Thursday and Friday, scheduled at 2 minutes after Sunrise. NOTE: the 2 minutes after sunrise is important as the VeraPlus processor is fairly fast and when using a sunrise schedule with the is_night() function, there is the possibility (although slim) that the scene will incorrectly function. This can be avoided by running the scene schedule 2 minutes after sunrise, and really who cares that it?s not exactly at sunrise but close enough and it still automatically adjusts with the cyclic nature of our planet.

The last piece of the puzzle and for some, the dreaded LUUP/LUA code. For those just interested in the code, here it is. For those new comers that would like to understand the code and what each part is doing, I have attached a line by line explanation at the end of this post.

local tNotBefore = “06:59”
local tHour, tMin = string.match(tNotBefore,“(%d+): (%d+)”) – Note: this line has an unwanted extra space after the ): because the editor wants to put in a :), space should be removed if you use code
local mNotBefore = (tHour * 60) + tMin
local tNow = os.date(“*t”)
if (tNow.wday == 1) or (tNow.wday == 7) then
– Saturday or Sunday, Run as scheduled
return true
else
local mNow = (tNow.hour * 60) + tNow.min
if (mNow >= mNotBefore) and not luup.is_night() then
– After sunrise and after 06:59am, open blinds
return true
else
– Either before sunrise or before 06:59, do not open blinds
return false
end
end

The Details: This section is provided as a help to the “New Comer,” as it was very difficult for me when I started in home automation. There are many great posts and ideas on this forum; however, sometimes they are hard to find, and/or one must wade through a lot of questions and put several pieces together to get your specific job done.

local tNotBefore = “06:59” – this creates a local variable that I use to store my ?don?t open blinds before? time. It is set to 1 minute before 7:00am for no other reason then to have a 1-minute safety margin. The other reason for setting this variable is that if I ever decided to change the ?not before time,? its an easy one-line change instead of having to read through the code and find cryptic numbers to decipher and change, sometimes in multiple places.

local tHour, tMin = string.match(tNotBefore,“(%d+): (%d+)”) – this line creates two new local variables, tHour and tMin that are parsed out from the variable tNotBefore, which in this case contain the numeric values 6 and 59 respectively

local mNotBefore = (tHour * 60) + tMin – here we create another local variable to contain the number of minutes since midnight that equates to 6:59am, i.e. (6 * 60) + 59 = 419 minutes since midnight

local tNow = os.date(“*t”) – this line creates a table of date information, according to wiki.micasaverde.com, containing: year, month, day, yday, wday, hour, min, sec, and isdst. The parts that we need to use are tNow.wday which contains the day of week, Sunday = 1, Saturday = 7.

if (tNow.wday == 1) or (tNow.wday == 7) then – here we determine if today is Sunday or Saturday (1 or 7)
– Sunday or Saturday, Run as scheduled
return true – tells the scene to continue to execute, i.e., open the blinds
else
local mNow = (tNow.hour * 60) + tNow.min – convert the current time into minutes since midnight
if (mNow >= mNotBefore) and not luup.is_night() then – if current time >= 419 (6:59am) and not night time
– After sunrise and after 06:59am, open blinds
return true – tells the scene to continue to execute, i.e., open the blinds
else
– Either before sunrise or before 06:59, do not open blinds
return false – tells the scene to NOT continue, i.e., don?t open the blinds
end
end

Final Results: The blinds in the master now open at sunrise (provided sunrise is > 7:00am) or at 7:00am but not before 7:00am, and the schedule never has to be changed…a Smart House.

I hope this walkthrough is helpful for some, especially the new comer. I know that I learned a lot from similar posts when I started with home automation. If there is any interest, I am willing to share other aspects of my home automation installation. Some possibilities: outside lights come on automatically, except October 31st (Halloween) for those that don?t participate or those who may not be home at the time and thus won?t have to worry about turning off their lights. I also have a weather station in our back yard that is linked to Vera that I use to determine of the living/dining room blinds (east facing windows) open completely (on cloudy days) or gradually (on sunny days) over a four-hour period to help keep sunlight out of our eyes off the furniture and floors.

You should try PLEG and see how much easier this is!

Can you share your weather station in your backyard linked to vera? how does that work? i also want to open my 9 autoview bali shades when it is cloudy instead of asking “Alexa, open south shades” in the Alexa routines. thanks in advance. the problem i see here is that the shades will open/close all day long if it is partly sunny, partly cloudy.

I use a Davis weather station reporting to Weather Underground … and use the Weather Underground plugin on Vera.

Looks like Weather Underground is no longer a choice for new users: Loading | Weather Underground

To improve our services and enhance our relationship with our users, we will no longer provide free weather API keys as part of our program. If you have been directed to download our Weather Underground free API key by a third party provider, please contact your vendor for resolution.

It’s unclear how long the existing key users will be able to continue.