Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome General
 PowerHome Messageboard : PowerHome General
Subject Topic: Philosophical question Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
judetf
Senior Member
Senior Member


Joined: January 23 2008
Online Status: Offline
Posts: 234
Posted: February 29 2008 at 14:57 | IP Logged Quote judetf

I get home at 6:30pm almost every night; never earlier, sometimes later. I would like my foyer lights to be on when I get home unless the sun hasn't set.

I can readily envision two ways to accomplish this, though there are probably more. It probably doesn't really matter which approach I take, but I'm curious as to whether there are concrete implications to one verses any other that I should factor.

One way I can think of is to create two macros: one fires at 6:30 and one fires and sunset. Each checks the alternate condition (6:30 macro checks if it is sunset yet; sunset macro checks if it's 6:30 yet), and turns on the light appropriately.

The other way is based on snippets of code I saw in the phsample.db file, which is a macro that runs every morning at 1am (or whenever) and creates triggers based on conditions. In that model I would assess whether 6:30 or sunset is later on that given day, and create a one-shot trigger for that day setting the correct variable.

All things considered, is there a particular value to one approach over another?

This is more an mental exercise than a plea for actual assistance, but I'm open to hearing any and all sides.

Thanks
jtf
Back to Top View judetf's Profile Search for other posts by judetf
 
bhlonewolf
Senior Member
Senior Member


Joined: March 29 2007
Online Status: Offline
Posts: 198
Posted: February 29 2008 at 16:26 | IP Logged Quote bhlonewolf

As you say there's a lot of different things to consider -- but just dealing with the issue at hand (6:30 vs sunset). If the sun sets at say 7:30, do you want the light to come on then? Or _only_ 6:30 if the sun has set?

There are a few ways that come to mind:

1) Similar to what you've said above, you run a macro daily that computes the sundown for that day, and creates one-time events as necessary.

2) You have a timed event run at sundown. If it's before 6:30, sleep until 6:30.

I like #1 as it is a bit more durable. I don't like running 2 macros, one at sundown and the other at 6:30 as it's a bit kludgy, particularly if both are around the same time... things can get messy.


Edited by bhlonewolf - February 29 2008 at 16:27
Back to Top View bhlonewolf's Profile Search for other posts by bhlonewolf
 
judetf
Senior Member
Senior Member


Joined: January 23 2008
Online Status: Offline
Posts: 234
Posted: February 29 2008 at 16:34 | IP Logged Quote judetf

I do want the lights on at 7:30 if that's when sunset it. Yes, 2 macros is definitely lame.

I didn't know about a "sleep" option, and I'll think about it. Number 2 makes a lot of sense, based on how I had been thinking about things.

I think I like #2 better than #1. #1 means that there is no timed event between when it last runs and 1am (or whenever the "daily macro" runs). I like the idea of seeing the event (even though I realize I don't know when it will actually turn on the lights just by looking).

I guess it doesn't really matter... But thanks for the pointer on the "sleep" option!

jtf
Back to Top View judetf's Profile Search for other posts by judetf
 
bhlonewolf
Senior Member
Senior Member


Joined: March 29 2007
Online Status: Offline
Posts: 198
Posted: February 29 2008 at 17:17 | IP Logged Quote bhlonewolf

In the macro itself, you can use a wait command that effectively sleeps. (There's also delay, but I think wait is the correct one here.)

The only thing I don't like about this method is that to me, macro waits are best for short durations. Meaning, turn off the fan in 10 minutes, or whatever. In summer, if sundown is at 8:30, the macro is waiting for 2 hours. You'd be able to see this in the macro execution queue.

The problem with this is that it isn't durable (at least, I don't think it is). If PH restarts, you update your computer, whatever, then it's lost. A timed event wouldn't have this issue. 'Course, you'd need PH to restart anyway and unless you've got it running as a service, manual intervention would be needed anyway.
Back to Top View bhlonewolf's Profile Search for other posts by bhlonewolf
 
judetf
Senior Member
Senior Member


Joined: January 23 2008
Online Status: Offline
Posts: 234
Posted: March 01 2008 at 08:23 | IP Logged Quote judetf

FWIW, here's what I went with in my 'daily macro' as the code for the createtimedevent action:

if(daynumber(today()) > 1 AND daynumber(today()) < 7, string(datetime(today(),relativetime(00:00:00,if([SUNSET] > 66000, [SUNSET], 66000+rand(600))))), 'weekend; do nothing')

Probably a more elegant way to do it... It first checks to make sure it's a weekday (and returns nothing if it is, so no timed event gets created).

If it's a weekend, it sets the one-shot event and compares SUNSET to 6:20pm. If sunset is later than 6:20 the timed event gets set for sunset. If sunset is earlier than 6:20, the timed event gets set for somewhere between 6:20 and 6:30 (to get a bit of the 'random' effect).

Seems to work, so I'm content.

Edited by judetf - March 01 2008 at 08:24
Back to Top View judetf's Profile Search for other posts by judetf
 

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