Indigo and Cosm.com

Posted on
Sun Oct 14, 2012 10:45 pm
davvi offline
User avatar
Posts: 110
Joined: Sep 27, 2011
Location: Austin, TX

Indigo and Cosm.com

Anyone have any ideas on how to get Indigo data into http://Cosm.com using the information on this page? http://www.perceptiveautomation.com/wiki/doku.php?id=indigo_s_restful_urls

It would make for a really neat dashboard/chart display of device data, like the thermostat temperature, or brightness levels.

Posted on
Mon Oct 15, 2012 9:04 am
jay (support) offline
Site Admin
User avatar
Posts: 18260
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Indigo and Cosm.com

I'm not sure if their automatic feeds know how to handle basic HTTP authentication but if it can then it could definitely use the RESTful API to get data out of Indigo via the RESTful API.

In the opposite direction, someone could probably use the SQL Logger plugin as a pattern and have it make the Cosm RESTful API calls to post device and variable updates.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Oct 15, 2012 9:54 am
bschollnick2 offline
Posts: 1355
Joined: Oct 17, 2004
Location: Rochester, Ny

Re: Indigo and Cosm.com

jay (support) wrote:
I'm not sure if their automatic feeds know how to handle basic HTTP authentication but if it can then it could definitely use the RESTful API to get data out of Indigo via the RESTful API.

In the opposite direction, someone could probably use the SQL Logger plugin as a pattern and have it make the Cosm RESTful API calls to post device and variable updates.


Actually, I don't believe it's that complex.

I am investigating, but simply subscribing to Changes, and then exporting the data via restful call to Cosm.com should work.

We would want it on a separate worker thread, so as to not bog the indigo server down due to network issues... But it should be easy enough to do...

But of course, that assumes this is a one way process.... I'm investigating COSM.com right now...

------
My Plugins for Indigo (v4, v5, and v6) - http://bit.ly/U8XxPG

Security Script for v4 - http://bit.ly/QTgclf
for v5 - http://bit.ly/T6WBKu

Support Forum(s) - http://www.perceptiveautomation.com/userforum/viewforum.php?f=33

Posted on
Mon Oct 15, 2012 10:11 am
jay (support) offline
Site Admin
User avatar
Posts: 18260
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Indigo and Cosm.com

bschollnick2 wrote:
Actually, I don't believe it's that complex.

I am investigating, but simply subscribing to Changes, and then exporting the data via restful call to Cosm.com should work.


Exactly - which is what the SQL Logger plugin does except that it inserts the data into a SQL db rather than doing a RESTful call.

It's a good working example of how to subscribe to all changes and use that data.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Mon Oct 15, 2012 11:05 am
bschollnick2 offline
Posts: 1355
Joined: Oct 17, 2004
Location: Rochester, Ny

Re: Indigo and Cosm.com

jay (support) wrote:
bschollnick2 wrote:
Actually, I don't believe it's that complex.

I am investigating, but simply subscribing to Changes, and then exporting the data via restful call to Cosm.com should work.


Exactly - which is what the SQL Logger plugin does except that it inserts the data into a SQL db rather than doing a RESTful call.

It's a good working example of how to subscribe to all changes and use that data.


Ah. I misunderstood your pattern reference. I was thinking pattern as in Regex or some other manner... Not as a template for a plugin...

- Ben

------
My Plugins for Indigo (v4, v5, and v6) - http://bit.ly/U8XxPG

Security Script for v4 - http://bit.ly/QTgclf
for v5 - http://bit.ly/T6WBKu

Support Forum(s) - http://www.perceptiveautomation.com/userforum/viewforum.php?f=33

Posted on
Mon Oct 15, 2012 10:18 pm
davvi offline
User avatar
Posts: 110
Joined: Sep 27, 2011
Location: Austin, TX

Re: Indigo and Cosm.com

Alright, after reading up a bit I found a way to get Indigo variable data into Cosm automagically. Now, this may not be pretty or particularly efficient even, but it does the job and is fairly easy to adjust.

The variable values get sent to Cosm using an AppleScript that gets triggered by Indigo any time that particular variable has any change. The script sits inside its own file rather than inside Indigo to avoid slowing down Indigo should anything go wrong.

I modified the AppleScript found here http://community.cosm.com/node/1399.

Code: Select all
property MyKey : "YOUR KEY HERE"
property FeedId : "YOUR FEED ID HERE"
property DataStream : "YOUR DATASTREAM ID HERE"

tell application "IndigoServer"
   set tvPower to value of variable "tvPower"
   set TheCommand to "curl -m 5 --request PUT --data " & tvPower & " --header \"X-PachubeApiKey: " & MyKey & "\" http://api.pachube.com/v2/feeds/" & FeedId & "/datastreams/" & DataStream & ".csv"
   do shell script TheCommand
end tell


In this instance I wanted to track power consumption of my TV (using an iMeter Solo), which is where the "tvPower" variable comes from. You want to replace any instance of tvPower with the name of your variable.

The end result?

Image

A live chart tracking whatever the hell you want. :D

And since Cosm can display multiple datastreams in 1 chart, you can create 1 line displaying your region's temperature from NOAA, and another line displaying indoor temperature from your thermostat, giving you an at-a-glance comparison.

Happy charting!

Posted on
Tue Oct 16, 2012 9:05 am
davvi offline
User avatar
Posts: 110
Joined: Sep 27, 2011
Location: Austin, TX

Re: Indigo and Cosm.com

Also, you can use Cosm's Graph Builder (click on the gear icon in the top-right corner of a chart) to generate an embeddable URL of the chart. The generated link from Cosm can go into a Refreshing Image URL field in an Indigo Control Page.

Posted on
Tue Oct 16, 2012 9:08 am
matt (support) offline
Site Admin
User avatar
Posts: 21429
Joined: Jan 27, 2003
Location: Texas

Re: Indigo and Cosm.com

Terrific idea / tip.

Image

Posted on
Tue Oct 16, 2012 10:18 am
berkinet offline
User avatar
Posts: 3298
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Indigo and Cosm.com

A little slow on the uptake here... It took me a bit to realize that cosm was Pachube (the original name of the service). I had created a script that is pretty much the same as the one davvi posted, but with a little extra error checking and also a save of the data to a local text file.

For those who care about such things, here it is...
Code: Select all
set myPachubeAPIKey to "YOUR KEY GOES HERE"
set myPachubeFeed to "http://www.pachube.com/api/feeds/YOUR FEED GOES HERE.csv"

tell application "IndigoServer"
   set wineTemp to value of variable "PhWineCabinetTemp"
   set wineHumid to value of variable "PhWineCabinetHumid"
   set cellarTemp to value of variable "PhCellarTemp"
   set outsideEast to value of variable "PhOutsideEast"
   set espresso to value of variable "PhEspressoGroup"
end tell

set myData to wineTemp & "," & wineHumid & "," & cellarTemp & "," & outsideEast & "," & espresso

try
   set CommandString to "curl -m 120 -S --request PUT -H \"X-PachubeApiKey: " & myPachubeAPIKey & "\" " & "--data " & myData & " " & "\"" & 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

set theNow to (current date)
set PhDateTime to month of theNow & " " & day of theNow & " " & hours of theNow & ":" & minutes of theNow as string

set newline to ASCII character 13
set phidgetHistoryFile to open for access "Library Desk:private:var:tmp:Phidgets:phidget-history.txt" with write permission
set phEOF to get eof of phidgetHistoryFile
--write PhDateTime & "," & wineTemp & "," & wineHumid & "," & cellarTemp & newline as text to phidgetHistoryFile starting at phEOF + 1
write PhDateTime & "," & myData & newline as text to phidgetHistoryFile starting at phEOF + 1
close access phidgetHistoryFile
Notes: I am updating several feeds in the single operation. The history file was named phidgetHistoryFile because the data comes from Phidgets sensors.

Posted on
Thu May 09, 2013 11:43 pm
Korey offline
User avatar
Posts: 816
Joined: Jun 04, 2008
Location: Henderson, NV

Re: Indigo and Cosm.com

berkinet wrote:
A little slow on the uptake here... It took me a bit to realize that cosm was Pachube (the original name of the service). I had created a script that is pretty much the same as the one davvi posted, but with a little extra error checking and also a save of the data to a local text file.

For those who care about such things, here it is..Notes: I am updating several feeds in the single operation. The history file was named phidgetHistoryFile because the data comes from Phidgets sensors.


Thanks for this!!

Modified the file to suit my needs and I am now graphing our Koi pond water temperature!

:D

--
Korey

Posted on
Fri May 10, 2013 8:25 am
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Indigo and Cosm.com

davvi wrote:
Also, you can use Cosm's Graph Builder (click on the gear icon in the top-right corner of a chart) to generate an embeddable URL of the chart. The generated link from Cosm can go into a Refreshing Image URL field in an Indigo Control Page.


Very awesome! Thank you for sharing this. Took me a bit, but I got a graph up :)

Posted on
Fri May 10, 2013 11:55 am
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Indigo and Cosm.com

Thought I'd give this a try but can't seem to find a "Datastream ID" anywhere.
I created a key and it shows a very long character set below it which
I assume is the "myKey" in davvi's script?

The feed ID is labeled as such on the site but any help finding a Datastream ID appreciated!

Thanks,

Carl

Posted on
Fri May 10, 2013 12:01 pm
Korey offline
User avatar
Posts: 816
Joined: Jun 04, 2008
Location: Henderson, NV

Re: Indigo and Cosm.com

ckeyes888 wrote:
Thought I'd give this a try but can't seem to find a "Datastream ID" anywhere.
I created a key and it shows a very long character set below it which
I assume is the "myKey" in davvi's script?

The feed ID is labeled as such on the site but any help finding a Datastream ID appreciated!

Thanks,

Carl


Not sure where to find it, I used berkinet's script that didn't have a Datastream ID field.

--
Korey

Posted on
Fri May 10, 2013 12:33 pm
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Indigo and Cosm.com

ckeyes888 wrote:
Thought I'd give this a try but can't seem to find a "Datastream ID" anywhere.
I created a key and it shows a very long character set below it which
I assume is the "myKey" in davvi's script?

The feed ID is labeled as such on the site but any help finding a Datastream ID appreciated!

Thanks,

Carl


If you click on your feed and then edit it, you'll see the this screen shot.
Attachments
Untitled.tiff
Untitled.tiff (42.38 KiB) Viewed 8559 times

Posted on
Fri May 10, 2013 12:41 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Indigo and Cosm.com

Thanks, I tried Berkinet's script and it seems to be working. Very cool.

Carl

Who is online

Users browsing this forum: No registered users and 1 guest

cron