Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Help with conditional macro Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
Lazyman
Groupie
Groupie
Avatar

Joined: February 08 2006
Location: United States
Online Status: Offline
Posts: 74
Posted: June 09 2006 at 19:10 | IP Logged Quote Lazyman

I would like to create a macro (I think a macro), so that if it is between 11:00 p.m. and 6:00 a.m., and motion is detected, and the bedroom light is off, certain Insteons will come on to a certain level for 10 minutes (if you get up in the middle of the night, you get a dim path to the kitchen).

I need a macro that says if an x10 command (D3 - on) is received, then, if it is after 11:00 p.m. and before 6:00 a.m., and if Insteon "Bedroom Light" is off, then turn on Insteon "Hallway" and "Kitchen" (or PLC group), wait 10 minutes, and turn off the Insteons.

Can it be done? Too much? Any suggestions?
Back to Top View Lazyman's Profile Search for other posts by Lazyman
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: June 09 2006 at 22:13 | IP Logged Quote TonyNo

Yes! No! Sure...

What I would do would be to create a trigger that calls the macro when D3 turns on. The macro would check to see if the light was off...

Code:
JUMP if( ph_getinsteonstat( "Bedroom Light" ) = 1, 1, 999)


...then check the time for the proper range...

Code:
JUMP if( hour( now()) >= 23 or hour( now()) <= 5, 1, 999)


If either were not true, the macro would exit (JUMP to 999). If both were true, the lamps would be turned on and a 10-minute wait would be started. After the wait, the lamps would be turned off.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
Lazyman
Groupie
Groupie
Avatar

Joined: February 08 2006
Location: United States
Online Status: Offline
Posts: 74
Posted: June 10 2006 at 00:46 | IP Logged Quote Lazyman

I think I am slowly starting to get this. There is not a lot of documentation on this stuff.

On the Macro list of the Powerhome Explorer I created the Macro "Path to Kitchen" I am not sure what list and grammer means, but I checked them. The macro name then appeared below the branch MACRO after I pushed F5.

Then I clicked on the new macro. For sequence 10, under command I selected Jump and under formula, I copied in "if( ph_getinsteonstat( "Bedroom Light" ) = 1, 1, 999)"

At seq. 20, I selected jump and copied under formula "if( hour( now()) >= 23 or hour( now()) <= 5, 1, 999).

At seq 30, under command I selected Insteon, for ID, I selected the Insteon unit I wanted to control and gave it the value on.

So far, is this correct? How do I set the ramp rate and level the unit comes on?

At seq 40, unde command I selected wait and put 600 in the formula.

At seq 50, I selected Insteon for ID, I selected the Insteon unit I wanted to turn off, and selected value off. Do I need anything under formula?

I then created a trigger with an action type of macro. For the action I selected my new macro. Action style I selected immediate (I remember reading out these options but do not remember specifically when to use each choice, but I know I have seen this). Status I picked active. Trigger type I picked X10 In. I then selected my house and unit code and a trigger value "on" I left boolean at 1 which I assume is true, meaning execute the trigger if it receives a C3 on command.

Was there an easier way? Did I do this correctly?

Tony, thanks for the fast response.
Back to Top View Lazyman's Profile Search for other posts by Lazyman
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: June 10 2006 at 08:40 | IP Logged Quote TonyNo

In the macro list, uncheck Grammar for your macro, that is for VR.

In line 30, the SendKeys/TTS/Dim/Formula field is for Dim level. The range is 0-255, so 128 would be 50%.

For line 50, Off has no other parameters, so you're good.

You want the trigger Action Style to be Queued.

If it works, you are done!
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
Lazyman
Groupie
Groupie
Avatar

Joined: February 08 2006
Location: United States
Online Status: Offline
Posts: 74
Posted: June 10 2006 at 11:21 | IP Logged Quote Lazyman

Tony, at 8:40 in the morning you should be sleeping.

Somehow, it does work. I am thrilled that I have progressed to this point.

Next, the lights in the macro come on and go off, one by one. I am going to revise it by creating a PLC group. I will let you know when I hit my first stumbling block.

(One question, I assigned a menu shortcut to the Macro so I could test it as I was working on it (ctrl-alt-shift-F12). It does not trigger the macro. Am I missing something.

Thanks for all your help.
Back to Top View Lazyman's Profile Search for other posts by Lazyman
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: June 10 2006 at 21:07 | IP Logged Quote TonyNo

Heh. I am getting older, so I wake up earlier!

Good job!

Have you refreshed or closed the macro window? I just tried assigning a keyboard sequence to a macro and it took a couple tries.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: June 11 2006 at 22:51 | IP Logged Quote dhoward

Lazyman,

Great job!!

Concerning the macro shortcut keys...you need to make the menu refresh before the shortcut key takes effect. The easiest way to do this is to close the Explorer and reopen it. If you look under the menu Macros and then the 4 different macro range menus, you'll see the various assigned macro shortcut keys. The shortcut wont work until it appears in the menu.

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

Joined: February 08 2006
Location: United States
Online Status: Offline
Posts: 74
Posted: June 11 2006 at 23:02 | IP Logged Quote Lazyman

I want button 5 on a keypadlinc to be an all off switch. I know there are many ways to do this.

I created a PLC group to do this (I know 255 would also do it), but I want to make this button an all off button whether it is on or off. (I know some of the options get over my head and making it not toggle is probably my best bet but I do not know how to deal with that).

I created my PLC group and then created a macro to turn off the PLC group. That works great. My problem is with the trigger. How to I set the trigger on button 5 so that it turns PLC group 8 off no matte what?
Back to Top View Lazyman's Profile Search for other posts by Lazyman
 
Lazyman
Groupie
Groupie
Avatar

Joined: February 08 2006
Location: United States
Online Status: Offline
Posts: 74
Posted: June 11 2006 at 23:03 | IP Logged Quote Lazyman

One more.

There are 2 macros that I did not create in my macro group. When I delete them, they come right back. Is there a trick to deleting them? (playbacklist and playslottrack)
Back to Top View Lazyman's Profile Search for other posts by Lazyman
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: June 11 2006 at 23:57 | IP Logged Quote dhoward

Lazyman,

You are right, several different ways to do it. You could link button 5 to all devices you want to turn off and then set the button to "non-toggle", off only.

However, you can also do it the way you describe. You've created a PLC group (group 8) with all the devices in it and have created a macro to send an OFF command to this group. Now all you need are a couple of triggers. Set the trigger action type to "Macro" and the action to the ID of your all off macro. Set the action style to "queued" and the Trigger type to "Insteon Group In". Set the Trigger ID to the ID of your KeypadLinc and the Trigger ID Number to 5. In the first trigger, set the Trigger Value to "On" and the second trigger set the Trigger Value to "Off". Now whether the keypadlinc button is on or off, you'll always call the all off macro.

The "PLAYSLOTTRACK" and "PLAYPLAYLIST" macros were default installed along with PowerHome. These macros are used to coordinate playback of songs with CD jukeboxes. However, you should be able to just right-click on them and hit delete. Press "F5" to refresh and they should be gone. Try this and if they still come back, let me know and I'll check it out.

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

Joined: February 08 2006
Location: United States
Online Status: Offline
Posts: 74
Posted: June 20 2006 at 18:40 | IP Logged Quote Lazyman

Let's go one further: What if I want the Macro to be conditioned on the level of the light. In other words, if the light is set at 50 or less, then go to the next line, else terminate.

ph_insteonstat only checks on or off, right?
Back to Top View Lazyman's Profile Search for other posts by Lazyman
 
Lazyman
Groupie
Groupie
Avatar

Joined: February 08 2006
Location: United States
Online Status: Offline
Posts: 74
Posted: June 20 2006 at 18:47 | IP Logged Quote Lazyman

Second question, I am thinking of trying to create a macro that would be triggered by a motion sensor (Hawkeye), and turn a light to full when it senses motion, then when motion stops, return the light to the level it was at before it sensed the motion.

I sense this would not be hard to do using a variable.

Also, I am now using groups/linking/PLC Groups; Timmed Events; Macros; and Triggers. Where would you use a formula as in the formula section of the explorer (I know they are in my macros.
Back to Top View Lazyman's Profile Search for other posts by Lazyman
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: June 20 2006 at 20:48 | IP Logged Quote TonyNo

1. You would use ph_getinsteonlevel( "Bedroom Light" ) for the dim level. Remember that 50 / 128 = 19% and 50% = 128.

JUMP if( ph_getinsteonlevel( "Bedroom Light" ) <= 50, 1, 999)

2. Create two triggers: one for motion and one for no motion. Each calls a different macro. "Motion" would read and store the light level in a global variable and bring the light up to 100%. The "no motion" macro would read the level and dim to that.

3. See the code in #1. That is a formula.

You could also create a formula for the triggers instead of calling a macro...

Motion Trigger

FORMULA ph_setglobal_a( "BRLEVEL", ph_getinsteonlevel ( "Bedroom Light" ) ) + ph_insteon( "Bedroom Light", ibright, 255 )

No Motion Trigger

FORMULA ph_insteon( "Bedroom Light", idim, ph_getglobal_n( "BRLEVEL" ) )
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: June 23 2006 at 21:59 | IP Logged Quote dhoward

Lazyman,

The "Formula" section in the PowerHome Explorer is mainly to be used for storing formulas that you would want to reuse. It allows you to type a short ID for referencing from other sections as well as a description of the formula. If you had several macros that used the same formula, rather than typing the formula in each macro or each section of a single macro, you could define the formula once in the "Formula" screen and then just call the formula ID in the macro. It would also be good if the formula logic needed to be changed. You could then just go to the formula itself and change it once rather than hunting it down in multiple macros and changing it.

It also is the only way to define a "Formula" button in the Control Center. This should be changing in the next beta so that you can type a "raw" formula for a button, but in the meantime, a formula button must have the formula defined in the "Formula" section.

HTH,

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

Joined: February 08 2006
Location: United States
Online Status: Offline
Posts: 74
Posted: June 25 2006 at 11:16 | IP Logged Quote Lazyman

1) That makes total sense and is a great idea. How do you use it? That is, what is the syntax to call a formula from a macro? Do you just list the name of your formula, or is there something else you need to do?

2) Also, TonyNo gave me the great formula:

FORMULA ph_setglobal_a( "BRLEVEL", ph_getinsteonlevel ( "Bedroom Light" ) ) + ph_insteon( "Bedroom Light", ibright, 255 )


Can you break it down for me please. Is that a compound formula or just a complex one? I am thinking of using it with several different lights. Do I just restate the entire formula for each device?

3) One last point: TonyNo suggested a no motion trigger. My experience is that with a Hawkeye, no motion is not going to work. It does not constantly trigger when there is motion, it only triggers at irregular intervals. I do not need the light to turn off instantly when someone leaves. How do I get it to turn off if it has not sensed motion in the last 5 minutes? Should I be concerned that the Macro will be constantly looping until there is no motion and interfering with other Powerhome stuff?

I was thinking the macro should run for 5 minutes, and then check to see if there had been an x-10 C1 on (my hawkeye) in the last 5 minutes. If so, wait another 5, if not, return the lights to there original state.

Thanks to both of you.
Back to Top View Lazyman's Profile Search for other posts by Lazyman
 
Lazyman
Groupie
Groupie
Avatar

Joined: February 08 2006
Location: United States
Online Status: Offline
Posts: 74
Posted: June 25 2006 at 11:52 | IP Logged Quote Lazyman

I have now re-read the User's Manual and the On-line help. The manual did not make a lot of sense when I first read it (or the time after that). Now it is helping me.

Any reason not to break up the last formula into two lines? Both would have FORMULA under the command column?
Back to Top View Lazyman's Profile Search for other posts by Lazyman
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: June 25 2006 at 12:08 | IP Logged Quote TonyNo

Breaking it down...

FORMULA ph_setglobal_a( "BRLEVEL", ph_getinsteonlevel ( "Bedroom Light" ) ) + ph_insteon( "Bedroom Light", ibright, 255 )

The first thing this does is reads the dim level of the specified module (ph_getinsteonlevel) and puts the value into Global Variable BRLEVEL (ph_setglobal_a). You must create it in the GV section. The next thing it does is brings the level up to 100% (ph_insteon).

For multiple lights, you would create a GV to hold each level and change the device ID.

You could also implement the formula in the Formula section, but then you would need to allow for the GV and device ID to be variables (maybe use Local's). I have never used the formula section, so Dave will need to cover that one.

Regarding the motion stuff, I use a method where I call a macro (TONY MOTION) when motion is sensed that checks to see if we are already waiting. If not, it turns the light on and does a WAIT for five minutes. Anytime motion is sensed after that (already waiting), it extends the WAIT for another five minutes. After the wait times out (no motion for five minutes), the light is turned off.

JUMP if( ph_ismacrowaiting("TONY MOTION") > 0, 1, 3)
FORMULA ph_extendmacrowait("TONY MOTION", 300, 0)
JUMP 999
[light on code]
WAIT 300
[light off code]
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: June 25 2006 at 12:12 | IP Logged Quote TonyNo

Quote:
Any reason not to break up the last formula into two lines?

No reason at all. Break it up if you want.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: June 27 2006 at 23:33 | IP Logged Quote dhoward

Lazyman,

Formulas are pretty easy once you understand the principle behind them. All a PowerHome formula is is a simple mathematical formula. Every PowerHome function returns a value. This value is usually always a "string" or "numeric" but can also sometimes be a date depending upon the function.

So in it's simplest form, a formula is just a sequence of numbers (or functions that return numbers) with mathematical operators joining them together. So a very simple formula is:

1 + 1

An even simpler formula would be:

1

These are all valid formulas, although not very useful. The formulas follow simple algebraic rules where the formula is normally evaluated from left to right in order of operator precedence. Simply, anything in innermost parenthesis is evaluated first. ^ (exponentiation) is next, followed by * and / (multiplication and division) and finally + and - (addition and subtraction). Oftimes, the result of the formula is not important (it can be useful however to determine if you had errors) and the act of evaluating the formula is what is important.

So if we had the formula:

5 - 2 * (3 + 4)

The rules of evaluation would be cause the 3 and 4 to be added together first (equals 7), then multiplied by 2 (equals 14) with that result subtracted from 5 (with a final result of -9).

The power of the formula comes from the functions. In addition to returning a value, the functions usually perform some desired action. So if we wanted to perform to separate actions, we could have two separate formulas each with a single function, or we can just "add" the two functions together so that both functions are performed together. They still follow operator precedence so if they are just added together, the function on the left is executed first followed by the function on the right.

Another key thing to remember is that when creating a formula, the operands must all be of the same type. IE, you cant add a number to a string or a date. You can use a conversion function to convert function from return value from one type to another such as ph_rtne taking a number value and converting it to an empty string.

Hope this helps a little,

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

Joined: February 08 2006
Location: United States
Online Status: Offline
Posts: 74
Posted: December 17 2008 at 17:07 | IP Logged Quote Lazyman

So I started this thread when I was trying to write a macro which would be triggered by a motion sensor to turn on a dem path of light to the kitchen, if is was after 11:00 at night and the master bedroom light was off (or better, dim). Back then I had it working. Now it is not.

Jump   if(ph_getinsteonstat("Master Bedroom")=1,1,999)
Jump   if(hour(now())>+23 of hour(now())<=5,1,999)
Insteon Group   Kithen Path On

What am I doing wrong?
Back to Top View Lazyman's Profile Search for other posts by Lazyman
 

Page of 2 Next >>
  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