Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Question about macro/timed event priority Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: May 27 2016 at 10:37 | IP Logged Quote gg102

Dave,

I've been troubleshooting long running, extremely intermittent bug. (happens maybe twice a
year) I think I have narrowed it down to one question:

If a macro is running, and a timed event "hits" during the execution of that macro, will PH
suspend the macro, and process the timed event/macro, then resume the previous macro,
or
does PH put the timed event/macro on the execution stack and process it AFTER the first macro
finishes?

If the first, then I can simply disable timed events at the beginning of this particular macro,
then re-enable/resume them at the end of the macro. (which I'm currently testing)

If the second, then I have to learn a whole new list of swear words.



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

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: May 27 2016 at 14:05 | IP Logged Quote dhoward

gg,

Sorry to be the bearer of bad news but it's the second
case.

However, it may not be as bad as you think. Putting a
"Wait" command (you can wait for 0.01 if you like)
will cause a macro to basically suspend and add itself
to the end of the execution queue. So if a macro is
running and a timed event fires (or any other action
that adds an event to the queue), when the macro hits
the "Wait" command, it takes a full snapshot of all
it's internal variables and when the wait is expired
(0.01 would be nearly instantaneous) it will add
itself to the end of the execution queue. This would
allow all other queued events to process and then the
macro would pick back up right where it left off.

Hope this helps,

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

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: May 27 2016 at 14:17 | IP Logged Quote dhoward

gg,

Another option, I hesitate to mention it though because of all the unique problems it can cause, is to put the "Action" of the timed event in the "Boolean" column.
The "Boolean" columns of Timed Events, Triggers, etc. are always executed without going into the execution queue. If that "Boolean" formula happened to do something
like turn on a light or launch a macro then you've effectively bypassed the execution queue.

However, if you are in the middle of doing something like communicating with your Insteon PLM to turn on a light and you then execute an Insteon command while that
first command is running, it will stomp right over the middle of the first command and yield completely unpredictable results and will oftentimes crash the system.
However, you can use the "Boolean" field to execute a ph_postexequeue function so you can "post" an action to the top of the queue or as a priority action (see the
help on ph_postexequeue). Since the resulting action is still going through the queue, no conflict will occur.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: May 27 2016 at 16:40 | IP Logged Quote gg102

Thanks for the quick and thorough response.

Now I understand a little more about how the internals
work.

Let me try to explain what I have figured out and
captured. This gets a little convoluted, so hang to
your hat.....

I have a macro that gets triggered when my HVAC system
comes on. This macro writes to my daily log file,
bumps some counters, and updates a graph for the
CC/RCC.   So, I can see how many times, and when, the
HVAC system comes on, and how many times it comes per
hour, and which hour per day. I also get a summary of
how long per cycle the HVAC system is on, and an
average duration per day.

Here's a couple lines from the log file:

0352 5/27/2016 12:51:32 HVAC AC has turned on while
NORMAL.
0353 5/27/2016 12:58:52 HVAC has turned off. It has
been on for: 7 minutes, 19 seconds, since: 05/27/2016
12:51:32. The HVAC cycle count is: 9. Mode is:
NORMAL.
0354 5/27/2016 12:58:52 HVAC (current) number of
cycles is: 9, HVAC (current) total duration is:
00:56:41, and the HVAC (current) average running time
is: 00:06:17.   The Mode is: NORMAL.



27_163132_Image1.jpg">


(This is NOT the capture of the failure, just a demo
of what I'm doing)

So far so good......

I have another macro that gets triggered at the top of
every hour. This macro writes to my daily log file
some hourly statistics, bumps some counters, and
CLEARS the hourly count of HVAC cycles.

So at the end of the day, the HVAC total cycle count
should equal the sum of HVAC cycles per hour.

you can see what's coming....

Yesterday, for the first time I figured out and
captured the failure. The HVAC system came on 1
second (or less) before the timed event for the hourly
log macro. The HVAC hourly count (for that specific
hour) incremented, then immediately got wiped out by
the hourly macro. Then the hour got incremented.
There's a lot more going on here, but that's the
basics of the situation. So, the count for that hour
was 0, and the sum of the hourly counts and the total
count was not equal to the daily count.

I'm going to look to restructure how this all happens
now that I know what's going on so as to prevent this
situation. Maybe I won't use a general hourly count,
but rather use (pseudo code) HVAC_COUNT[HOUR(NOW()].
This way, the hour_count won't ever get wiped out.


Let me ask another question:
Can hour(now()) change during a macro or between a
macro its submacro before the macro pair ends? If so,
I'll have to save hour(now()) at the top of this
macro.


hmmm.... image didn't load...


Edited by gg102 - May 27 2016 at 16:41
Back to Top View gg102's Profile Search for other posts by gg102
 
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: May 27 2016 at 16:43 | IP Logged Quote gg102






That's better!


Edited by gg102 - May 27 2016 at 16:43
Back to Top View gg102's Profile Search for other posts by gg102
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: June 14 2016 at 19:13 | IP Logged Quote dhoward

gg,

Sorry to take so long responding, I missed your question
at the end.

Yes...hour(now) can change within the confines of a
macro or submacro if it is called just before and just
after the hour changes. Best to store it off in a local
or temp at the start of the macro.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
gg102
Senior Member
Senior Member


Joined: January 29 2013
Location: United States
Online Status: Offline
Posts: 245
Posted: June 15 2016 at 22:15 | IP Logged Quote gg102

Thank you Dave.
Back to Top View gg102's Profile Search for other posts by gg102
 

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