Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: programming Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
MarkJames
Newbie
Newbie


Joined: November 10 2009
Location: Canada
Online Status: Offline
Posts: 18
Posted: November 21 2009 at 11:25 | IP Logged Quote MarkJames

Well, I've got a decent grip on this now and am starting to write some macros. I have something I want to do and just spent half an hour or so looking at the macros in the repository forum but can't find anything that gives me a punt in the right direction so I thought I'd ask.

I have a paddle switch - call it P1 - that I use to turn on 3 other lights - L1, L2, L3. Those three lights are, in turn, controlled by multiple trigger KPLs - T1, T2, T3. It's easy to set up the links so that when a light turns on the trigger turns on and so forth.

However it's not so easy to sync P1 with an OFF press from L1, L2, L3, T1, T2, T3. If I turn off one of those lights from a different controller it should only turn off P1 IF all three lights are indeed off. Otherwise it should leave that one alone.

So the code would really just be a trigger that reads all the states whenever one of the keys is pressed and turns off p1 if all evaluate to off

Something like
trigger - l1, l2, l3, t1, t2, or t3 send an off
__________________________
f_turnoff=false
if(L1=off and L2=off and L3=off) then f_turnoff=true

if f_turnoff=true then turnoff(p1)
___________________________________

** note - that I do realize I don't need the variable here - that it could be accomplished in the first line - I'd just like to sneak a lesson in local variables in at the same time.

what would a macro to do this look like? and is there a way for a macro to trip on multiple triggers? Or would I have to execute this macro as 6 different triggers in response to each of the Light switches and Triggers sending an off?


Edited by MarkJames - November 21 2009 at 11:41
Back to Top View MarkJames's Profile Search for other posts by MarkJames
 
grif091
Super User
Super User


Joined: March 26 2008
Location: United States
Online Status: Offline
Posts: 1357
Posted: November 21 2009 at 12:45 | IP Logged Quote grif091

You define separate Triggers for I1 Off, I2 Off, etc invoking the same Macro. The macro checks the status of each device one at a time. As each device is checked if it is found to be On the macro exits. No sense checking more devices than necessary. If all devices are found to be off then turn Off P1. The process is going to take a few seconds to accomplish since multiple Insteon commands have to be issued but P1 will turn off if all the devices are off. Be sure there are no direct links from the devices back to P1 or P1 will turn off immediately if any switch is linked back to P1.     

__________________
Lee G
Back to Top View grif091's Profile Search for other posts by grif091
 
grif091
Super User
Super User


Joined: March 26 2008
Location: United States
Online Status: Offline
Posts: 1357
Posted: November 21 2009 at 17:41 | IP Logged Quote grif091

Here is a "very crude" macro that does a query of a device for status. It displays all the temp variables passed to the macro so you can see that the device ID that caused the trigger to fire and invoke the macro can be used to compare to avoid doing a needless query of a device that just fired a trigger indicating it was off. Many changes are possible to combine statements to make the process more streamlined.

Insert the lines below into the Powerhome Multi-Editor and then select Edit/Execute Script which will execute the statements and define a macro named MDEVICESTATUS. The macro statements are much easier to read when actually in a macro definition.    

insert into macroheader values ('MDEVICESTATUS','Check Device Status',0,0,1);
insert into macrodetail values ('MDEVICESTATUS',1,36,'',NULL,'"temp1= " + ph_getvar_s(2,1) + " temp2= " + ph_getvar_s(2,2) + " temp3= " + ph_getvar_s(2,3) + " temp4= " + ph_getvar_s(2,4) + " temp5= " + ph_getvar_s(2,5) + " temp6= " + ph_getvar_s(2,6) + " temp7= " + ph_getvar_s(2,7) + " temp8= " + ph_getvar_s(2,8) + " temp9= " + ph_getvar_s(2,9) + " temp10= " + ph_getvar_s(2,10)',0,'');
insert into macrodetail values ('MDEVICESTATUS',2,27,'',NULL,'if (ph_getvar_s(1,7) = "TABLE KEYPAD1", "SKIPL1", "CONTINUE")',0,'');
insert into macrodetail values ('MDEVICESTATUS',3,36,'',NULL,'"Query ICON SWITCH TEST"',0,'');
insert into macrodetail values ('MDEVICESTATUS',4,38,'',0,'ph_setvar_a(2,1,ph_insteonwithre t("ICON SWITCH TEST",25,0))',0,'');
insert into macrodetail values ('MDEVICESTATUS',5,36,'',NULL,'"Device Status = " + ph_getvar_s(2,1)',0,'');
insert into macrodetail values ('MDEVICESTATUS',6,27,'',NULL,'if (ph_getvar_n(2,1) > 0,"EXIT", "CONTINUE")',0,'');
insert into macrodetail values ('MDEVICESTATUS',7,36,'',NULL,'"ICON SWITCH TEST is OFF"',0,'');
insert into macrodetail values ('MDEVICESTATUS',8,26,'',NULL,'SKIPL1',0,'');
insert into macrodetail values ('MDEVICESTATUS',9,37,'',NULL,'Next device status check goes here',0,'');
insert into macrodetail values ('MDEVICESTATUS',10,26,'',NULL,'EXIT',0,'');
insert into macrodetail values ('MDEVICESTATUS',11,0,'',NULL,'',0,'');

Edited by grif091 - November 21 2009 at 17:43


__________________
Lee G
Back to Top View grif091's Profile Search for other posts by grif091
 
MarkJames
Newbie
Newbie


Joined: November 10 2009
Location: Canada
Online Status: Offline
Posts: 18
Posted: December 07 2009 at 01:47 | IP Logged Quote MarkJames

Sorry.. it took me a bit to get to this but I worked at it this evening.

I copied the snippet above, pasted it into the multi-editor and hit execute but all I get is formula error in the status bar. I've tried taking out line by line but none of it seems to work for me.

The odd thing is I tried to search on the field 'insert into' in the forum and got no hits. Not even your post above w hich is chock-a-block full of 'insert into's. I wonder if the forum search is indexing properly?

Back to Top View MarkJames's Profile Search for other posts by MarkJames
 
grif091
Super User
Super User


Joined: March 26 2008
Location: United States
Online Status: Offline
Posts: 1357
Posted: December 07 2009 at 01:58 | IP Logged Quote grif091

Sounds like the editor was not in SQL mode.

You can select which forum section search is looking in. Try selecting All Forums.

__________________
Lee G
Back to Top View grif091's Profile Search for other posts by grif091
 
MarkJames
Newbie
Newbie


Joined: November 10 2009
Location: Canada
Online Status: Offline
Posts: 18
Posted: December 07 2009 at 02:47 | IP Logged Quote MarkJames

I tried searching all forums...
http://www.power-home.com/forum/search.asp?KW=insert+into&SM =1&SI=PT&FM=0&OB=1

no result...

I looked through every menu choice in the program and the help file - I can't find any place that references whether the editor is in SQL mode or not. How is that changed?

Mark
Back to Top View MarkJames's Profile Search for other posts by MarkJames
 
grif091
Super User
Super User


Joined: March 26 2008
Location: United States
Online Status: Offline
Posts: 1357
Posted: December 07 2009 at 03:11 | IP Logged Quote grif091

The Title line should say Script Editor (SQL)-

If not the 4th Icon from the right in the second row of Icons on the main Powerhome display, click on the small arrow and select SQL option in the pulldown list.

__________________
Lee G
Back to Top View grif091's Profile Search for other posts by grif091
 
grif091
Super User
Super User


Joined: March 26 2008
Location: United States
Online Status: Offline
Posts: 1357
Posted: December 07 2009 at 03:19 | IP Logged Quote grif091

The link below takes you to a topic which describes a macro unrelated to your topic but it has great screen captures at the beginning of the topic for using the Script Editor for importing a macro.

Script Editor example

__________________
Lee G
Back to Top View grif091's Profile Search for other posts by grif091
 

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