Author |
|
judetf Senior Member
Joined: January 23 2008
Online Status: Offline Posts: 234
|
Posted: March 20 2008 at 14:34 | IP Logged
|
|
|
Looking for an elegant way to turn off all lights _except_ for two specified lights. I don't want to turn them all off and then turn those two back on: I want them left on if they are on, and left off if they are off.
Ideal is for this to be a global "off" so that if I ever add new lights they'll get turned off, too, without having to reprogram the macro.
Thanks for any thoughts.
jtf
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: March 20 2008 at 19:44 | IP Logged
|
|
|
Sorry, but what kind of devices do you have?
If Insteon, you can create a Group that contains the lights you want to turn off, then just issue a Group Off command.
If X10, I think the easy thing to do would be to create a macro that turns each light off.
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: March 20 2008 at 22:46 | IP Logged
|
|
|
jtf,
It kind of depends on how you want the lights to turn off. If it's ok for them to sequence off one after the other, you could write a macro that queries the database and dynamically builds a list of all but the two lights. You could then loop through the list, turning the lights off one by one. Since it's a database query, you wouldnt need to maintain it unless you wanted to change the lights being excluded...not the ones being included.
If you're wanting the lights to all turn off simulataneously (this is assuming you have Insteon), then the only way to really do it is to create a PLC containing all of the lights except the two.
Dave.
|
Back to Top |
|
|
judetf Senior Member
Joined: January 23 2008
Online Status: Offline Posts: 234
|
Posted: March 21 2008 at 05:41 | IP Logged
|
|
|
Dave,
That's perfect. I haven't yet played with SQL querying as part of a macro, but that's the exact effect I want. I'm off to see if I can learn how to do that... Thanks.
(Tony, yes, they are Insteon; apologies.)
|
Back to Top |
|
|
judetf Senior Member
Joined: January 23 2008
Online Status: Offline Posts: 234
|
Posted: March 21 2008 at 07:17 | IP Logged
|
|
|
So perfect!!
Again, Dave's advice worked like a charm. Here's the code:
ph_sqlselect(1, "select ID from insteondevices where ID <> 'GARAGE' and ID <> 'FOYER' and ID <> 'INSTEON PLC'")+
ph_forloopwinc('
ph_insteon(
ph_getdata(1,ph_getvar_n(1,1),1)
,ioff,0)
',1,ph_getsqlrows(1),1,1)+
ph_sqldestroy(1)
If you care about why: wife and I leave together in the morning. I am programming a "leave home" button for the garage KPL, and want it to turn off any/all lights in the house except for the garage light and the foyer light (which will both turn off later on a timed event).
If you care about why/how the code above works (via my limited SQL/programming skills): I query the insteondevices table for the ID of all devices but the two (plus the PLC). As I understand it, this gets saved into a "data retrieval area." I then loop through each row in that area, and run my ph_insteon ioff command by querying the ID (col 1 from the data area) from the row that represents the count of the loop (ph_getvar_n(1,1) - I'm not sure what/how this function works, but I copied it from somewhere else and, well, it works). The loop runs for the total count of rows returned in the original SQL query.
Voila!
Thanks, Dave, and others whose vast programming skills left breadcrumbs to follow throughout the forums.
jtf
|
Back to Top |
|
|
|
|