Author |
|
jmvanden Newbie
Joined: February 16 2006
Online Status: Offline Posts: 16
|
Posted: September 19 2012 at 20:28 | IP Logged
|
|
|
I would like to capture the current status of all insteon devices in my home - on/off/dim level. I would then like to be able to re-set all of my lights to that same status - on/off/dim - at a future time. Has anyone attempted to do that using a macro or other PowerHome capability?
Thanks!
jim
|
Back to Top |
|
|
BeachBum Super User
Joined: April 11 2007 Location: United States
Online Status: Offline Posts: 1880
|
Posted: September 19 2012 at 22:23 | IP Logged
|
|
|
I do that all the time. I have a global for every device and store the desired level there. I use the ph_getinsteonlevelrt for retrieving the level in real time. I later then can issue a ph_insteon command with that level.
__________________ Pete - X10 Oldie
|
Back to Top |
|
|
jmvanden Newbie
Joined: February 16 2006
Online Status: Offline Posts: 16
|
Posted: September 20 2012 at 00:03 | IP Logged
|
|
|
Makes sense. How do you store/capture that information so you can later replay it?
|
Back to Top |
|
|
BeachBum Super User
Joined: April 11 2007 Location: United States
Online Status: Offline Posts: 1880
|
Posted: September 20 2012 at 06:54 | IP Logged
|
|
|
This should work
ph_setglobal_a("store_level",ph_getinsteonlevelrt("device_na me"))
Edited by BeachBum - September 20 2012 at 07:15
__________________ Pete - X10 Oldie
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: September 20 2012 at 12:31 | IP Logged
|
|
|
Thought about this a little while and this is what I came up with. This assumes that the "state" you want to save is updated within PowerHome (it doesnt query the devices) and uses the state that is displayed in the Device Status window.
The first part is a formula that saves the current state to a file in c:\download\insteonrecall.txt. You can edit this in the formula for a different file/location. The SQL is also tailored to only store Insteon devices that are flagged as active and only stores the state for lights and appliances (devcat = 1 or 2). The data is actually saved as a list of formulas to restore the devices to their current state. Its pretty slick if I say so myself .
Code:
ph_writefile("c:\download\insteonrecall.txt",1,ph_sql(0,"sel ect 'ph_insteon(''' || id.id || ''',' || (if id.status = 0 then 'ioff,0)' else 'ion,' || status || ')' endif) from insteondevices id,insteontypes it where id.typeid = it.typeid and id.activeflag = 1 and it.devcat in (1,2)")) |
|
|
The second part to this is a macro that will restore the previoulsy saved state. Its fairly simple, just reads the file that was previously saved (c:\download\insteonrecall.txt). Parses the file line by line and executes a line using the ph_formula function. It then waits 1 second and loops back for the next line. There is some code to exit the macro after you've done all the lines. Thats it.
Code:
insert into macroheader values ('INSTEONRECALL','Insteon Recall',0,0,1);
insert into macrodetail values ('INSTEONRECALL',1,15,'[LOCAL1] ',NULL,'ph_readfile("c:\download\insteonrecall.txt")',0,'',' ');
insert into macrodetail values ('INSTEONRECALL',2,15,'[LOCAL2]',NULL,'1',0,'','');
insert into macrodetail values ('INSTEONRECALL',3,26,'',NULL,'LOOP1',0,'','');
insert into macrodetail values ('INSTEONRECALL',4,15,'[LOCAL3]',NULL,'ph_getline(ph_getvar_s(1,1),2)',0,'','');
insert into macrodetail values ('INSTEONRECALL',5,27,'',NULL,'if(ph_getvar_s(1,3) = "","END","")',0,'','');
insert into macrodetail values ('INSTEONRECALL',6,38,'',0,'ph_formula(ph_getvar_s(1,3))',0, '','');
insert into macrodetail values ('INSTEONRECALL',7,31,'',NULL,'1',0,'','');
insert into macrodetail values ('INSTEONRECALL',8,27,'',NULL,'if(ph_getvar_n(1,2) > 0,"LOOP1","")',0,'','');
insert into macrodetail values ('INSTEONRECALL',9,26,'',NULL,'END',0,'',''); |
|
|
Dave.
|
Back to Top |
|
|
smarty Super User
Joined: May 21 2006 Location: United States
Online Status: Offline Posts: 728
|
Posted: September 21 2012 at 22:13 | IP Logged
|
|
|
Cool functionality - Thanks Dave.
Question - I get the following when I run the Insteon-recall macro:
An error occurred while processing the execution queue. Resetting execution queue and trying again.
*** Error Details ***
Error Number: 3
Object Name: uo_function
Class: uo_function
Routine Name: f_playmacro
Line: 235
Text: Array boundary exceeded at line 235 in function f_playmacro of object uo_function.
The text file with my Insteon status (62 devices) does appear to be written properly. It is attached (edit - forum does not allow me to upload a SMALLL zip file).
The macro looks like it was imported properly and each line looks OK. Maybe I have too many Insteon devices?
Edited by smarty - September 21 2012 at 22:15
__________________ Elk - Insteon - BlueIris - DMC1 - PowerHome - XLobby - HA_Bridge w/Dots - Brultech
|
Back to Top |
|
|
smarty Super User
Joined: May 21 2006 Location: United States
Online Status: Offline Posts: 728
|
Posted: September 21 2012 at 22:17 | IP Logged
|
|
|
Update - just needed to retype the [LOCAL1] varaiable line for some reason...now the macro works as expected...must have been some quirk with the SQL import.
Edited by smarty - September 21 2012 at 22:42
__________________ Elk - Insteon - BlueIris - DMC1 - PowerHome - XLobby - HA_Bridge w/Dots - Brultech
|
Back to Top |
|
|
BeachBum Super User
Joined: April 11 2007 Location: United States
Online Status: Offline Posts: 1880
|
Posted: September 21 2012 at 23:08 | IP Logged
|
|
|
The code is cool... Makes my error recovery macro look like it was written by a cave man. So now I have a new project.
__________________ Pete - X10 Oldie
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: September 22 2012 at 08:56 | IP Logged
|
|
|
Smarty,
Yep, that was it. I got an email notification of your message (but not the edit) so started tracking the error down and it was definitely either line 10, 20, or 40 with one of the [LOCALXX] values not importing properly and being out of range.
I checked the SQL above and it looks good so must have just been a glitch. Glad to hear you got it working.
You can also further refine this by making use of the "Filter" and "Sort" columns in the Insteon Devices screen. You could put values here and modify the SQL so that only the devices with a particular filter are captured and use the sort so that they are restored in a particular order.
Pete, you knew you were getting bored .
Dave.
|
Back to Top |
|
|
nick7920 Senior Member
Joined: March 04 2008 Location: United States
Online Status: Offline Posts: 193
|
Posted: October 14 2012 at 12:32 | IP Logged
|
|
|
in above code write to file select statement has extra space which will gives an error
ph_sql(0,"sel ect
it should be
ph_sql(0,"select
|
Back to Top |
|
|
|
|