How to read power usage from TED5000 into Indigo.

Posted on
Tue Sep 29, 2009 6:18 pm
bobeast offline
User avatar
Posts: 396
Joined: Apr 16, 2003

How to read power usage from TED5000 into Indigo.

Hi All,
The new Energy Detective makes it really easy to get power usage data into Indigo. The Gateway periodically stores its data in an XML file which can be downloaded and parsed via AppleScript. Here is a quick and dirty example of how to track KWh usage in an Indigo variable.

To grab the data from the gateway;
Code: Select all
set gatewayAddress to "http://192.168.7.100"
set thePort to "8172"
set output_path to "~/Desktop/LiveData.xml"


set fileURL to gatewayAddress & ":" & thePort & "/api/LiveData.xml"
do shell script "curl " & fileURL & " -o " & output_path


obviously you'll want to change gatewayAddress, thePort, and output_path as appropriate for your setup.


Now to parse the data, you can do something like this;

Code: Select all
set XMLfile to "~/Desktop/LiveData.xml"

tell application "System Events"
   set xml_data to contents of XML file XMLfile
   tell xml_data to set live_data to XML element "LiveData"
   tell xml_data to set power to XML element "Power" of live_data
   tell xml_data to set total to XML element "Total" of power
   tell xml_data to set power_now to XML element "PowerNow" of total
   set power to value of power_now
   tell application "IndigoServer"
      set value of variable "current_power" to power as integer
   end tell
end tell


add additional variables as desired. As you examine the downloaded xml file, you'll be able to determine which data is important to you.

I wrap the whole thing in a 1 minute timer and can then set triggers on the variables, as desired. Next, I think I'll set up a control page so I can view Power usage on the iPhone. I'd be interested in hearing of other ideas as to how this data can be used.

Regards
Bob E.

Choose to chance the rapids.
Dare to dance the tide.

Posted on
Tue Feb 23, 2010 11:04 pm
Ian offline
Posts: 36
Joined: Oct 13, 2008
Location: Ottawa, ON ,Canada

Re: How to read power usage from TED5000 into Indigo.

Hey Bob

Thanks or all the help with scripts for weather retrieval. It is working great.

On to the next project...TED5000. Read your notes and understand the objective and concept.....just need a little help to get going with the first part of the script.

changed the gateway address in the script to http://192.168.0.100 for my setup.

How do I ascertain which port is being used.?....I tried 80 and 8172. I googled this to find out what port TED5000 is using but no success. Using Powermac G4 and DIR555 router.

output path should be ???? "ianrothwell/Desktop/Temp/LiveData.xml" or "~/Temp/LiveData.xml"

So far just errors running the script as I obviously don't have the right info for it to connect and the get the data.

Thanks again.

Cheers......Ian

Posted on
Wed Feb 24, 2010 12:20 am
bobeast offline
User avatar
Posts: 396
Joined: Apr 16, 2003

Re: How to read power usage from TED5000 into Indigo.

Ian wrote:
Hey Bob

Thanks or all the help with scripts for weather retrieval. It is working great.

On to the next project...TED5000. Read your notes and understand the objective and concept.....just need a little help to get going with the first part of the script.

changed the gateway address in the script to http://192.168.0.100 for my setup.

How do I ascertain which port is being used.?....I tried 80 and 8172. I googled this to find out what port TED5000 is using but no success. Using Powermac G4 and DIR555 router.

output path should be ???? "ianrothwell/Desktop/Temp/LiveData.xml" or "~/Temp/LiveData.xml"

So far just errors running the script as I obviously don't have the right info for it to connect and the get the data.

Thanks again.

Cheers......Ian


Assuming you are able to access the footprints software via your browser, you should be able to look there to determine your ip address and port. Specifically, in the System Setup Wizard under the Network Settings tab, you'll see entries for your IP address and port #. A bit of warning here, if you are using DHCP, the address could change making its use in a script temporary at best. Ideally, you would enter a manual address in the range that your DHCP router normally provides. That's what I'm doing which is where I came up with the 10.168.7.100 value you see in my example. The way that works is that DHCP servers will serve up a range of ip addresses. If you manually assign an IP to a device within that range *most* DHCP servers will honor it and not try and assign that address to a different device, especially if you choose a number at the upper end of its range. Thats why I chose 100. Once you get that set up, just use the same numbers in the script.

The output path can be wherever you want it to be. as long as you have read/write access. Just make sure both parts of the script target the same file. The tilde character is interpreted as your user folder, so you should be able to use it as opposed to explicitly entering your username. If you DO explicetely enter your user namke you need to use a complete path. For example /Users/username/Desktop/filename.txt

You'll notice that my example separates out the reading of the device from the parsing of the data into two different code snippets. You'll want to have a several second delay between the two. The way I did it is to add both snippets as separate AppleScript actions to a single group. first the device read, and then the parse snippet with a .03 minute delay.

Choose to chance the rapids.
Dare to dance the tide.

Posted on
Wed Feb 24, 2010 4:44 pm
bobeast offline
User avatar
Posts: 396
Joined: Apr 16, 2003

Re: How to read power usage from TED5000 into Indigo.

One other thought.

You can simplify your testing by entering the following line into your terminal app on a machine on your local network.

curl http://192.168.7.100:8172/api/LiveData.xml -o /Users/ianrothwell/Desktop/LiveData.xml

you'll need to plug in your appropriate IP address and port as described above. Once the LiveData.xml file shows up on your desktop, you'll know you have the right values, and can then plug them into the script.

Choose to chance the rapids.
Dare to dance the tide.

Posted on
Wed Feb 24, 2010 10:35 pm
Ian offline
Posts: 36
Joined: Oct 13, 2008
Location: Ottawa, ON ,Canada

Re: How to read power usage from TED5000 into Indigo.

Hi Bob

Thanks...getting closer. changed the IP to static as per your suggestion and also changed the port in the TED settings. Ran the terminal command and have the LiveData.xml on the desktop now. deleted it and used the script with the same results so that part is working fine.

ran the next portion of the script....to parse the data and import into Indigo variables

set XMLfile to "~/Desktop/LiveData.xml"

tell application "System Events"
set xml_data to contents of XML file XMLfile
tell xml_data to set live_data to XML element "LiveData"
tell xml_data to set power to XML element "Power" of live_data
tell xml_data to set total to XML element "Total" of power
tell xml_data to set power_now to XML element "PowerNow" of total
set power to value of power_now
tell application "IndigoServer"
set value of variable "current_power" to power as integer
end tell
end tell





and got the following error

"IndigoServer got an error: Can’t set value of variable "current_power" to 1374".

So thats where I am at the moment...any ideas

Posted on
Wed Feb 24, 2010 10:55 pm
bobeast offline
User avatar
Posts: 396
Joined: Apr 16, 2003

Re: How to read power usage from TED5000 into Indigo.

Go to Indigo and create a new variable called "current_power" then re-run your script.

Choose to chance the rapids.
Dare to dance the tide.

Posted on
Sat Feb 27, 2010 8:17 pm
Ian offline
Posts: 36
Joined: Oct 13, 2008
Location: Ottawa, ON ,Canada

Re: How to read power usage from TED5000 into Indigo.

Yep

That did it. I was not sure how to set the delay in the script however leaving the space between the 2 scripts and running them on a 1 minute timer/trigger is working perfect.

Thanks again for all your help Bob.

Cheers......Ian

Posted on
Sat Feb 27, 2010 8:39 pm
bobeast offline
User avatar
Posts: 396
Joined: Apr 16, 2003

Re: How to read power usage from TED5000 into Indigo.

Ian wrote:
Yep

That did it. I was not sure how to set the delay in the script however leaving the space between the 2 scripts and running them on a 1 minute timer/trigger is working perfect.

Thanks again for all your help Bob.

Cheers......Ian


Glad to hear you got it working!

The delay is to give the first part time to complete. I'm not sure if the second AppleScript waits for the first to complete. (JayMatt??) In any case, you'll notice at the bottom of each Action entry there is a Delay by xxxx minutes checkbox and text field. To add a delay, I enabled the checkbox and entered .03 in the textbox for the second action (the parsing script) which works out to about 1.8 seconds.

Regards
Bob E.

Choose to chance the rapids.
Dare to dance the tide.

Posted on
Sun Aug 28, 2011 12:39 am
MountainEars offline
Posts: 144
Joined: Oct 19, 2010
Location: Georgetown, CA

Re: How to read power usage from TED5000 into Indigo.

I've been messing with the TED5000 data a little based on this thread. I had started another thread trying to publish some TED data with a graph, haven't made it there yet but thought I would update this thread with some stuff I did in case it helps others. I'm not good with scripting but seeing this thread helped got me started in my data collection efforts, so thank you!

This the previous posts were pulling data out of the LiveData.xml page that TED publishes. I was looking to collect historical, hourly data and this data is published as well. The data that is published by the TED API is covered in this document I found online.

What I wanted to do was to collect the previous 24 hours of data that TED stored on an hourly basis (really just trying to get the hourly kWh information into a file). TED keeps the data for 90 days on an hourly basis, but I figured I'd collect it daily. I have a scheduled job running every 24 hours to write the data to a file which includes the current date in the file name for sorting purposes.

I was originally trying to append the data to the same file over and over, but was having troubles getting the append option to work on the curl command, so I decided to just keep a different file for each day for now. If someone knows how I can just dump this data all into one file, it would probably be better.

I'm hoping to be able to take this hourly data and match it up with my hourly outdoor temp info from my weather station for some graphing of power to temperature. I can do this manually now that I'll have all this data in somewhat of the same location. I guess the ultimate goal will be to have all of that data in one file, I think I'll get there...

For now, all I'm doing with this data in Indigo is to file it (its my cron scheduler). I am using the LiveData retrieval to publish my current power usage on my control page along with the current temp from my weather station. THe only thing I've done different with the LiveData publishing is to date stamp when I collect the data which I show on my control page as well.

In any case, here's my sloppy code to pull the hourly data and dump it into a file:
Code: Select all
set TheDate to (current date) as string
set ShortMonth to get the (month of (current date)) as string
set ShortDay to get the (day of (current date)) as string
set ShortYear to get the (year of (current date)) as string
set DateCalc to the current date
copy DateCalc to b
set the month of b to January
set monthNum to (1 + (DateCalc - b + 1314864) div 2629728) as string
-- add a leading zero to monthNum
set monthlength to (length of monthNum)
if monthlength < 2 then
   set monthNum to "0" & monthNum
end if
-- end leading zero routine
set IntDate to monthNum & ShortDay & ShortYear
set tedURL to "'http://110.110.1.80/history/hourlyhistory.xml?MTU=0&COUNT=24&INDEX=1'"
tell application "IndigoServer"
   set value of variable "IntDate" to (IntDate) as string
   set value of variable "TheDate" to (current date) as string
end tell
do shell script "curl " & tedURL & " -o ~/Desktop/TED-Data/" & (IntDate) & "-HourlyData.xml"

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest