Home > Applescript, Home Automation, Home Improvement And Automation, Macintosh > Weeder Board Integration With Indigo Using Applescript And Serial Bridge

Weeder Board Integration With Indigo Using Applescript And Serial Bridge

Weeder Technologies makes nice I/O board that can be used for a variety of purposes. I have a WTDIO-M that I’ve been experimenting with for use with my home automation system. To interface with Indigo I use Serial Bridge and it output data to variables in Indigo. I had a poorly written script and never bother to make it production worthy.

A user on the Perceptive Automation message boards shared a nice generic script that interfaces with the analog and digital boards and outputs the data to Indigo variables.

This scripts requires a trigger action to run at a set time (1 hour) to poll the analog board using the following code.

tell application "Serial Bridge"
     request reading from WT Analog I/O
    
send to source "wtdio" string "BS" & return
    
end tell

For the digital board, the a Auto Zeroize function needs to be performed one a day with this code in a trigger action.

tell application "Serial Bridge"
     AutoZeroize WT Analog I/O
    
send to source "wtdio" string "BZ" & return
    
end tell

Below is the script that is used with Serial Bridge.

on MyProcessSerialData(connectionName)
    tell application "Serial Bridge"
        wait for data from source connectionName to count 1
        
set whichWeeder to read string from source connectionName to count 1
        
if whichWeeder = "A" then digital I/O
            
            
capture the remaingin two character word from the Weeder Module
            
set WeederResponse to read string from source connectionName to count 2
            
            
Log it in its untraslated state
            
log "The Weeder says… " & "A" & WeederResponse using type "Sample"
            
set restOfString to read string from source connectionName
            
            
Identify the which contact the Weeder is reporting on.
            
set ContactName to "Contact_" & first character of WeederResponse as text
            
            
Convert the Contact state to state of the Contact
            
set ContactState to second character of WeederResponse
            
if ContactState = "L" then
                set ContactState to "CLOSED" as text
            else if ContactState = "H" then
                set ContactState to "OPEN" as text
            end if
            
Log the the tranaslated state.
            
log "That translates to… " & ContactName & " is " & ContactState & "."
            
Get a timestamp from the OS.
            
set time_stamp to do shell script "date +%Y-%m-%d\ %H:%M:%S"
            
            
tell application "IndigoServer"
                log ContactName & " is " & ContactState & "."
                
                
Create if neccessary a state varable name after the Contact, then set the state.
                
if not (variable ContactName exists) then
                    make new variable with properties {name:ContactName, value:ContactState}
                else
                    set value of variable ContactName to ContactState
                end if
                
                
Create a dynamic variable name (just because we are going to call on it several times)
                
set ContactTimestamp to ContactName & "_LastEvent_TimeStamp"
                
                
Create if neccessary a timestamp varable name after the Contact number, then set the timestamp.
                
if not (variable ContactTimestamp exists) then
                    make new variable with properties {name:ContactTimestamp, value:time_stamp}
                else
                    set value of variable ContactTimestamp to time_stamp
                end if
            end tell
            
        else if whichWeeder = "B" then analog I/O
            
            
delay 0.2
            
set wtaio to read string from source connectionName
            
log "Analog I/O: " & wtaio
            
set measurement1 to word 1 of wtaio as integer
            
log "Word 1: " & measurement1
            
            
tell application "IndigoServer"
                set AutoZero to word 1 of wtaio
                
if AutoZero = "Z" then
                    log "AutoZeroize WT Analog I/O"
                else
                    set value of variable "wtaio1" to word 1 of wtaio
                    
set value of variable "wtaio2" to word 2 of wtaio
                    
set value of variable "wtaio3" to word 3 of wtaio
                    
set value of variable "wtaio4" to word 4 of wtaio
                    
set value of variable "wtaio5" to word 5 of wtaio
                    
set value of variable "wtaio6" to word 6 of wtaio
                    
set value of variable "wtaio7" to word 7 of wtaio
                    
set value of variable "wtaio8" to word 8 of wtaio
                    
log "Reading WT Analog I/O"
                    
                    
adjust scaling for integer degrees with a single decimal place
                    
set t1 to (get value of variable "wtaio8" as string)
                    
set t1Last to last character of t1
                    
set t1Len to length of t1
                    
set t1 to characters 1 thru (t1Len - 1) of t1 as string
                    
set value of variable "TempBasement" to t1 & "." & t1Last
                    
set value of variable "TempBasement" to t1
                    
set t1 to (get value of variable "wtaio1" as string)
                    
set t1Last to last character of t1
                    
set t1Len to length of t1
                    
set t1 to characters 1 thru (t1Len - 1) of t1 as string
                    
set value of variable "TempOutside" to t1 & "." & t1Last
                end if
            end tell
        end if
    end tell
end MyProcessSerialData

—————————————————————————
on startCommunication(connectionName)
    tell application "Serial Bridge"
         initialize Serial Bridge; 5 contacts into Switch Mode
        
        
send to source connectionName string "ASI" & return
        
delay 0.2
        
send to source connectionName string "ASJ" & return
        
delay 0.2
        
send to source connectionName string "ASK" & return
        
delay 0.2
        
send to source connectionName string "ASL" & return
        
delay 0.2
        
send to source connectionName string "ASM" & return
        
delay 0.2
        
        
make other ios into outputs to prevent false triggering
        
send to source connectionName string "AHA" & return
        
delay 0.2
        
send to source connectionName string "AHB" & return
        
delay 0.2
        
send to source connectionName string "AHC" & return
        
delay 0.2
        
send to source connectionName string "AHD" & return
        
delay 0.2
        
send to source connectionName string "AHE" & return
        
delay 0.2
        
send to source connectionName string "AHF" & return
        
delay 0.2
        
send to source connectionName string "AHG" & return
        
delay 0.2
        
send to source connectionName string "AHH" & return
        
delay 0.2
        
send to source connectionName string "AHN" & return
        
        
log "INITIALIZED" using type "Error"
        
        
repeat while true
            try
                set maxTimeoutDelay to 8947848 103.56 days (hex 0×00888888)
                
with timeout of maxTimeoutDelay seconds
                    my MyProcessSerialData(connectionName)
                end timeout
            on error number errNum
                
                
if errNum is -1712 then
                    log "timeout waiting for serial data" using type "Error"
                else if errNum is -1708 then
                    log "AppleEvent not handled" using type "Error"
                    
return fatal error; exit script processing
                else if errNum is -128 then
                    log "connection script aborted" using type "Error"
                    
return fatal error; exit script processing
                else
                    log "error " & errNum & " inside MyProcessSerialData()" using type "Error"
                    
return maybe fatal error; exit script processing
                end if
                
            end try
        end repeat
    end tell
end startCommunication

I have not yet implemented this applescript. If you want to know more, check out the thread on the Perceptive Automation message boards.

Related Items:

Security Sales & IntegrationSecurity Sales & IntegrationSecurity Sales & Integration is a trade magazine for professional installation contractors, dealers, and key end users in the electronic security indu... Read More >
Morgan PollsAustralian public opinion poll including statistics and other information on surveys discussing political, economic, and social issues.
Board Dudes 18"x22" Magnetic Combo Board (15094-4)Board Dudes 18"x22" Magnetic Combo Board (15094-4)Improve your work space with a black frame that has both a fine grain cork surface and a magnetic dry erase surface. This board provides you with the... Read More >
  1. No comments yet.
  1. No trackbacks yet.

Additional comments powered by BackType