Page 1 of 1

Apple script to send temperature (or others) to pachube.com

PostPosted: Sat Dec 26, 2009 9:45 pm
by cullenfluffyjennings
I wrote a script to send data from indigo up to pachube. From there you can make some interesting graphs and others of the data.

You can find the script and instructions at
http://www.dial911anddie.com/weblog/200 ... -software/

Re: Apple script to send temperature (or others) to pachube.

PostPosted: Mon Dec 28, 2009 11:06 am
by matt (support)
Great -- thanks for sharing. I signed up for a beta pachube account quite a while back, but never got around to trying it out with Indigo.

PostPosted: Sat Jan 02, 2010 2:29 pm
by Matt
This is going to be awesome if I can get it to work :)

I created a Pachube.com account and started a manual feed with two data streams.

I copied and pasted your code and changed a few variables around. I entered my Pachube account keys where they belong, but I get an error everytime the time/date action triggers.

I had to change around a lof of " characters as the ones in your applescript were making my computer choke. I also noticed a bunch of ' or something so I got rid of those, and the applescript still does not run.

The log error is this: Problem with posting to pachube. curl result is:Unauthorized

The applescript I am using looks like this:

set myPachubeAPIKey to "myAPIKey"
set myPachubeFeed to "http://www.pachube.com/api/feeds/####.csv"

tell application "IndigoServer"
    set myTemp to value of variable "outside_Temp"
    set myHumidity to value of variable "outdoor_humidity"
end tell

try    
    set myRes to do shell script "curl –request PUT –header "X-PachubeApiKey:myAPIKey" & –data & myTemp & "," & myHumidity & " " & myPachubeFeed
    if myRes is not equal to " " then
    log "Problem with posting to pachube. curl result is:" & myRes        
    end if
on error
    log "Error execting curl to post to pachube.com: Result was " & myRes
end try

That has got to be close, I just can't figure out what is wrong. I have a hunch it has to do with the " and ' that I replaced or removed from the applescript.

Can you please help?

PostPosted: Sat Jan 02, 2010 5:35 pm
by asw24b
Matt wrote:
This is going to be awesome if I can get it to work :)

I created a Pachube.com account and started a manual feed with two data streams.

I copied and pasted your code and changed a few variables around. I entered my Pachube account keys where they belong, but I get an error everytime the time/date action triggers.

I had to change around a lof of " characters as the ones in your applescript were making my computer choke. I also noticed a bunch of ' or something so I got rid of those, and the applescript still does not run.

The log error is this: Problem with posting to pachube. curl result is:Unauthorized

The applescript I am using looks like this:

set myPachubeAPIKey to "myAPIKey"
set myPachubeFeed to "http://www.pachube.com/api/feeds/####.csv"

tell application "IndigoServer"
    set myTemp to value of variable "outside_Temp"
    set myHumidity to value of variable "outdoor_humidity"
end tell

try    
    set myRes to do shell script "curl –request PUT –header "X-PachubeApiKey:myAPIKey" & –data & myTemp & "," & myHumidity & " " & myPachubeFeed
    if myRes is not equal to " " then
    log "Problem with posting to pachube. curl result is:" & myRes        
    end if
on error
    log "Error execting curl to post to pachube.com: Result was " & myRes
end try

That has got to be close, I just can't figure out what is wrong. I have a hunch it has to do with the " and ' that I replaced or removed from the applescript.

Can you please help?


Yes... the sample code above seems to have gotten corrupted when it was pasted in.


I am sending only one temp value.

Here is the code that I am using:

(Thermotemp is the parsed temperature string that I get back from my Proliphix thermostat)


Code: Select all
            set myTemp to (Thermotemp as real)
            
            
            try
               set CommandString to "curl -m 120 -S --request PUT -H "X-PachubeApiKey: " & myPachubeAPIKey & "" " & "--data " & myTemp & " " & """ & myPachubeFeed & """
               set myRes to do shell script CommandString
               
               if myRes is not equal to " " then
                  log "Problem with posting to pachube. curl result is:" & myRes
               end if
            on error
               log "Error execting curl to post to pachube.com: Result was " & myRes
            end try
            
            log "ran the temp log script temp=" & myTemp

PostPosted: Sun Jan 03, 2010 1:17 am
by Matt
That fixed it. Thanks!!!