SATI discussion

Posted on
Tue Aug 18, 2015 8:34 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

SATI discussion

please use this thread for comments & questions & suggestions & problems for SATI


Karl

Posted on
Wed Aug 19, 2015 4:43 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: SATI discussion

Hi Karl,
Just having a play with this and have detected a small bug:
Line '215' has error='not all arguments converted during string formatting'

Looks like the line number isn't included in the error text.

Also, on my system the Documents folder starts with an uppercase D and the SATI folder is uppercase which is relevant in the set pathX to "/users/" & myuserid & "/Documents/SATI/ line.

Thanks for producing this :D

Posted on
Wed Aug 19, 2015 6:43 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

SATI discussion

The upper / lower case in the path should not matter. OS X should ignore that. (Depends how your hard disk is formatted . The standard format should be fine )

As for the error. The log file entry has a bit more info. The apple script only gets the error text.
Could you post the command you are using. With all the " '.
Karl.


Sent from my iPhone using Tapatalk

Posted on
Wed Aug 19, 2015 7:43 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: SATI discussion

Unfortunately, I can't exactly remember as I was playing around with your sample script. :(

I think it might have been trying to fail on this: EXECCMD Line '213' has error='ElementNotFoundError -- could not find device "GameRoomCeilingLights"'

I got the above error after amending your line 215 to read:
Code: Select all
self.myLog(255, u"EXECCMD Line '%s' has error='%s'" % (sys.exc_traceback.tb_lineno, e) )
As you can see I was just trying it out and I would expect to get an error as I don't have a device named GameRoomCeilingLights.

Next question (an Applescript one):
How do I insert an applescript variable as a replacement for value in the line:
Code: Select all
set cmd to "\"setVariable;:;:;myVariableName;:;:;value\" "

Posted on
Wed Aug 19, 2015 8:02 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: SATI discussion

autolog wrote:
How do I insert an applescript variable as a replacement for value in the line:
Code: Select all
set cmd to "\"setVariable;:;:;myVariableName;:;:;value\" "


Answering my own question :) :
Code: Select all
set cmd to "\"setVariable;:;:;myVariableName;:;:;" & value & "\" "

Posted on
Wed Aug 19, 2015 8:03 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: SATI discussion

How do I insert an applescript variable as a replacement for value in the line:

Code: Select all
set command to "setVariable"
set variableName to "window1"
set windowValue to "55"
set seper to ";:;:;"
set cmd to "\""& command & seper & variableName & seper & windowValue &"\" "  -- the spaces before and after & are ignored
--is equivalent to
set cmd to "\"setVariable;:;:;window1;:;:;55\" "


hope that helps

Karl

Posted on
Wed Aug 19, 2015 8:12 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: SATI discussion

kw123 wrote:
... hope that helps
Yes it does - thanks :)

I have now got SATI working in conjunction with my Applescript to send SIRI commands to Indigo :)

For example, I can now say
Tell Indigo turn on study lamp
and it does :D

Posted on
Wed Aug 19, 2015 8:30 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: SATI discussion

cool ..

next release with subscriptions ++ posted

Posted on
Wed Aug 19, 2015 10:52 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: SATI discussion

Jon,

I have now got SATI working in conjunction with my Applescript to send SIRI commands to Indigo :)


could you post the code you are using?

Karl

Posted on
Wed Aug 19, 2015 10:59 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Re: SATI discussion

just an example how to use SATI:

cd into ~/Documents/SATI

type:
echo "execCmd;:;:;indigo.device.turnOn('GameRoomCeilingLights')" > fromAS-1

and the lights GameRoomCeilingLights will turn on

or
echo "execCmd;:;:;indigo.server.log('hallo from applescript')" > fromAS-1

will print "hallo from applescript" in the indigo log file


Karl

Posted on
Thu Aug 20, 2015 2:08 pm
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: SATI discussion

kw123 wrote:
Jon,

I have now got SATI working in conjunction with my Applescript to send SIRI commands to Indigo :)


could you post the code you are using?

Karl


It's a little bit convoluted and based on an AppleScript posted here by mrmatt68

The script is modified to make use of your SATI plugin which must be installed in order to update an indigo variable.

I have removed all the SIRI command interpretation from the Applescript and now this is done in Indigo using standard Indigo triggers.

You need to setup a separate apple account that you can send messages to from SIRI (I have named the account indigo for obvious reasons. :)
In the messages App on the Indigo mac, set-up an account with this new AppleID and in the Messages App, set Preferences... > General > AppleScript Handler to point at the script below e.g. indigo.applescript

The AppleScript looks like this (change to enter your relevant details):
Code: Select all
(* File: Indigio Remote Control.applescript *)
using terms from application "Messages"
   
    -- handler to respond to all incoming messages.
    on runiTunesRemoteControl(theMessage, theBuddy)
        with timeout of 30 seconds
            set theResponse to "STARTING UP"
            if theBuddy is not equal to "TESTBUDDY" then
                set theBuddy to theBuddy's handle
                (* change the below email address to those allowed and decide response to those not allowed *)
                set Allowed to 0
                if theBuddy is equal to "<MOBILE 1 OR EMAIL 1>" then
                    set Allowed to 1
                end if
                if theBuddy is equal to "<MOBILE 2 OR EMAIL 2 (ETC)>" then
                    set Allowed to 1
                end if
                if Allowed is equal to 0 then
                    set theResponse to "ERROR: Access to Indigo not allowed for sender '" & theBuddy & "'"
                    return theResponse
                end if
            end if
           
            try
                set myuserid to "<USERID>"
                set pathX to "/users/" & myuserid & "/Documents/SATI/"
                set channel to 1
                set cmd to "\"setVariable;:;:;iMessage;:;:;" & theMessage & "\" "
                set cmd to "echo " & cmd
                do shell script cmd & " > " & pathX & "fromAS-" & channel as string
                set theResponse to "ACTIONED: " & theMessage
            on error errorMessage
                set theResponse to "ERROR: " & errorMessage
            end try
           
        end timeout
       
        return theResponse
       
    end runiTunesRemoteControl
   
    -- When first message is received, accept the invitation and send a greeting message from iTunes Remote Control.
    on received text invitation theMessage from theBuddy for theChat
        accept theChat
        send "Welcome to Indigo Remote Control." to theChat
        set theResponse to runiTunesRemoteControl(theMessage, theBuddy)
        send theResponse to theChat
    end received text invitation
   
    -- On subsequent messages, pass the message directly to iTunes Remote Control.
    on message received theMessage from theBuddy for theChat
       
        -- run the iTunesRemoteControl parser.
        set theResponse to runiTunesRemoteControl(theMessage, theBuddy)
       
        -- send back the response.     
        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 "status"
    set theMessage to the text returned of the result
    set theTestBuddy to "TESTBUDDY"
   
    set theResponse to runiTunesRemoteControl(theMessage, theTestBuddy)
    (*display dialog theResponse
    *)
    # The following are unused but need to be defined to avoid an error
   
    on received audio invitation theText from theBuddy for theChat
       
    end received audio invitation
   
    on received video invitation theText from theBuddy for theChat
       
    end received video invitation
   
    on received remote screen sharing invitation from theBuddy for theChat
       
    end received remote screen sharing invitation
   
    on received local screen sharing invitation from theBuddy for theChat
       
    end received local screen sharing invitation
   
    on received file transfer invitation theFileTransfer
       
    end received file transfer invitation
   
    on message sent theMessage for theChat
       
    end message sent
   
    on addressed message received theMessage from theBuddy for theChat
       
        -- run the iTunesRemoteControl parser.
        set theResponse to runiTunesRemoteControl(theMessage, theBuddy)
       
        -- send back the response.     
        send theResponse to theChat
       
    end addressed message received
   
    on av chat started
       
    end av chat started
   
    on av chat ended
       
    end av chat ended
   
    (* HANDLERS *)
   
    on login finished for theService
       
    end login finished
   
    on logout finished for theService
       
    end logout finished
   
    on buddy became available theBuddy
       
    end buddy became available
   
    on buddy became unavailable theBuddy
       
    end buddy became unavailable
   
    on buddy authorization requested theRequest
       
    end buddy authorization requested
   
    on chat room message received theMessage from theBuddy for theChat
       
        -- run the iTunesRemoteControl parser.
        set theResponse to runiTunesRemoteControl(theMessage, theBuddy)
       
        -- send back the response.     
        send theResponse to theChat
       
    end chat room message received
   
    on addressed chat room message received theMessage from theBuddy for theChat
       
        -- run the iTunesRemoteControl parser.
        set theResponse to runiTunesRemoteControl(theMessage, theBuddy)
       
        -- send back the response.     
        send theResponse to theChat
       
    end addressed chat room message received
   
    on active chat message received theMessage from theBuddy for theChat
       
        -- run the iTunesRemoteControl parser.
        set theResponse to runiTunesRemoteControl(theMessage, theBuddy)
       
        -- send back the response.     
        send theResponse to theChat
       
    end active chat message received
   
   
    on completed file transfer
       
    end completed file transfer
   
end using terms from
You need to substitute <USERID> and <MOBILE 1 OR EMAIL 1> with your values. Set <MOBILE 2 OR EMAIL 2> if you want more than one user to send commands (extend as necessary). The mobile or email address is of the users sending the message to Indigo i.e. probably yourself :wink:

I have removed all the SIRI command interpretation from the Applescript and now this is done in Indigo using standard Indigo triggers.

I have defined two variables in Indigo: iMessage and iMessageLower
iMessage will contain the message from SIRI and iMessageLower is the same message converted to lower case so that condition checking in Indigo is less complicated.

At some point I might move the following logic into a generalised command interpreter plugin but for the moment as proof of concept it is all done using Indigo triggers and conditions with a bit of python scripting. :)

The first trigger is called SIRI:
  • Trigger:
    • Type: Variable Changed
    • Variable: iMessage
    • Changes
  • Condition
    • if conditions match rules
    • All
    • if variable - iMessage - does not contain - value - 'Lowered:'
  • Actions:
    1. execute embedded python script:
      iMessageId = <SUBSTITUTE YOUR ID> # iMessage
      iMessageLowerId = <SUBSTITUTE YOUR ID> # iMessageLower
      iMessage = indigo.variables[iMessageId]
      iMessageLowerValue = iMessage.value.strip().lower()
      indigo.variable.updateValue(iMessageLowerId, value=iMessageLowerValue)
      iMessageValue = str('Lowered: %s' % (iMessage.value))
      indigo.variable.updateValue(iMessageId, value= iMessageValue)

The above script will wait for the variable iMessage to change and then copy it to iMessageLower whilst lowercasing it. It changes the original iMessage variable by prepending 'Lowered:'.

The following three trigger examples takes a LIFX lamp in my study and allows me to turn it on, off and toggle it on/off. The lamp is called 'Study':

SIRI - Study [ON]:
  • Trigger:
    • Type: Variable Changed
    • Variable: iMessageLower
    • Changes
  • Condition
    • if conditions match rules
    • All
    • if variable - iMessageLower - does not contain - value - 'Actioned:'
    • if variable - iMessageLower - contains - value - 'on'
    • if variable - iMessageLower - contains - value - 'study'
    • Any
      • if variable - iMessageLower - contains - value - 'lamp'
      • if variable - iMessageLower - contains - value - 'light'
  • Actions:
    1. execute embedded python script:
      iMessageLowerId = <SUBSTITUTE YOUR ID> # iMessageLower
      iMessageLower = indigo.variables[iMessageLowerId]
      iMessageLowerValue = str('SIRI Actioned: %s' % (iMessageLower.value))
      indigo.variable.updateValue(iMessageLowerId, value= iMessageLowerValue))
    2. turn on 'study'

    SIRI - Study [OFF]:
    • Trigger:
      • Type: Variable Changed
      • Variable: iMessageLower
      • Changes
    • Condition
      • if conditions match rules
      • All
      • if variable - iMessageLower - does not contain - value - 'Actioned:'
      • if variable - iMessageLower - contains - value - 'off'
      • if variable - iMessageLower - contains - value - 'study'
      • Any
        • if variable - iMessageLower - contains - value - 'lamp'
        • if variable - iMessageLower - contains - value - 'light'
    • Actions:
      1. execute embedded python script:
        iMessageLowerId = <SUBSTITUTE YOUR ID> # iMessageLower
        iMessageLower = indigo.variables[iMessageLowerId]
        iMessageLowerValue = str('SIRI Actioned: %s' % (iMessageLower.value))
        indigo.variable.updateValue(iMessageLowerId, value= iMessageLowerValue))
      2. turn off 'study'

      SIRI - Study [TOGGLE]:
      • Trigger:
        • Type: Variable Changed
        • Variable: iMessageLower
        • Changes
      • Condition
        • if conditions match rules
        • All
        • if variable - iMessageLower - does not contain - value - 'Actioned:'
        • if variable - iMessageLower - does not contain - value - 'on'
        • if variable - iMessageLower - does not contain - value - 'off'
        • if variable - iMessageLower - contains - value - 'study'
        • Any
          • if variable - iMessageLower - contains - value - 'lamp'
          • if variable - iMessageLower - contains - value - 'light'
      • Actions:
        1. execute embedded python script:
          iMessageLowerId = <SUBSTITUTE YOUR ID> # iMessageLower
          iMessageLower = indigo.variables[iMessageLowerId]
          iMessageLowerValue = str('SIRI Actioned: %s' % (iMessageLower.value))
          indigo.variable.updateValue(iMessageLowerId, value= iMessageLowerValue))
        2. toggle 'study'

        So once this is all set up, in this example you can just say to SIRI:
        Tell indigo turn study lamp on
        to turn on the lamp or
        Tell indigo study lamp
        (to toggle it).

        The logic just looks for on / off / study / lamp / light - so it is fairly simple but effective - just shows the power of Indigo's condition checks :)

        SIRI seems much better these days in understanding the spoken word :)

        Hope this helps - E&OE ;)

        Page 1 of 1

        Who is online

        Users browsing this forum: No registered users and 1 guest