Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Need Advice for AWAY Lighting Schedule Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
GCollins
Groupie
Groupie
Avatar

Joined: March 27 2011
Location: United States
Online Status: Offline
Posts: 54
Posted: March 09 2015 at 16:49 | IP Logged Quote GCollins

Hi PowerHome Experts,

I'd like to have a single macro that runs an automated lighting schedule whenever we are away from home. While that seems like one of the more basic uses for
PowerHome, I haven't seen anything comprehensive posted here. However, I have read discussions of various PH functions and want to apply what I've learned to my
application.

The first part of the scheme uses a trigger to set the value of a global variable {AWAY} to either 1 (true, Elvis has left the building) or 0 (false, he's come back
home).

The second part uses a single timed event to launch the macro. It's set to run daily beginning at some capped Random+ number of minutes after Dusk, conditional on
the value of the {AWAY} variable per this function in the Boolean column: if("{AWAY}"="1", 1, 0)

The third and final part is the macro, which gradually turns various lights on/off over the next few hours leading up to Elvis' normal bedtime. It goes like this:

10 Goto Label    if("{AWAY}"="0", "END", "nextLINE")   'Check if system taken out of AWAY mode, break out of macro if so, else fall thru
20 X10         &nb sp; xxx                                      'Turn some light on or off
30 WAIT         &n bsp;1800 + (60 * (ph_random (10)))        'Wait some fixed # of seconds (1800) plus some additional random # of seconds
40 ...         &nb sp;         &nb sp;         &nb sp;         &nb sp;         'Ad ditional series of 3 statements like above for different lights and time intervals, and so on
500 LABEL        END

As a fairly new PH user I'd appreciate any feedback. Are there any fatal flaws or unexpected negative consequences in this approach? Is there a more efficient way
or better commands to use?

I'm already having trouble getting the Goto Label command to work, which I've posted about in a separate thread. My other concern is with the WAIT command; I've seen
mentioned that the similar DELAY command causes ALL PowerHome processing to pause. I wouldn't want that. It's important that other timed events, macros and triggers
(like Elvis coming home and toggling the Away button) continue to function while this one particular macro is in its various wait states. My testing thus far
indicates it's not a problem, but I just want to be sure.

Thanks,
G


Edited by GCollins - March 09 2015 at 16:52
Back to Top View GCollins's Profile Search for other posts by GCollins
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: March 09 2015 at 17:51 | IP Logged Quote TonyNo

What I do in this situation is to use Timed Events via a macro called Create Random Events. It generates random on/off times for various lights...

Create Timed Event | FOYER MOTION | string( datetime( today(), relativetime( 00:00:00, [DUSK] + rand( 3600) )))      
Create Timed Event | SINK LIGHT OFF | string( datetime( today(), relativetime( 00:00:00, 79200 + rand( 7200) )))
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
GCollins
Groupie
Groupie
Avatar

Joined: March 27 2011
Location: United States
Online Status: Offline
Posts: 54
Posted: March 09 2015 at 19:00 | IP Logged Quote GCollins

Hi Tony,

That's interesting. If I understand properly, I would
keep a daily repeating event that checks the {AWAY}
variable, and when true would execute a macro that
creates a bunch of one-shot timed events for various
other macros.

Is this a more efficient use of the system versus a
single macro that is stepping slowly though its
commands over the course of a few hours?

Also, how do you cancel the random one-shot events
when the homeowner returns?

Thanks

Back to Top View GCollins's Profile Search for other posts by GCollins
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: March 09 2015 at 23:38 | IP Logged Quote dhoward

GC,

This is basically what I do as well. I have a global
variable such as your AWAY var that is set to 1 when
Im gone and 0 when Im home. A timed event runs daily
that checks the value of this GV (can be done in the
boolean field of the timed event). If conditions are
met and the timed event executes, it launches a macro
to create my random 1 shot timed events.

In my macro, I made a list of all possible items that
I may want to have randomly turned on. I then assigned
a percentage chance of whether that device would
actually get switched for this days random events. If
it does get turned on, I then create a couple of one
shot timed events (one for on, one for off) with
suitable random start/stop time values.

A couple of ways to handle the already created timed
events when the AWAY var changes. I use the
ph_createtimedevent1 function (so I have full control
over the parms). You can include in the boolean
parameter a check for the AWAY var and just leave the
timed events alone as they'll fire (but won't execute)
and then will be gone. The other way you could handle
it is to give all the one shot events a leading prefix
on the ID and then create a trigger on the AWAY var to
run a SQL statement to delete all timedevents with an
ID beginning with the prefix.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
GCollins
Groupie
Groupie
Avatar

Joined: March 27 2011
Location: United States
Online Status: Offline
Posts: 54
Posted: March 10 2015 at 09:36 | IP Logged Quote GCollins

OK, that's two valued suggestions to go with the
create timed events approach. I like the percentage
concept and the boolean method for checking the AWAY
var (just like I do when launching the whole thing,
duh).

I will move to this approach, but it's a bit more
complex so I may put it off for a while. Until then,
is there anything terribly wrong with my use of the
WAIT statements as I have it set up now?

Also Dave, would you mind sharing a line of your macro
code that uses the ph_createtimedevent1 function?

Thanks
Back to Top View GCollins's Profile Search for other posts by GCollins
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: March 11 2015 at 21:35 | IP Logged Quote dhoward

G,

You should have no problem using the Wait command. It
won't hold up any PowerHome processing. However, it
will hold up the rest of the macro lines that appear
after the wait (which may be what you want) so your
lights or other "control" statements will be
sequential.

Below is a sample of what a randomly generated timed
event would look like:


In this macro, the first checks whether to skip the
generation of this event. Basically there is an 85%
chance that we will control the KITCHEN light. Line 20
is the creation of the timed event. Im using a random
+/- offset of 40 minutes from the default starttime of
08:00:00. The next parameter (3) is for an action of
Device Control string (this is missing from the help
file). The next line is the event to turn the light
off. Basically you would duplicate these 4 lines over
and over for each light/device you want to randomly
turn on.

Dave.


Edited by dhoward - March 11 2015 at 21:42
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
GCollins
Groupie
Groupie
Avatar

Joined: March 27 2011
Location: United States
Online Status: Offline
Posts: 54
Posted: March 15 2015 at 21:29 | IP Logged Quote GCollins

Dave,

Yes, I want my AWAY events to be sequential (yet at
somewhat random spacing), for now. Mimics our "routine".

Thanks for the peace of mind on the WAIT statement.

Thanks also for the examples, great for the future.

G
Back to Top View GCollins's Profile Search for other posts by GCollins
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum