Author |
|
Dean Senior Member
Joined: August 21 2003 Location: United States
Online Status: Offline Posts: 109
|
Posted: November 19 2004 at 22:59 | IP Logged
|
|
|
Programming is not one of my strong points, so I'm hoping someone can help me out with this one.
I would like the ability to press a button on a keypad (Palm Pad or KeyChain remote, or could be a door/window sensor) when I come home at night that turns on a series of lights/modules so the house is not dark. I would like to keep the lights on for some period of time, say 10 minutes) and then turn off. This part I kinda figured out from reading this forum. The part I need help with is reading the current status of the lights/modules before anything executes in my macro. If a light is already on when the macro executes, I want to make sure I don't turn this light/module off after the designated period of time.
So in pseudo code, something like this:
// Start of Macro
set A1Status=readStatus(A1)
set A4Status=readStatus(A4)
// You could also check and if the status is already on
// don't send the on command, but I'll keep it simple
TurnOn(A1)
TurnOn(A4)
Wait (600) // Wait 10 minutes. Also check if macro
// is already running and adjust wait time
If A1Status <> On Then // If A1 was not already On
TurnOff(A1)
End If
If A4Status <> On Then // If A4 was not already On
TurnOff(A4)
End If
// End of Macro
Thanks.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: November 20 2004 at 08:20 | IP Logged
|
|
|
The status of a device can be read with X10STAT. To check A1, you would check [X10STATA1], for A4, it would be [X10STATA4]. The values returned are 0 for Unknown, 1 for Off, and 2 for On.
Remember, though, that if someone manually changes the state of a lower-end (i.e. affordable ) light control, PH won't know about it due to the modules not reporting the change.
|
Back to Top |
|
|
Dean Senior Member
Joined: August 21 2003 Location: United States
Online Status: Offline Posts: 109
|
Posted: November 20 2004 at 10:57 | IP Logged
|
|
|
I'll give the X10STATxx commands a try and see what I get, but as you pointed out, it may not do much if someone manually turns on a light.
What do I need to look at on a switch/module box/description to know if it will report the change? Is there a specific term for this? I am sure I don't have any of these modules, but if I wanted to purchase a light switch that would report the change to PowerHome, what would I be looking for?
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: November 20 2004 at 19:05 | IP Logged
|
|
|
They are called 2-way X-10 devices and are made by several companies, none of which is X-10 . SwitchLinc, Leviton, and PCS are three types.
This is a nice reference...
http://www.smarthome.com/x10_smart_switches1.html
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: November 21 2004 at 15:25 | IP Logged
|
|
|
Dean,
As Tony stated, unless you have two way modules, PowerHome cant know for sure what the actual status is. However, if you are working with plug-in modules and not so much with switch modules, you're most likely controlling them via X-10 already. In that case, PowerHome should have an accurate view of whats on and whats off. With that disclaimer, here is a macro you can import that will do what you want.
insert into macroheader values ('AFTERDARK','AFTERDARK',0,0,1);
insert into macrodetail values ('AFTERDARK',1,37,'',NULL,'This macro will sequence on a series of lights contained within the AFTERDARKLIST global variable. Each specified light must be in the format of HUU where H is the housecode and U is the unitcode. The light A3 must be encoded as A03.',0);
insert into macrodetail values ('AFTERDARK',2,37,'',NULL,'The macro will check the PowerHome status of the light. If PowerHome believes the light is on, it will not turn it on. If it is off, it will turn it on and store this address in a temporary variable [TEMP1]. After all lights are on, the macro will then wait a specified number of seconds and then will sequence off only the lights that it actually turned on.',0);
insert into macrodetail values ('AFTERDARK',3,15,'[LOCAL1]',NULL,'- 1',0);
insert into macrodetail values ('AFTERDARK',4,26,'',NULL,'STARTLOOP',0);
insert into macrodetail values ('AFTERDARK',5,15,'[LOCAL1]',NULL,'[LOCAL1] + 1',0);
insert into macrodetail values ('AFTERDARK',6,37,'',NULL,'Cycle though the afterdarklist.',0);
insert into macrodetail values ('AFTERDARK',7,15,'[LOCAL2]',NULL,'mid("{AFTERDARKLIST}",[LOCAL1] * 3 + 1,3)',0);
insert into macrodetail values ('AFTERDARK',8,37,'',NULL,'If no more lights in list then we go to the wait section.',0);
insert into macrodetail values ('AFTERDARK',9,27,'',NULL,'if("[LOCAL2]" = "","WAIT","CHECKSTATUS")',0);
insert into macrodetail values ('AFTERDARK',10,26,'',NULL,'CHECKSTATUS',0);
insert into macrodetail values ('AFTERDARK',11,37,'',NULL,'Check the current PowerHome status of the light. If you had a two way module then you could actually request the status.',0);
insert into macrodetail values ('AFTERDARK',12,27,'',NULL,'if(ph_getx10stat(left("[LOCAL2]",1),integer(mid("[LOCAL2]",2))) = 1,"TURNON","STARTLOOP")',0);
insert into macrodetail values ('AFTERDARK',13,26,'',NULL,'TURNON',0);
insert into macrodetail values ('AFTERDARK',14,37,'',NULL,'Create a temporary list of lights we turned on',0);
insert into macrodetail values ('AFTERDARK',15,15,'[TEMP1]',NULL,'"[TEMP1][LOCAL2]"',0);
insert into macrodetail values ('AFTERDARK',16,37,'',NULL,'Turn the light on',0);
insert into macrodetail values ('AFTERDARK',17,38,'',0,'ph_x10btn(left("[LOCAL2]",1),integer(mid("[LOCAL2]",2)),2,0)',0);
insert into macrodetail values ('AFTERDARK',18,27,'',NULL,'"STARTLOOP"',0);
insert into macrodetail values ('AFTERDARK',19,26,'',NULL,'WAIT',0);
insert into macrodetail values ('AFTERDARK',20,37,'',NULL,'Enter the time to wait before turning lights off. This value is in seconds. A value of 600 is equivalent to 10 minutes.',0);
insert into macrodetail values ('AFTERDARK',21,31,'',NULL,'600',0);
insert into macrodetail values ('AFTERDARK',22,15,'[LOCAL1]',NULL,'- 1',0);
insert into macrodetail values ('AFTERDARK',23,26,'',NULL,'TURNOFFLOOP',0);
insert into macrodetail values ('AFTERDARK',24,15,'[LOCAL1]',NULL,'[LOCAL1] + 1',0);
insert into macrodetail values ('AFTERDARK',25,37,'',NULL,'Cycle through the temporarylist',0);
insert into macrodetail values ('AFTERDARK',26,15,'[LOCAL2]',NULL,'mid("[TEMP1]",[LOCAL1] * 3 + 1,3)',0);
insert into macrodetail values ('AFTERDARK',27,27,'',NULL,'if("[LOCAL2]" = "","END","TURNOFF")',0);
insert into macrodetail values ('AFTERDARK',28,26,'',NULL,'TURNOFF',0);
insert into macrodetail values ('AFTERDARK',29,37,'',NULL,'Turn the light off',0);
insert into macrodetail values ('AFTERDARK',30,38,'',0,'ph_x10btn(left("[LOCAL2]",1),integer(mid("[LOCAL2]",2)),3,0)',0);
insert into macrodetail values ('AFTERDARK',31,27,'',NULL,'"TURNOFFLOOP"',0);
insert into macrodetail values ('AFTERDARK',32,26,'',NULL,'END',0);
It requires you to create a Global Variable called "AFTERDARKLIST". You will put in this GV the lights that you want controlled. For example, if you want to turn on lights A1,A2,B3, and C4 then put A01A02B03C04 in the global variable. Launch the macro by whatever means you like either through a button, etc. The macro will turn on the lights you've placed in the AFTERDARKLIST GV only if PowerHome believes they are off by checking the X10STAT variables (done through the ph_x10getstat function). If it turns a light on, it will temporarily store that address into a temporary variable. After all the specified light are on, the macro will then Wait for 10 minutes. You can change this wait time to whatever you want. After waiting, PowerHome will then cycle through the temporary list and turn the lights off that it turned on. The macro is commented to help you follow what is going on.
Good Luck,
Dave.
|
Back to Top |
|
|
Dean Senior Member
Joined: August 21 2003 Location: United States
Online Status: Offline Posts: 109
|
Posted: November 23 2004 at 06:59 | IP Logged
|
|
|
Dave,
The AfterDark macro works great in my testing so far. I will examine this more closely so I can learn from it as well. I do have a question, I see you are using [TEMP1] to store the list of lights we turned on. If I set up a trigger to execute this, say on pressing a button on an X10 keypad, it appears PowerHome passes the Trigger ID to the macro in TEMP1 (manual page 32). I assume since we are not using the Trigger ID you are just overwriting it in TEMP1? I also assume that the Trigger ID is value in the Trigger "ID" column, not the actual value that is in the Trigger "Trigger ID" column when you view the triggers?
Should the trigger be set to Queued or Immediate?
Lastly, if for whatever reason I hit the keypad multiple times and the AFTERDARK macro executes twice, will that screw things up or if the AFTERDARK macro is already running multiple executions will be ignored?
Thanks,
-Dean
|
Back to Top |
|
|
Dean Senior Member
Joined: August 21 2003 Location: United States
Online Status: Offline Posts: 109
|
Posted: November 25 2004 at 22:04 | IP Logged
|
|
|
Happy Thanksgiving everyone.
When I assign the AfterDark macro to an X10 Keypad (KC674) button (e.g. K1 ON), the proper lights turn on, but after the wait period I receive an error that states "error retrieving data from the X10UNITCODE and X10TYPES tables." If I just Play the AfterDark macro from within PowerHome everything works great.
Any ideas on this one?
Thanks.
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: November 26 2004 at 11:12 | IP Logged
|
|
|
Dean,
You are correct. If you call the macro from a trigger, the ID of the trigger will be in the [TEMP1] variable (and yes...this is the ID in the "ID" column, not the "Trigger ID"). In any event, we don't need this value so I just overwrite it in the macro.
Most triggers should be set to queued. Sometimes, immediate must be used to access variables while they are in a certain state. When using immediate, then you would "queue" any actions that communicate with controllers (X-10,IR, etc). This is more a holdover from previous versions of PowerHome where outgoing controller commands were not queued and were executed immediately. Later versions of PowerHome automatically queue outgoing commands so immediate and queued are there for compatibility purposes.
If you hit the button multiple times, the AFTERDARK macro will be triggered multiple times and will cause unpredictable results. To fix this, you can add a line at the beginning of the macro that checks (either a new line 10 before the comments or a new line 30 after the comments). This line could simply be a "Jump" command with the following formula:
if(ph_ismacrowaiting("AFTERDARK") > 0,999,1)
Hope this helps,
Dave.
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: November 26 2004 at 11:22 | IP Logged
|
|
|
Dean,
That is indeed strange with that error. There should be no difference between being triggered and just played.
Usually when an error is received concerning the X10TYPES table, it means that an X10 UnitCode has a "module type" that is no longer defined.
In this case though, it's probably another problem. It may have something to do with value of your AFTERDARKLIST variable. Please post the value you are using so I can take a look at it.
What it sounds like is happening is that something is not being stored properly in the temporary list for when the lights are turned off. When this improper value is looked up in the ph_x10btn function an error is returned because it cant find it in the unitcode or types tables.
Dave.
|
Back to Top |
|
|
Dean Senior Member
Joined: August 21 2003 Location: United States
Online Status: Offline Posts: 109
|
Posted: November 26 2004 at 11:52 | IP Logged
|
|
|
Dave,
Thanks for the new line to insert into the AFTERDARK macro. I'll insert that line and give it a shot.
My AFTERDARK variable is: A03A02A01A05A08
I did change TEMP1 to TEMP10 and I no longer get the error when the macro executes via the trigger.
Thanks,
-Dean
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: November 26 2004 at 14:46 | IP Logged
|
|
|
Dean,
Duhhhh....my bad . You are absolutely right. The problem you were having is because of the [TEMP1] variable. I was right in my assessment of the problem. The temporary string is not of the proper format. It's not of the proper format because the first part of the temporary string is the trigger ID (duhh...Now I get it).
While changing to [TEMP10] may make it work, it may not be the best answer. Ive got to check to verify, but I believe I sometimes use [TEMP10] for data as well. You may would rather want to use one of the [LOCAL??] variables. You could also, clear the [TEMP1] or [TEMP10] variable before using it. I'll leave that as an exercise for you. If you need help though, let me know.
Sorry for not thinking clearly.
Dave.
|
Back to Top |
|
|
|
|