Page 1 of 2

Talk to Indigo via IChat on Leopard

PostPosted: Tue Feb 26, 2008 7:17 pm
by jashaffner
Please feel free to throw in some ideas for this script for anyone who finds it convenient to talk to the house via IM.

You can just put script in /Library/Scripts/iChat/ and use it in iChat > Preferences > Alerts > Event: Message Received. I use separate IM account and leave it running 24/7 on machine running Indigo.

Ideas:
- get device's status
- ???

Enjoy!

Code: Select all
using terms from application "iChat"
   
   -- handler to respond to all incoming messages.
   on runIndigoRemoteControl(theMessage)
      
      set theResponse to "Unknown command."
      
      try
         if theMessage is "flash" then
            tell application "IndigoServer"
               flash(2)
            end tell
            set theResponse to "Executing flash"
         else if theMessage is "bedtime" then
            tell application "IndigoServer"
               execute group "scene - bedtime"
            end tell
            set theResponse to "Executing bedtime scene"
         else if theMessage is "tail log" then
            tell application "IndigoServer"
               set theResponse to build event log list line count 30
            end tell
         else if theMessage is "help" then
            -- display available commands on "help"
            set theResponse to "Available Commands: flash, bedtime, tail log, turn on/off [device], toggle [device], dim/brighten [device], all lights on/off, execute group [name], tail log, send email to [emailAddress] [with subject text] [with body text]"
         else
            tell application "IndigoServer"
               set result to (run script theMessage) as string
            end tell
            
            if result is "" then
               set theResponse to "Executing " & theMessage
            else
               set theResponse to result
            end if
         end if
      on error errorMessage
         set theResponse to errorMessage
      end try
      return theResponse
      
   end runIndigoRemoteControl
   
   -- When first message is received, accept the invitation and send a greeting message from Indigo Remote Control.
   on received text invitation theMessage from theBuddy for theChat
      accept theChat
      send "Welcome to Indigo Remote Control." to theChat
      set theResponse to runIndigoRemoteControl(theMessage)
      send theResponse to theChat
   end received text invitation
   
   -- On subsequent messages, pass the message directly to Indigo Remote Control.
   on message received theMessage from theBuddy for theChat
      set theResponse to runIndigoRemoteControl(theMessage)
      send theResponse to theChat
   end message received
   
   -- Sample, so you can test run this through Script Editor.
   display dialog "Send a command to Indigo Remote Control:" default answer "help"
   set theMessage to the text returned of the result
   set theResponse to runIndigoRemoteControl(theMessage)
   display dialog theResponse
   
end using terms from


ps: borrowed a piece of code from script that came with iChat on Leopard for remote controlling iTunes.

Re: Talk to Indigo via IChat on Leopard

PostPosted: Wed Feb 27, 2008 10:41 pm
by asw24b
I made one small change, which prevents anyone but me from from controlling things...


-- only allow connections from me for control -- put your name here
if the name of theBuddy is "myname@mac.com" then
accept theChat
send "Welcome to Indigo Remote Control." to theChat
set theResponse to runIndigoRemoteControl(theMessage)
send theResponse to theChat

else
log "Someone bogus tried to connect to us"
send "Bye" to theChat
decline theChat

end if

PostPosted: Thu Feb 28, 2008 8:55 am
by jashaffner
yea, I thought about restricting to certain users (ie: wife and myself) via applescript but figured that I could just use iChat's privacy level which is set to allow people only in buddylist.

PostPosted: Thu Feb 28, 2008 10:54 am
by matt (support)
Great script idea -- thanks for sharing!

Matt

random thought

PostPosted: Thu Mar 20, 2008 10:20 pm
by mreyn2005
It would be neat if one could incorporate an AIML bot application... Then your indigo mac could talk back! I know there are some python AIML implementations...

Matthew

PostPosted: Sun Apr 27, 2008 4:55 pm
by gregjsmith
I've been testing ichat scripting. I found one problem, when ichat looses it's connection a bunch of dialogs pop up. You can't get rid of them without human interaction. I'm going to try this as a replacement.

http://www.macupdate.com/info.php/id/21 ... -scripting

PostPosted: Sun Apr 27, 2008 6:18 pm
by mreyn2005
gregjsmith wrote:
I've been testing ichat scripting. I found one problem, when ichat looses it's connection a bunch of dialogs pop up. You can't get rid of them without human interaction. I'm going to try this as a replacement.

http://www.macupdate.com/info.php/id/21 ... -scripting


the website says there is a charge for each SMS message sent?

PostPosted: Sun Apr 27, 2008 7:42 pm
by gregjsmith
It appears you have to sign up for their SMS service. :(

PostPosted: Sun Feb 22, 2009 3:27 pm
by jnscolo
Help. I copied and used this script (after commenting out the test stub at the bottom.) It works great, except, it only responds on the second inbound message (and subsequent,) not the first. No matter what I've tried, I can't get it to respond to the initial message. Anybody have any suggestions?

Re: Talk to Indigo via IChat on Leopard

PostPosted: Mon Jan 03, 2011 7:10 pm
by jmesberg
I realize this is a pretty old & stale thread, but I just started playing around with controlling Indigo through iChat and found that these scripts didn't quite work for me. The biggest problem was that the threads assumed that you'd be using an AIM or iChat account that was dedicated to home control. I don't think that's practical so I reworked the script to first assess whether the user is attempting to have a normal chat, or trying to control devices in the home,

I also fixed the other problem that member jnscolo describes below. It requires two scripts, one that you attach to the Text Invitation event, and the other that you attach to the Message Received event (as described in this thread you attach these in the Alerts pane of the iChat preferences panel).

Here is the Text Invitation event script:
Code: Select all
using terms from application "iChat"
   
   global AttemptingControl
   local theResponse
   set AttemptingControl to false
   set theResponse to ""
   
   on received text invitation theMessage from theBuddy for theChat
      accept theChat
      -- run parser.
      set theResponse to runAction(theMessage)
      -- determine if theBuddy is attempting Home Control
      if AttemptingControl is true then
         -- send back the response.      
         send theResponse to theChat
         -- initiate Indigo action
         tell application "IndigoServer"
            execute group theResponse
         end tell
      end if
      
   end received text invitation
   
   on runAction(theMessage)
      
      set theResponse to ""
      set AttemptingControl to false
      
      if theMessage is "Entrance Lights on" then
         set AttemptingControl to true
         set theResponse to "Entrance Lights On"
         
      else if theMessage is "Heater On" then
         set AttemptingControl to true
         set theResponse to "Downstairs Heater On"
         
      else if theMessage is "help" then
         set AttemptingControl to true
         -- display available commands on "help"
         set theResponse to "Available commands: Entrance Lights On, Heater On"
         
      end if
         
      return theResponse
      
   end runAction
   
end using terms from


...and here is the Message Received event script:
Code: Select all
using terms from application "iChat"
   global AttemptingControl
   local theResponse
   set AttemptingControl to false
   set theResponse to ""
   
   on message received theMessage from theBuddy for theChat
      -- run parser.
      set theResponse to runAction(theMessage)
      
      -- send back the response.      
      send theResponse to theChat
      -- initiate Indigo action
      tell application "IndigoServer"
         execute group theResponse
      end tell
      
   end message received
   
   on runAction(theMessage)
      
      set theResponse to ""
      set AttemptingControl to false
      
      if theMessage is "Entrance Lights on" then
         
         set theResponse to "Entrance Lights On"
         set AttemptingControl to true
         
      else if theMessage is "Heater On" then
         set theResponse to "Downstairs Heater On"
         set AttemptingControl to true
         
      else if theMessage is "help" then
         
         -- display available commands on "help"
         set theResponse to "Available commands: Entrance Lights On, Heater On"
         set AttemptingControl to true
         
      end if
         
      return theResponse
      
   end runAction
   
end using terms from


I am not an experienced programmer so I'm sure there is probably a more elegant way to solve these problems, but these work for me and perhaps can help someone else out there.

John

Re: Talk to Indigo via IChat on Leopard

PostPosted: Mon Jan 03, 2011 7:12 pm
by jmesberg
apologies for the formatting above. I tried to use the Code block html formatting offered by the forum, but clearly not using it correctly. I hope to be posting some more applescripts soon, can someone tell me the right way to post code?

Re: Talk to Indigo via IChat on Leopard

PostPosted: Tue Jan 04, 2011 12:19 am
by macpro
Just look at the last line of your code.
You have just /code] instead of [/code].

Re: Talk to Indigo via IChat on Leopard

PostPosted: Tue Jan 04, 2011 7:27 am
by jmesberg
Thank you. Reposted here properly:
*****************************************************
I realize this is a pretty old & stale thread, but I just started playing around with controlling Indigo through iChat and found that these scripts didn't quite work for me. The biggest problem was that the threads assumed that you'd be using an AIM or iChat account that was dedicated to home control. I don't think that's practical so I reworked the script to first assess whether the user is attempting to have a normal chat, or trying to control devices in the home,

I also fixed the other problem that member jnscolo describes below. It requires two scripts, one that you attach to the Text Invitation event, and the other that you attach to the Message Received event (as described in this thread you attach these in the Alerts pane of the iChat preferences panel).

Here is the Text Invitation event script:
Code: Select all
using terms from application "iChat"

global AttemptingControl
local theResponse
set AttemptingControl to false
set theResponse to ""

on received text invitation theMessage from theBuddy for theChat
accept theChat
-- run parser.
set theResponse to runAction(theMessage)
-- determine if theBuddy is attempting Home Control
if AttemptingControl is true then
-- send back the response.   
send theResponse to theChat
-- initiate Indigo action
tell application "IndigoServer"
execute group theResponse
end tell
end if

end received text invitation

on runAction(theMessage)

set theResponse to ""
set AttemptingControl to false

if theMessage is "Entrance Lights on" then
set AttemptingControl to true
set theResponse to "Entrance Lights On"

else if theMessage is "Heater On" then
set AttemptingControl to true
set theResponse to "Downstairs Heater On"

else if theMessage is "help" then
set AttemptingControl to true
-- display available commands on "help"
set theResponse to "Available commands: Entrance Lights On, Heater On"

end if

return theResponse

end runAction

end using terms from


...and here is the Message Received event script:
Code: Select all
using terms from application "iChat"
global AttemptingControl
local theResponse
set AttemptingControl to false
set theResponse to ""

on message received theMessage from theBuddy for theChat
-- run parser.
set theResponse to runAction(theMessage)

-- send back the response.   
send theResponse to theChat
-- initiate Indigo action
tell application "IndigoServer"
execute group theResponse
end tell

end message received

on runAction(theMessage)

set theResponse to ""
set AttemptingControl to false

if theMessage is "Entrance Lights on" then

set theResponse to "Entrance Lights On"
set AttemptingControl to true

else if theMessage is "Heater On" then
set theResponse to "Downstairs Heater On"
set AttemptingControl to true

else if theMessage is "help" then

-- display available commands on "help"
set theResponse to "Available commands: Entrance Lights On, Heater On"
set AttemptingControl to true

end if

return theResponse

end runAction

end using terms from


I am not an experienced programmer so I'm sure there is probably a more elegant way to solve these problems, but these work for me and perhaps can help someone else out there.

John

Re: Talk to Indigo via IChat on Leopard

PostPosted: Mon Mar 28, 2011 2:50 pm
by chrisla23
Does the script originally posted work? It seems to me the on/off does not as the name of the device needs to be quoted ie:

Code: Select all

turn off "bedroom lights"



It does not seem to work either way. It seems fine if I hard code in the commands per device like the later versions do, but essentially passing applescript thru as the first one appears to try to do in its final else fails.

Am I missing something? Obviously the first way is nice as it's simpler and does not need to be modified each time new devices are added.

Re: Talk to Indigo via IChat on Leopard

PostPosted: Wed Mar 30, 2011 6:49 am
by matt (support)
I'm not seeing "turn off" anywhere in the scripts posted above. Can you specify which script you are trying to to use exactly?