Have added the attached code to the end of the eTrack script file.
It reads out the parameters and writes them to a coma delimited file for use in excel
A scheduled action calls this function and then the reset function 1 minute before midnight.
Result is a file that has all usage data for each day concatenated - one line per device/type (several for a thermostat - fan, heater, ac ..)
It is a completely de-normalized format, can be used in excel pivot tables.
File size is ~2K for 40 devices per day.
The file eTrackout.txt gets put into the $HOME/Documents/ directory
I have not done the iMeter section yet.
Seems to work fine.
Use as you you see fit.
Karl
+++ updated the file exist section, did not work properly.
- Code: Select all
on writefileeTrack()
(* ================================================
This primary handler write out all data to file in coma delimted format
Expects: nothing
Returns: true
=================================================== *)
set rightNow to (current date)
set rightNow to ((month of rightNow) as integer) & "/" & ((day of rightNow) as integer) & "/" & ((year of rightNow) as integer) & " " & time string of rightNow
set rightNow to rightNow as text
set outputfile to "\"$HOME/Documents/etrackout.txt\" "
--create headerline if called first time
set myPath to (path to home folder) as text
set myPath to myPath & "Documents:etrackout.txt"
--create headderline if called first time
tell application "Finder"
if exists myPath then
set create to "no"
else
set create to "yes"
end if
end tell
if create = "yes" then
set outcmd to "echo \"" & "Dev, Date-Time, "
set outcmd to outcmd & "GrandTotalCOST, GrandTotalKWH, GrandTotalTherms, CostPerKWH, CostPerTherm"
set outcmd to outcmd & " ," & "Cost, TotalCost ,TotalTime ,TotalCycles, KWH, TotalKWH, Therms, TotalTherms, ThermsPerHour"
set outcmd to outcmd & " \" >> " & outputfile
do shell script outcmd
end if
(* to be done, dont have the hardware , need to check code which variables get set
-- Reset tracked iMeter Solo devices
set iMeterVars to every variable whose name begins with "eTrackiMeter_"
--------
-- check if any variable is set
set iMexists to "true" -- added
try -- added
iMeterVars -- check if this works, then there is something in the variable, Indigo make this variable undefined if there is no hit.
on error -- added
set iMexists to "false" -- added
end try -- added
if iMexists = "true" then -- yes variables are set, continue -- added
repeat with thisVar in iMeterVars
set thisiMeter to value of thisVar
set outcmd to "echo " & "\" " & " VAR " & thisiMeter & "\" >> " & outputfile
do shell script outcmd
end repeat
end if --- added
*)
set outcmd0 to rightNow
tell application "IndigoServer"
set dat to (get value of variable "eTrackGrandTotalCost") as text
set outcmd0 to outcmd0 & ", " & dat
set dat to (get value of variable "eTrackGrandTotalKWH") as text
set outcmd0 to outcmd0 & " ," & dat
set dat to (get value of variable "eTrackGrandTotalTherms") as text
set outcmd0 to outcmd0 & " ," & dat
set dat to (get value of variable "eTrackCostPerKWH") as text
set outcmd0 to outcmd0 & " ," & dat
set dat to (get value of variable "eTrackCostPerTherm") as text
set outcmd0 to outcmd0 & " ," & dat
end tell
tell application "IndigoServer"
-- eTrackCost variables
set costVars to every variable whose name begins with "eTrackCost_"
set ni to number of items in costVars
end tell
set nn to 1
repeat while nn < ni
tell application "IndigoServer"
set w to item nn of costVars
set nam to name of w
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "_"
set devName to (text item 2 of nam) as text
set AppleScript's text item delimiters to tid
set outcmd to "echo " & "\"" & devName & ", " & outcmd0
set dat to "-0"
if variable nam exists then set dat to (get value of variable nam) as text
set outcmd to outcmd & " ," & dat
set dat to "-0"
set nam to "eTrackTotalCost_" & devName
if variable nam exists then set dat to (get value of variable nam) as text
set outcmd to outcmd & " ," & dat
set dat to "-0"
set nam to "eTrackTotalTime_" & devName
if variable nam exists then set dat to (get value of variable nam) as text
set outcmd to outcmd & " ," & dat
set dat to "-0"
set nam to "eTrackTotalCycles_" & devName
if variable nam exists then set dat to (get value of variable nam) as text
set outcmd to outcmd & " ," & dat
set dat to "-0"
set nam to "eTrackKWH_" & devName
if variable nam exists then set dat to (get value of variable nam) as text
set outcmd to outcmd & " ," & dat
set dat to "-0"
set nam to "eTrackTotalKWH_" & devName
if variable nam exists then set dat to (get value of variable nam) as text
set outcmd to outcmd & " ," & dat
set dat to "-0"
set nam to "eTrackTherms_" & devName
if variable nam exists then set dat to (get value of variable nam) as text
set outcmd to outcmd & " ," & dat
set dat to "-0"
set nam to "eTrackTotalTherms_" & devName
if variable nam exists then set dat to (get value of variable nam) as text
set outcmd to outcmd & " ," & dat
set dat to "-0"
set nam to "eTrackThermsPerHour_" & devName
if variable nam exists then set dat to (get value of variable nam) as text
set outcmd to outcmd & " ," & dat
end tell
set outcmd to outcmd & "\" >> " & outputfile
do shell script outcmd
set nn to nn + 1
end repeat