|
Page 1 of 1
|
[ 6 posts ] |
|
Need Script in attachment to run before trigger
| Author |
Message |
|
jldomains
Joined: Jan 30, 2007 Posts: 32
|
 Need Script in attachment to run before trigger
I have 5 PCS 8 button x10 controllers model SMST8. They are around the house and set the "mode" of the house (Home, Romantic, Entertain, Bedtime, Pathway, Security, Arrival, All Off). The SMST 8 switch lights up every button you push and I only want the last button pushed to be lit, so I have to turn off the previously lit button with Indigo.
I wrote the following script and it works, however for example when I press the button All Off, Indigo executes a trigger turning all lights off before excuting my command to turn the prevoiusly lit button off so it seems slugish. What I would like to do is to synch the lights on the SMST8 first then have all X10 lights at all address turned off.
Here is the script that I wrote and put in the attachment folder. I tried putting continue receive x10 event .... at the end but it did not help the trigger still runs before my turning off previously lit button. The 8 buttons are programmed as X10 address C1 thru C8.
-- SMST8 Synch
-- SMST8 Synch allows you to synch the lights on the 8 button PCS SMST8 x10 controller
-- so only one button is lit up at a time
-- -- v1.0 Jorgen Lien 2-9-2007 (tested on Indigo 2.03)
property debugLog : true --set to false to turn off, set to true to send debug messages to the log
property scriptName : "SMST8 Sync"
using terms from application "IndigoServer"
on receive x10 event of command for address addr with dim dimVal with preset presetlevel with xdata xdataVal with xcommand xcommandVal
--Log event
if debugLog then log "Adr: " & addr & " Cmd: " & command & " Dim: " & dimVal & " Pre: " & presetlevel & " xDa: " & xdataVal & " xCm: " & xcommandVal using type scriptName
-- Check if a Ambiance SMST8 button was pushed
if addr is in {"C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8"} then
if debugLog then log "Entered inside if addr is in list, address is" & addr using type scriptName
-- SMST8 programmed in mode that button press creates only X10 on
if command is x10TurnOn then
if debugLog then log "command is x10 turnon " using type scriptName
set xaddr to value of variable "LastAmbiance"
if debugLog then log "LastAmbiance was " & xaddr using type scriptName
-- if same button pressed twice in a row kep it lit
if addr is not equal to xaddr then
send x10 off to address xaddr
end if
-- log last button pressed, so we know which one to turn off next time a button is pressed
set value of variable "LastAmbiance" to addr
if debugLog then log "LastAmbiance set to " & addr using type scriptName
end if
end if
-- Usually we first, let Indigo process the event, however in this case we want the button lights
-- to turn off quickly
continue receive x10 event of command for address addr with dim dimVal with preset presetlevel with xdata xdataVal with xcommand xcommandVal
end receive x10 event
end using terms from
_________________ JSL
|
| Sun Feb 11, 2007 3:24 pm |
|
 |
|
matt (support)
Site Admin
Joined: Jan 27, 2003 Posts: 11813 Location: Texas
|
 Re: Need Script in attachment to run before trigger
Are you using Indigo 2? Indigo 2's event engine always processes incoming events first, which is why the Trigger Action always executes first. I'd recommend that you disable your Trigger Action so it doesn't execute using Indigo's event engine, and instead at the end of your handling logic add:
- Code: Select all
execute trigger action "MyTriggerName"
Note that the above verb ignores any conditions that might be defined on the Trigger Action, so if you have any then you'll need to add logic to only call the execute above if the condition is true.
Regards,
Matt
|
| Mon Feb 12, 2007 3:54 pm |
|
 |
|
jldomains
Joined: Jan 30, 2007 Posts: 32
|
 How to pass x10 events to applescript file.
Matt,
I am using Indigo 2. I have 8 trigger actions that are involved (and it will grow to 14). Is there any way for me to just put the first action in the triggers to be applescript and call a applescript file (same file from all 8 triggers)?
What is the equivalent command
"on receive x10 event of command for address addr with dim dimVal with preset presetlevel with xdata xdataVal with xcommand xcommandVal"
to use if I call a applescript file from within a Trigger action to pass on the X10 variables to my sript:
Also if Indigo 2's event engine always processes incoming events first what does this command mean in the attachment scripts:
-- Let Indigo process the event first
continue receive x10 event of command for address addr with dim dimVal with preset presetlevel with xdata xdataVal with xcommand xcommandVal
_________________ JSL
|
| Tue Feb 13, 2007 12:26 pm |
|
 |
|
matt (support)
Site Admin
Joined: Jan 27, 2003 Posts: 11813 Location: Texas
|
 Re: How to pass x10 events to applescript file.
You can definitely put the core logic in your script above into an attachment script function which is then accessible from the Execute AppleScript action.
There isn't currently a way to easily pass information about the incoming X10/INSTEON command to your handler though, so you'll have to hard code it as an argument to your attachment function call. For example, if your attachment script function is called SyncSmst8(), then your embedded AppleScript action will have to look like:
- Code: Select all
SyncSmst8("C2", true) -- true represents a TurnOn command
The "continue receive X10 event" usage was deprecated in beta 4 of 2.0.0:
All attachment scripts that define plugin on-handler functions (on receive x10 event, on receive insteon event, on receive security event, etc.) should no longer pass the event to Indigo via the "continue..." line. Passing these events back up to Indigo has been deprecated and is no longer supported. Indigo Server will report an error in the log once per run if these events are passed up to Indigo. To prevent this error, delete all of the "continue..." lines from your attachment scripts. New versions of the default attachment scripts are installed with this version.
Regards,
Matt
|
| Tue Feb 13, 2007 8:06 pm |
|
 |
|
jldomains
Joined: Jan 30, 2007 Posts: 32
|
Matt,
I changed the script as recommended and put the core logic in the script above into an attachment script function which is then accessible from the Execute AppleScript action.
I have 8 trigger actions one for each of the 8 buttons on the SMST8, I call SyncSMST8 as the first action in each one. I then realized that the 3 of the actions check to so if it is dark as a condition. So the SMST synch won't work during daylight.
What I need is to be able to sync the lights of the SMST8 swicthes so that the only one is on at a time first before other actions (like turn off all lights which take a long time). I need the UI of the SMST8 buttons to be responsive so that is why I need to have Indigo do SyncSMST8 first. Please advise on how I can resolve this I need some kind of mechanism in Indigo 2 to be able to process X10TurnOn before anything else does.
Here is the revised script:
-- SyncSMST8 allows you to synch the lights on the 8 button PCS SMST8 x10 controller
-- so only one button is lit up at a time
-- v1.0 Jorgen Lien 2-9-2007 (tested on Indigo 2.03)
-- v1.1 Revised to be called from Indigo Actions Execute Applescript, based on advice from Matt
-- put in as Embedded: SyncSMST8("C1",True) for C1
-- Put this script file in the Indigo attachment folder
-- SMST8 programmed in mode that button press creates only X10 on
-- buttonMap is X10 codes assigned to each of the eight buttons on the PCS SMST 8 switch, starting at the top of the switch
property buttonMap : {"C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8"}
property debugLog : true --set to false to turn off, set to true to send debug messages to the Indigo log
property scriptName : "SyncSMST8" -- Identifier in Indigo Log
using terms from application "IndigoServer"
on SyncSMST8(addrString, funcType)
if debugLog then log "Entered inside SyncSMST8, address is" & addrString using type scriptName
-- verify that a SMST8 button was pushed
if addrString is in buttonMap and funcType is equal to "x10TurnOn" then
if debugLog then log "Entered inside if addrString is in list, address is" & addrString using type scriptName
set last_addrString to value of variable "LastAmbiance"
if debugLog then log "LastAmbiance was " & last_addrString using type scriptName
-- if same button pressed twice in a row kep it lit
if addrString is not equal to last_addrString then
send x10 off to address last_addrString
end if
-- log last button pressed, so we know which one to turn off next time a button is pressed
set value of variable "LastAmbiance" to addrString
if debugLog then log "LastAmbiance set to " & addrString using type scriptName
end if
end SyncSMST8
end using terms from
_________________ JSL
Last edited by jldomains on Fri Feb 16, 2007 3:53 pm, edited 1 time in total.
|
| Fri Feb 16, 2007 3:36 pm |
|
 |
|
matt (support)
Site Admin
Joined: Jan 27, 2003 Posts: 11813 Location: Texas
|
The easiest sol'n would be for you to duplicate your Trigger Actions that use the "if dark" conditional. Change the conditional on the copies to "is daylight" and remove all of the actions except for your embedded AppleScript that does the SyncSMST8() call. There are other solutions as well, but none of them are cleaner or more elegant.
Regards,
Matt
|
| Fri Feb 16, 2007 3:46 pm |
|
|
|
Page 1 of 1
|
[ 6 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 1 guest |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|