| Author |
Message |
|
mgolden50
Joined: Jan 29, 2007 Posts: 40 Location: Sedona, AZ
|
 Not getting expected result from receive X10 event
Hi,
I'm trying to use the Receive X10 event applescript verb and don't get what I expect in the associated variables.
Here is the script snippet:
using terms from application "IndigoServer"
on receive x10 event of functionType for address addrString with dim dimVal with preset presetVal with xdata xdataVal with xcommand xcommandVal
tell application "Finder"
display dialog functionType
end tell
end receive x10 event
end using terms from
Here is the error I get:
using terms from application "IndigoServer"
on receive x10 event of functionType for address addrString with dim dimVal with preset presetVal with xdata xdataVal with xcommand xcommandVal
tell application "Finder"
display dialog functionType
end tell
end receive x10 event
end using terms from
Error script error: Finder got an error: Can't make «constant ****xF02» into type string.
Error error dispatching event to attachment script (-1753)
Why does the variable functionType contain this apple event rather than the string I'm expecting to descripe the type of X10 event received?
BTW the addrString variable does correctly contain the address of the received X10 event.
Thanks,
Mike
|
| Thu May 17, 2007 10:43 pm |
|
 |
|
Matt
Joined: Aug 13, 2006 Posts: 390 Location: Northern Idaho
|
Why not make a variable that changes value when the specified x10 state is changed? Then make a trigger action that triggers when the value of said variable, changes. Dump your applescript in to this new trigger action and there you go...
But then I will probably wind up deleting this post since I don't even understand the line: on receive x10 event of functionType for address addrString with dim dimVal with preset presetVal with xdata xdataVal with xcommand xcommandVal - too much code for me...
|
| Fri May 18, 2007 4:45 am |
|
 |
|
mgolden50
Joined: Jan 29, 2007 Posts: 40 Location: Sedona, AZ
|
Hi Matt,
What I'm really trying to do is report out to another application the X10 or Insteon event actually received when it's received (both the event type e.g. on/off/dim/etc. and the source of the event e.g. H15.) Can you show me a sample of applescript that might accomplish this?
Thanks,
Mike
|
| Fri May 18, 2007 9:22 am |
|
 |
|
mgolden50
Joined: Jan 29, 2007 Posts: 40 Location: Sedona, AZ
|
Hi Matt,
I thought the line I used to receive an X10 event was directly from the Indego PlugIn Suite's dictionary...
on receive x10 event of functionType for address addrString with dim dimVal with preset presetVal with xdata xdataVal with xcommand xcommandVal
Here is a copy of what the dictionary says:
receive x10 event?v : Sent to all attachments when Indigo receives an X10 event from any interface
receive x10 event x10AllOff/x10AllLightsOn/x10AllLightsOff/x10TurnOn/x10TurnOff/x10BrightenDevice/x10DimDevice/x10StatusRequest/x10ExtendedCode/x10HailRequest/x10HailAcknowledge/x10PresetDim/x10ExtendedXfer/x10StatusOn/x10StatusOff : the x10 function type
[for address text] : the x10 house code/device code address (ex: "D6")
[with dim integer] : relative amount of dim or brighten (0 - 100)
[with preset integer] : the preset value (0 to 31)
[with xdata integer] : the extended data (first byte) (0 to 255)
[with xcommand integer] : the extended command (second byte) (0 to 255)
I thought the first variable after Receive X10 Event would be set to the X10 event type and the next to the X10 address received and so on.
Am I terribly mis-understanding the syntax to be used.
Sorry to be such an idiot about this.
Mike
|
| Fri May 18, 2007 3:54 pm |
|
 |
|
Matt
Joined: Aug 13, 2006 Posts: 390 Location: Northern Idaho
|
It looks to me that the receive x10 event command is telling other devices to recieve the values that follow.
I am not very adept at applecript - I have to tool around with things over and over to get them to do what I want Which is half the fun of Applescript for me.)
If you are trying to report something to another program you could simply make a new variable, have it change when various devices or triggers activate. Create a trigger that activates when the variable value changes and runs a script for the other program.
|
| Fri May 18, 2007 9:11 pm |
|
 |
|
matt (support)
Site Admin
Joined: Jan 27, 2003 Posts: 11814 Location: Texas
|
 Re: Not getting expected result from receive X10 event
Hi Mike,
I think you are close. You are correct to want to use these attachment on handlers to patch into the lower level X10 and INSTEON traffic. The problem is the event (stuffed into your argument variable functionType) is not a string and cannot be converted to a string. It is an enumerated argument type. I think I have seen the Script Editor have some success converting these types to strings, but the attachment script itself cannot do it independently since that mapping is in Indigo's AppleScript dictionary and not in the script.
Anyhow, the solution is to manually do the mapping yourself. Try something like this (untested!):
- Code: Select all
if functionType is x10AllOff then set functionTypeStr to "All Off" else if functionType is x10AllLightsOn then set functionTypeStr to "All Lights On" -- etc...
display dialog functionTypeStr
Regards,
Matt
|
| Fri May 18, 2007 9:51 pm |
|
 |
|
mgolden50
Joined: Jan 29, 2007 Posts: 40 Location: Sedona, AZ
|
 Victory!
Matt (Northern Idaho) Thanks for your encouragement. By toodling around I did finally crack the code with significant help from Matt (Texas).
Matt (Texas) thankyou for the code snippet and suggestion. What finally worked was adding the term "as string" which forced the coersion of the Apple Event statement into string form. I was then able to parse the salient element out of the Apple Event string which turned out to be a two digit number representing the event type detected. Apparently only the event function type is presented as an Apple Event by the attached handler. All of the other variables that are filled in by the event handler are in (easily processed) string or numeric form.
The final script looks like this:
------------------------------
using terms from application "IndigoServer"
on receive x10 event of functionType for address deviceAddress
try
set functionTypeStr to functionType as string
set functionCode to characters 17 through 18 of functionTypeStr as string
set EventType to functionCode --this will pass the actual code if it is not translated to an english phrase
if functionCode = "02" then set EventType to "On"
if functionCode = "03" then set EventType to "Off"
if functionCode = "18" then set EventType to "Dim"
if functionCode = "19" then set EventType to "Dim Stopped"
if functionCode = "20" then set EventType to "Brighten"
if functionCode = "21" then set EventType to "Brighten Stopped"
tell application "SuperCard 4.6"
do script "X10Event " & deviceAddress & " " & EventType
end tell
end try
end receive x10 event
on receive insteon event of functionType for address deviceAddress
try
set functionTypeStr to functionType as string
set functionCode to characters 17 through 18 of functionTypeStr as string
set EventType to functionCode
if functionCode = "02" then set EventType to "On"
if functionCode = "03" then set EventType to "Off"
if functionCode = "18" then set EventType to "Dim"
if functionCode = "19" then set EventType to "Dim Stopped"
if functionCode = "20" then set EventType to "Brighten"
if functionCode = "21" then set EventType to "Brighten Stopped"
tell application "SuperCard 4.6"
do script "InsteonEvent " & deviceAddress & " " & EventType
end tell
end try
end receive insteon event
end using terms from
---------------
I am sending this low level traffic to SuperCard where I have created a GUI that displays events and the status of devices and scenes on TVs and VGA screens throughout my home. It is much more intuitive and easier to code than AppleScript and yet can execute in-line AppleScripts when needed SuperTalk has proven to be a very versatile GUI programing tool with significant access and control over every aspect of OS X's multimedia capabilities. It also has large body of external commands and functions availalbe to support a wide varitey of network communications.
For anyone who may be familiar with HyperTalk/SuperTalk scripting, here is the SuperCard handler which receives the Insteon/X10 event detected by the Indego attached AppleScript handler:
-------------
on X10Event var1, var2
put "X10Event" && var1 && var2
end X10Event
on InsteonEvent var1, var2
put "InsteonEvent" && var1 && var2
end InsteonEvent
--------------
Again, my thanks to both Matts for your support.
Mike
[/code]
|
| Mon May 21, 2007 1:05 pm |
|
 |
|
mgolden50
Joined: Jan 29, 2007 Posts: 40 Location: Sedona, AZ
|
 Receive Insteon Event Handler Doesn't return V2 Button Numb
Hi,
I just discovered that the Receive Insteon Event Handler of the Plugin Suite doesen't seem to have a variable defined in the Dictionary that describes which button was pushed on an Insteon Keypad V2 dimmer.
Am I missing something? Help please!
Thanks,
Mike
|
| Thu May 24, 2007 11:31 pm |
|
 |
|
matt (support)
Site Admin
Joined: Jan 27, 2003 Posts: 11814 Location: Texas
|
 Re: Receive Insteon Event Handler Doesn't return V2 Button
Hi Mike,
The using broadcast group argument should contain an integer with the value of the button pressed.
Regards,
Matt
|
| Fri May 25, 2007 1:04 pm |
|
 |
|
mgolden50
Joined: Jan 29, 2007 Posts: 40 Location: Sedona, AZ
|
Thanks Matt once again,
That was indeed the answer. "Broadcast group" just didn't sound like it had anything remotely to do with a button number.
I appreciate your unflagging support.
Mike
|
| Fri May 25, 2007 1:44 pm |
|
|